提交 3989a061 编写于 作者: H Hongze Cheng

more TDB

上级 123dc0cd
set(META_DB_IMPL_LIST "BDB" "TDB") set(META_DB_IMPL_LIST "BDB" "TDB")
set(META_DB_IMPL "BDB" CACHE STRING "Use BDB as the default META implementation") set(META_DB_IMPL "TDB" CACHE STRING "Use BDB as the default META implementation")
set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST}) set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST})
if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST) if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST)
......
...@@ -22,16 +22,21 @@ ...@@ -22,16 +22,21 @@
extern "C" { extern "C" {
#endif #endif
typedef struct STDb TDB; typedef struct STDb TDB;
typedef struct STDbEnv TENV; typedef struct STDbEnv TENV;
typedef struct STDbCurosr TDBC;
// TEVN // TEVN
int tdbEnvOpen(TENV **ppEnv);
int tdbEnvClose(TENV *pEnv);
// TDB // TDB
int tdbCreate(TDB **ppDb); int tdbCreate(TDB **ppDb);
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv); int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv);
int tdbClose(TDB *pDb); int tdbClose(TDB *pDb);
// TDBC
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData); static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
int pgFileOpen(const char *fname, SPgCache *pPgCache, SPgFile **ppPgFile) { int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache) {
SPgFile *pPgFile; SPgFile *pPgFile;
*ppPgFile = NULL; *ppPgFile = NULL;
......
...@@ -42,8 +42,11 @@ static int tdbDestroy(TDB *pDb) { ...@@ -42,8 +42,11 @@ static int tdbDestroy(TDB *pDb) {
} }
int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
TDB *pDb; TDB * pDb;
int ret; int ret;
uint8_t fileid[TDB_FILE_ID_LEN];
SPgFile * pPgFile;
SPgCache *pPgCache;
// Create DB if DB handle is not created yet // Create DB if DB handle is not created yet
if (ppDb == NULL) { if (ppDb == NULL) {
...@@ -56,12 +59,31 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { ...@@ -56,12 +59,31 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
// Create a default ENV if pEnv is not set // Create a default ENV if pEnv is not set
if (pEnv == NULL) { if (pEnv == NULL) {
// if ((ret = tenvOpen(&pEnv)) != 0) { if ((ret = tdbEnvOpen(&pEnv)) != 0) {
// return -1; return -1;
// } }
} }
/* TODO */ pDb->pEnv = pEnv;
// register DB to ENV
ASSERT(fname != NULL);
// Check if file exists (TODO)
// Check if the SPgFile already opened
pPgFile = tdbEnvGetPageFile(pEnv, fileid);
if (pPgFile == NULL) {
pPgCache = tdbEnvGetPgCache(pEnv);
if ((ret = pgFileOpen(&pPgFile, fname, pPgCache)) != 0) {
return -1;
}
}
pDb->pPgFile = pPgFile;
// open the access method (TODO)
return 0; return 0;
} }
......
...@@ -21,4 +21,21 @@ struct STDbEnv { ...@@ -21,4 +21,21 @@ struct STDbEnv {
struct { struct {
} pgfht; // page file hash table; } pgfht; // page file hash table;
SPgCache pgc; // page cache SPgCache pgc; // page cache
}; };
\ No newline at end of file
int tdbEnvOpen(TENV **ppEnv) {
// TODO
return 0;
}
int tdbEnvClose(TENV *pEnv) {
// TODO
return 0;
}
SPgFile *tdbEnvGetPageFile(TENV *pEnv, const uint8_t fileid[]) {
// TODO
return NULL;
}
SPgCache *tdbEnvGetPgCache(TENV *pEnv) { return &(pEnv->pgc); }
\ No newline at end of file
...@@ -30,7 +30,7 @@ struct SPgFile { ...@@ -30,7 +30,7 @@ struct SPgFile {
pgno_t pgFileSize; pgno_t pgFileSize;
}; };
int pgFileOpen(const char *fname, SPgCache *pPgCache, SPgFile **ppPgFile); int pgFileOpen(SPgFile **ppPgFile, const char *fname, SPgCache *pPgCache);
int pgFileClose(SPgFile *pPgFile); int pgFileClose(SPgFile *pPgFile);
SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno); SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno);
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
extern "C" { extern "C" {
#endif #endif
SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]);
SPgCache* tdbEnvGetPgCache(TENV* pEnv);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册