Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1e5c2688
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1e5c2688
编写于
2月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact
上级
68cc3d4f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
237 addition
and
236 deletion
+237
-236
source/libs/tdb/CMakeLists.txt
source/libs/tdb/CMakeLists.txt
+1
-0
source/libs/tdb/src/db/tdbPFile.c
source/libs/tdb/src/db/tdbPFile.c
+204
-204
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+1
-1
source/libs/tdb/src/inc/tdbPFile.h
source/libs/tdb/src/inc/tdbPFile.h
+31
-31
未找到文件。
source/libs/tdb/CMakeLists.txt
浏览文件 @
1e5c2688
...
...
@@ -8,6 +8,7 @@ add_library(tdb "")
target_sources
(
tdb
PRIVATE
"src/db/tdbPCache.c"
"src/db/tdbPFile.c"
)
target_include_directories
(
...
...
source/libs/tdb/src/db/tdbPFile.c
浏览文件 @
1e5c2688
...
...
@@ -15,207 +15,207 @@
#include "tdbInt.h"
typedef
struct
SPage1
{
char
magic
[
64
];
SPgno
mdbRootPgno
;
// master DB root page number
SPgno
freePgno
;
// free list page number
uint32_t
nFree
;
// number of free pages
}
SPage1
;
typedef
struct
SFreePage
{
/* TODO */
}
SFreePage
;
TDB_STATIC_ASSERT
(
sizeof
(
SPage1
)
<=
TDB_MIN_PGSIZE
,
"TDB Page1 definition too large"
);
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
SPgno
pgno
,
uint8_t
*
pData
);
int
pgFileOpen
(
SPgFile
**
ppPgFile
,
const
char
*
fname
,
TENV
*
pEnv
)
{
SPgFile
*
pPgFile
;
SPgCache
*
pPgCache
;
size_t
fnameLen
;
SPgno
fsize
;
*
ppPgFile
=
NULL
;
// create the handle
fnameLen
=
strlen
(
fname
);
pPgFile
=
(
SPgFile
*
)
calloc
(
1
,
sizeof
(
*
pPgFile
)
+
fnameLen
+
1
);
if
(
pPgFile
==
NULL
)
{
return
-
1
;
}
ASSERT
(
pEnv
!=
NULL
);
// init the handle
pPgFile
->
fname
=
(
char
*
)(
&
(
pPgFile
[
1
]));
memcpy
(
pPgFile
->
fname
,
fname
,
fnameLen
);
pPgFile
->
fname
[
fnameLen
]
=
'\0'
;
pPgFile
->
fd
=
-
1
;
pPgFile
->
fd
=
open
(
fname
,
O_CREAT
|
O_RDWR
,
0755
);
if
(
pPgFile
->
fd
<
0
)
{
// TODO: handle error
return
-
1
;
}
tdbGnrtFileID
(
fname
,
pPgFile
->
fileid
,
false
);
tdbGetFileSize
(
fname
,
tdbEnvGetPageSize
(
pEnv
),
&
fsize
);
pPgFile
->
fsize
=
fsize
;
pPgFile
->
lsize
=
fsize
;
if
(
pPgFile
->
fsize
==
0
)
{
// A created file
SPgno
pgno
;
pgid_t
pgid
;
pgFileAllocatePage
(
pPgFile
,
&
pgno
);
ASSERT
(
pgno
==
1
);
memcpy
(
pgid
.
fileid
,
pPgFile
->
fileid
,
TDB_FILE_ID_LEN
);
pgid
.
pgno
=
pgno
;
pgCacheFetch
(
pPgCache
,
pgid
);
// Need to allocate the first page as a description page
}
else
{
// An existing file
}
/* TODO: other open operations */
// add the page file to the environment
tdbEnvRgstPageFile
(
pEnv
,
pPgFile
);
pPgFile
->
pEnv
=
pEnv
;
*
ppPgFile
=
pPgFile
;
return
0
;
}
int
pgFileClose
(
SPgFile
*
pPgFile
)
{
if
(
pPgFile
)
{
if
(
pPgFile
->
fd
>=
0
)
{
close
(
pPgFile
->
fd
);
}
tfree
(
pPgFile
->
fname
);
free
(
pPgFile
);
}
return
0
;
}
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
SPgno
pgno
)
{
SPgCache
*
pPgCache
;
SPage
*
pPage
;
pgid_t
pgid
;
// 1. Fetch from the page cache
// pgCacheFetch(pPgCache, pgid);
// 2. If only get a page frame, no content, maybe
// need to load from the file
if
(
1
/*page not initialized*/
)
{
if
(
pgno
<
pPgFile
->
fsize
)
{
// load the page content from the disk
// ?? How about the freed pages ??
}
else
{
// zero the page, make the page as a empty
// page with zero records.
}
}
#if 0
pPgCache = pPgFile->pPgCache;
pPage = NULL;
memcpy(pgid.fileid, pPgFile->fileid, TDB_FILE_ID_LEN);
pgid.pgno = pgno;
if (pgno > pPgFile->pgFileSize) {
// TODO
} else {
pPage = pgCacheFetch(pPgCache, pgid);
if (1 /*Page is cached, no need to load from file*/) {
return pPage;
} else {
// TODO: handle error
if (pgFileRead(pPgFile, pgno, (void *)pPage) < 0) {
// todoerr
}
return pPage;
}
}
#endif
return
pPage
;
}
int
pgFileRelease
(
SPage
*
pPage
)
{
pgCacheRelease
(
pPage
);
return
0
;
}
int
pgFileWrite
(
SPage
*
pPage
)
{
// TODO
return
0
;
}
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
SPgno
*
pPgno
)
{
SPgno
pgno
;
SPage1
*
pPage1
;
SPgCache
*
pPgCache
;
pgid_t
pgid
;
SPage
*
pPage
;
if
(
pPgFile
->
lsize
==
0
)
{
pgno
=
++
(
pPgFile
->
lsize
);
}
else
{
if
(
0
)
{
// TODO: allocate from the free list
pPage
=
pgCacheFetch
(
pPgCache
,
pgid
);
if
(
pPage1
->
nFree
>
0
)
{
// TODO
}
else
{
pgno
=
++
(
pPgFile
->
lsize
);
}
}
else
{
pgno
=
++
(
pPgFile
->
lsize
);
}
}
*
pPgno
=
pgno
;
return
0
;
}
static
int
pgFileRead
(
SPgFile
*
pPgFile
,
SPgno
pgno
,
uint8_t
*
pData
)
{
pgsz_t
pgSize
;
ssize_t
rsize
;
uint8_t
*
pTData
;
size_t
szToRead
;
#if 0
// pgSize = ; (TODO)
pTData = pData;
szToRead = pgSize;
for (; szToRead > 0;) {
rsize = pread(pPgFile->fd, pTData, szToRead, pgno * pgSize);
if (rsize < 0) {
if (errno == EINTR) {
continue;
} else {
return -1;
}
} else if (rsize == 0) {
return -1;
}
szToRead -= rsize;
pTData += rsize;
}
#endif
return
0
;
}
\ No newline at end of file
// typedef struct SPage1 {
// char magic[64];
// SPgno mdbRootPgno; // master DB root page number
// SPgno freePgno; // free list page number
// uint32_t nFree; // number of free pages
// } SPage1;
// typedef struct SFreePage {
// /* TODO */
// } SFreePage;
// TDB_STATIC_ASSERT(sizeof(SPage1) <= TDB_MIN_PGSIZE, "TDB Page1 definition too large");
// static int pgFileRead(SPgFile *pPgFile, SPgno pgno, uint8_t *pData);
// int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
// SPgFile * pPgFile;
// SPgCache *pPgCache;
// size_t fnameLen;
// SPgno fsize;
// *ppPgFile = NULL;
// // create the handle
// fnameLen = strlen(fname);
// pPgFile = (SPgFile *)calloc(1, sizeof(*pPgFile) + fnameLen + 1);
// if (pPgFile == NULL) {
// return -1;
// }
// ASSERT(pEnv != NULL);
// // init the handle
// pPgFile->fname = (char *)(&(pPgFile[1]));
// memcpy(pPgFile->fname, fname, fnameLen);
// pPgFile->fname[fnameLen] = '\0';
// pPgFile->fd = -1;
// pPgFile->fd = open(fname, O_CREAT | O_RDWR, 0755);
// if (pPgFile->fd < 0) {
// // TODO: handle error
// return -1;
// }
// tdbGnrtFileID(fname, pPgFile->fileid, false);
// tdbGetFileSize(fname, tdbEnvGetPageSize(pEnv), &fsize);
// pPgFile->fsize = fsize;
// pPgFile->lsize = fsize;
// if (pPgFile->fsize == 0) {
// // A created file
// SPgno pgno;
// pgid_t pgid;
// pgFileAllocatePage(pPgFile, &pgno);
// ASSERT(pgno == 1);
// memcpy(pgid.fileid, pPgFile->fileid, TDB_FILE_ID_LEN);
// pgid.pgno = pgno;
// pgCacheFetch(pPgCache, pgid);
// // Need to allocate the first page as a description page
// } else {
// // An existing file
// }
// /* TODO: other open operations */
// // add the page file to the environment
// tdbEnvRgstPageFile(pEnv, pPgFile);
// pPgFile->pEnv = pEnv;
// *ppPgFile = pPgFile;
// return 0;
// }
// int pgFileClose(SPgFile *pPgFile) {
// if (pPgFile) {
// if (pPgFile->fd >= 0) {
// close(pPgFile->fd);
// }
// tfree(pPgFile->fname);
// free(pPgFile);
// }
// return 0;
// }
// SPage *pgFileFetch(SPgFile *pPgFile, SPgno pgno) {
// SPgCache *pPgCache;
// SPage * pPage;
// pgid_t pgid;
// // 1. Fetch from the page cache
// // pgCacheFetch(pPgCache, pgid);
// // 2. If only get a page frame, no content, maybe
// // need to load from the file
// if (1 /*page not initialized*/) {
// if (pgno < pPgFile->fsize) {
// // load the page content from the disk
// // ?? How about the freed pages ??
// } else {
// // zero the page, make the page as a empty
// // page with zero records.
// }
// }
// #if 0
// pPgCache = pPgFile->pPgCache;
// pPage = NULL;
// memcpy(pgid.fileid, pPgFile->fileid, TDB_FILE_ID_LEN);
// pgid.pgno = pgno;
// if (pgno > pPgFile->pgFileSize) {
// // TODO
// } else {
// pPage = pgCacheFetch(pPgCache, pgid);
// if (1 /*Page is cached, no need to load from file*/) {
// return pPage;
// } else {
// // TODO: handle error
// if (pgFileRead(pPgFile, pgno, (void *)pPage) < 0) {
// // todoerr
// }
// return pPage;
// }
// }
// #endif
// return pPage;
// }
// int pgFileRelease(SPage *pPage) {
// pgCacheRelease(pPage);
// return 0;
// }
// int pgFileWrite(SPage *pPage) {
// // TODO
// return 0;
// }
// int pgFileAllocatePage(SPgFile *pPgFile, SPgno *pPgno) {
// SPgno pgno;
// SPage1 * pPage1;
// SPgCache *pPgCache;
// pgid_t pgid;
// SPage * pPage;
// if (pPgFile->lsize == 0) {
// pgno = ++(pPgFile->lsize);
// } else {
// if (0) {
// // TODO: allocate from the free list
// pPage = pgCacheFetch(pPgCache, pgid);
// if (pPage1->nFree > 0) {
// // TODO
// } else {
// pgno = ++(pPgFile->lsize);
// }
// } else {
// pgno = ++(pPgFile->lsize);
// }
// }
// *pPgno = pgno;
// return 0;
// }
// static int pgFileRead(SPgFile *pPgFile, SPgno pgno, uint8_t *pData) {
// pgsz_t pgSize;
// ssize_t rsize;
// uint8_t *pTData;
// size_t szToRead;
// #if 0
// // pgSize = ; (TODO)
// pTData = pData;
// szToRead = pgSize;
// for (; szToRead > 0;) {
// rsize = pread(pPgFile->fd, pTData, szToRead, pgno * pgSize);
// if (rsize < 0) {
// if (errno == EINTR) {
// continue;
// } else {
// return -1;
// }
// } else if (rsize == 0) {
// return -1;
// }
// szToRead -= rsize;
// pTData += rsize;
// }
// #endif
// return 0;
// }
\ No newline at end of file
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
1e5c2688
...
...
@@ -123,7 +123,7 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
#include "tdbPCache.h"
//
#include "tdbPFile.h"
#include "tdbPFile.h"
// #include "tdbEnv.h"
...
...
source/libs/tdb/src/inc/tdbPFile.h
浏览文件 @
1e5c2688
...
...
@@ -20,37 +20,37 @@
extern
"C"
{
#endif
typedef
struct
__attribute__
((
__packed__
))
{
char
hdrInfo
[
16
];
// info string
pgsz_t
szPage
;
// page size of current file
int32_t
cno
;
// commit number counter
SPgno
freePgno
;
// freelist page number
uint8_t
resv
[
100
];
// reserved space
}
SPgFileHdr
;
#define TDB_PG_FILE_HDR_SIZE 128
TDB_STATIC_ASSERT
(
sizeof
(
SPgFileHdr
)
==
TDB_PG_FILE_HDR_SIZE
,
"Page file header size if not 128"
);
struct
SPgFile
{
TENV
*
pEnv
;
// env containing this page file
char
*
fname
;
// backend file name
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
// file id
SPgno
lsize
;
// page file logical size (for count)
SPgno
fsize
;
// real file size on disk (for rollback)
int
fd
;
SPgFileListNode
envHash
;
SPgFileListNode
envPgfList
;
};
int
pgFileOpen
(
SPgFile
**
ppPgFile
,
const
char
*
fname
,
TENV
*
pEnv
);
int
pgFileClose
(
SPgFile
*
pPgFile
);
SPage
*
pgFileFetch
(
SPgFile
*
pPgFile
,
SPgno
pgno
);
int
pgFileRelease
(
SPage
*
pPage
);
int
pgFileWrite
(
SPage
*
pPage
);
int
pgFileAllocatePage
(
SPgFile
*
pPgFile
,
SPgno
*
pPgno
);
//
typedef struct __attribute__((__packed__)) {
//
char hdrInfo[16]; // info string
//
pgsz_t szPage; // page size of current file
//
int32_t cno; // commit number counter
//
SPgno freePgno; // freelist page number
//
uint8_t resv[100]; // reserved space
//
} SPgFileHdr;
//
#define TDB_PG_FILE_HDR_SIZE 128
//
TDB_STATIC_ASSERT(sizeof(SPgFileHdr) == TDB_PG_FILE_HDR_SIZE, "Page file header size if not 128");
//
struct SPgFile {
//
TENV * pEnv; // env containing this page file
//
char * fname; // backend file name
//
uint8_t fileid[TDB_FILE_ID_LEN]; // file id
//
SPgno lsize; // page file logical size (for count)
//
SPgno fsize; // real file size on disk (for rollback)
//
int fd;
//
SPgFileListNode envHash;
//
SPgFileListNode envPgfList;
//
};
//
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
//
int pgFileClose(SPgFile *pPgFile);
//
SPage *pgFileFetch(SPgFile *pPgFile, SPgno pgno);
//
int pgFileRelease(SPage *pPage);
//
int pgFileWrite(SPage *pPage);
//
int pgFileAllocatePage(SPgFile *pPgFile, SPgno *pPgno);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录