diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index f668d3e047..daf74e07e3 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -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 diff --git a/source/libs/tdb/src/db/tdbPgFile.c b/source/libs/tdb/src/db/tdbPgFile.c index 9e006aa2b4..b993b68635 100644 --- a/source/libs/tdb/src/db/tdbPgFile.c +++ b/source/libs/tdb/src/db/tdbPgFile.c @@ -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; diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index ef2eab87ef..4f9f32b8ea 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -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 } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 782206a4aa..06674496a9 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -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 { \ diff --git a/source/libs/tdb/src/inc/tdbPgFile.h b/source/libs/tdb/src/inc/tdbPgFile.h index d0b51442d1..90136ef886 100644 --- a/source/libs/tdb/src/inc/tdbPgFile.h +++ b/source/libs/tdb/src/inc/tdbPgFile.h @@ -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 mapping DB. };