This commit is contained in:
Hongze Cheng 2022-02-15 11:04:31 +00:00
parent c9cd5fce3b
commit 5c1cad5a3a
5 changed files with 23 additions and 6 deletions

View File

@ -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;
}

View 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;

View File

@ -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
}

View File

@ -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 { \

View File

@ -37,6 +37,7 @@ struct SPgFile {
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.
};