提交 fb0b5340 编写于 作者: H Hongze Cheng

more TDB

上级 baf5ceed
......@@ -86,7 +86,7 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
pDb->dbname[dbNameLen] = '\0';
// open pPgFile or get from the env
// get page file from the env, if not opened yet, open it
pPgFile = NULL;
snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname);
fileExist = (tdbCheckFileAccess(fname, TDB_F_OK) == 0);
......@@ -103,39 +103,11 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
}
}
#if 0
pDb->pEnv = pEnv;
// register DB to ENV
ASSERT(fname != NULL);
// Check if file exists
if (tdbCheckFileAccess(fname, TDB_F_OK) != 0) {
if (1) {
// create the file
}
}
// Check if the SPgFile already opened
tdbGnrtFileID(fname, fileid, false);
pPgFile = tdbEnvGetPageFile(pEnv, fileid);
if (pPgFile == NULL) {
pPgCache = tdbEnvGetPgCache(pEnv);
if ((ret = pgFileOpen(&pPgFile, fname, pPgCache)) != 0) {
return -1;
}
}
// TODO: open the database (an existing or a new one)
pDb->pPgFile = pPgFile;
// open the access method (TODO)
if (btreeOpen(&pBt, pPgFile) != 0) {
return -1;
}
pDb->pBt = pBt;
#endif
tdbEnvRgstDB(pEnv, pDb);
pDb->pEnv = pEnv;
return 0;
}
......
......@@ -29,6 +29,12 @@ struct STDbEnv {
SJournal *pJournal;
};
#define TDB_ENV_PGF_HASH(fileid) \
({ \
uint8_t *tmp = (uint8_t *)(fileid); \
tmp[0] + tmp[1] + tmp[2]; \
})
static int tdbEnvDestroy(TENV *pEnv);
int tdbEnvCreate(TENV **ppEnv, const char *rootDir) {
......@@ -108,8 +114,15 @@ pgsz_t tdbEnvGetPageSize(TENV *pEnv) { return pEnv->pgSize; }
cachesz_t tdbEnvGetCacheSize(TENV *pEnv) { return pEnv->cacheSize; }
SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) {
// TODO
return NULL;
SPgFileList *pBucket;
SPgFile * pPgFile;
pBucket = pEnv->pgfht.buckets + (TDB_ENV_PGF_HASH(fileid) % TDB_ENV_PGF_HASH_BUCKETS); // TODO
for (pPgFile = TD_DLIST_HEAD(pBucket); pPgFile != NULL; pPgFile = TD_DLIST_NODE_NEXT_WITH_FIELD(pPgFile, envHash)) {
if (memcmp(fileid, pPgFile->fileid, TDB_FILE_ID_LEN) == 0) break;
};
return pPgFile;
}
SPgCache *tdbEnvGetPgCache(TENV *pEnv) { return pEnv->pPgCache; }
......@@ -131,12 +144,6 @@ int tdbEnvCommit(TENV *pEnv) {
const char *tdbEnvGetRootDir(TENV *pEnv) { return pEnv->rootDir; }
#define TDB_ENV_PGF_HASH(fileid) \
({ \
uint8_t *tmp = (uint8_t *)(fileid); \
tmp[0] + tmp[1] + tmp[2]; \
})
int tdbEnvRgstPageFile(TENV *pEnv, SPgFile *pPgFile) {
SPgFileList *pBucket;
......@@ -145,5 +152,10 @@ int tdbEnvRgstPageFile(TENV *pEnv, SPgFile *pPgFile) {
pBucket = pEnv->pgfht.buckets + (TDB_ENV_PGF_HASH(pPgFile->fileid) % TDB_ENV_PGF_HASH_BUCKETS); // TODO
TD_DLIST_APPEND_WITH_FIELD(pBucket, pPgFile, envHash);
return 0;
}
int tdbEnvRgstDB(TENV *pEnv, TDB *pDb) {
// TODO
return 0;
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ const char* tdbEnvGetRootDir(TENV* pEnv);
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
int tdbEnvRgstPageFile(TENV* pEnv, SPgFile* pPgFile);
int tdbEnvRgstDB(TENV* pEnv, TDB* pDb);
#ifdef __cplusplus
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册