diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index bd633fa70af2de0bf2d2ab1301d149731aae96da..429bd2143fd36111727404b7e8380c76336e784d 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -1,5 +1,5 @@ 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}) if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST) diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 7784282a24e01c75f08f19478afa9abb97024e49..63da7999c9f3fd9d1ac31d8bafba64096b1aa4f5 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -22,16 +22,21 @@ extern "C" { #endif -typedef struct STDb TDB; -typedef struct STDbEnv TENV; +typedef struct STDb TDB; +typedef struct STDbEnv TENV; +typedef struct STDbCurosr TDBC; // TEVN +int tdbEnvOpen(TENV **ppEnv); +int tdbEnvClose(TENV *pEnv); // TDB int tdbCreate(TDB **ppDb); int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv); int tdbClose(TDB *pDb); +// TDBC + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/db/pgfile.c b/source/libs/tdb/src/db/pgfile.c index f7d4eef7994c17950f6bdaada0fdc3cc1f2b1332..1c3e2700b4b6ca109fbff588753f199e63bf3c6a 100644 --- a/source/libs/tdb/src/db/pgfile.c +++ b/source/libs/tdb/src/db/pgfile.c @@ -17,7 +17,7 @@ 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; *ppPgFile = NULL; diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index b5b248eac3eca18cda749b487317090525523fa1..ffaef0addd5f625e50f2d6ae92d8ffb31d0b4614 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -42,8 +42,11 @@ static int tdbDestroy(TDB *pDb) { } int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) { - TDB *pDb; - int ret; + TDB * pDb; + int ret; + uint8_t fileid[TDB_FILE_ID_LEN]; + SPgFile * pPgFile; + SPgCache *pPgCache; // Create DB if DB handle is not created yet if (ppDb == NULL) { @@ -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 if (pEnv == NULL) { - // if ((ret = tenvOpen(&pEnv)) != 0) { - // return -1; - // } + if ((ret = tdbEnvOpen(&pEnv)) != 0) { + 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; } diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index c738b691c8e297f6d1d513d3a5fc6700b4564734..302c238927ead0e69ee569e84200fb8e24796da6 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -21,4 +21,21 @@ struct STDbEnv { struct { } pgfht; // page file hash table; 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 diff --git a/source/libs/tdb/src/inc/pgfile.h b/source/libs/tdb/src/inc/pgfile.h index ad59fc711c64066d687766ad072360321705ed70..cb954ba94606418310379a9ab045e8b35dcacfbf 100644 --- a/source/libs/tdb/src/inc/pgfile.h +++ b/source/libs/tdb/src/inc/pgfile.h @@ -30,7 +30,7 @@ struct SPgFile { 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); SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno); diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 2bd93fc530d5ac2fd3a4ea1efc75192dc229cc38..a68ae0c7e93f62411091484b031459da51c04eae 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -20,6 +20,9 @@ extern "C" { #endif +SPgFile* tdbEnvGetPageFile(TENV* pEnv, const uint8_t fileid[]); +SPgCache* tdbEnvGetPgCache(TENV* pEnv); + #ifdef __cplusplus } #endif