提交 5c1cad5a 编写于 作者: H Hongze Cheng

more TDB

上级 c9cd5fce
......@@ -23,6 +23,8 @@ struct STDbEnv {
SPgFileList pgfList; // SPgFile List
SPgCache * pPgCache; // page cache
struct {
#define TDB_ENV_PGF_HASH_BUCKETS 17
SPgFileList buckets[TDB_ENV_PGF_HASH_BUCKETS];
} pgfht; // page file hash table;
SJournal *pJournal;
};
......@@ -128,3 +130,12 @@ int tdbEnvCommit(TENV *pEnv) {
}
const char *tdbEnvGetRootDir(TENV *pEnv) { return pEnv->rootDir; }
int tdbEnvRgstPageFile(TENV *pEnv, SPgFile *pPgFile) {
SPgFileList *pBucket;
pBucket = pEnv->pgfht.buckets + (0 % TDB_ENV_PGF_HASH_BUCKETS); // TODO
TD_DLIST_APPEND_WITH_FIELD(pBucket, pPgFile, envHash);
return 0;
}
\ No newline at end of file
......@@ -34,7 +34,6 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
ASSERT(pEnv != NULL);
// init the handle
pPgFile->pEnv = pEnv;
pPgFile->fname = (char *)(&(pPgFile[1]));
memcpy(pPgFile->fname, fname, fnameLen);
pPgFile->fname[fnameLen] = '\0';
......@@ -48,7 +47,11 @@ int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
tdbGnrtFileID(fname, pPgFile->fileid, false);
/* TODO */
/* TODO: other open operations */
// add the page file to the environment
tdbEnvRgstPageFile(pEnv, pPgFile);
pPgFile->pEnv = pEnv;
*ppPgFile = pPgFile;
return 0;
......
......@@ -23,6 +23,7 @@ extern "C" {
const char* tdbEnvGetRootDir(TENV* pEnv);
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
int tdbEnvRgstPageFile(TENV* pEnv, SPgFile* pPgFile);
#ifdef __cplusplus
}
......
......@@ -84,6 +84,7 @@ typedef pgsz_t pgoff_t;
typedef TD_DLIST(STDb) STDbList;
typedef TD_DLIST(SPgFile) SPgFileList;
typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
#define TERR_A(val, op, flag) \
do { \
......
......@@ -33,10 +33,11 @@ typedef struct __attribute__((__packed__)) {
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
int fd;
TENV * pEnv; // env containing this page file
char * fname; // backend file name
uint8_t fileid[TDB_FILE_ID_LEN]; // file id
int fd;
SPgFileListNode envHash;
// TDB * pDb; // For a SPgFile for multiple databases, this is the <dbname, pgno> mapping DB.
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册