From 79cdb9c275d18b9cb69a02fb8ba1f3583c879073 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Feb 2022 09:02:46 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/CMakeLists.txt | 3 +++ source/libs/tdb/src/db/tdb.c | 4 ++- source/libs/tdb/src/db/tdbEnv.c | 43 +++++++++++++++++++++++++++++++- source/libs/tdb/src/inc/tdbEnv.h | 2 +- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 9473fb83c2..c55847aa4d 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -10,6 +10,9 @@ target_sources(tdb "src/db/tdbPCache.c" "src/db/tdbPFile.c" "src/db/tdbUtil.c" + "src/db/tdbBtree.c" + "src/db/tdb.c" + "src/db/tdbEnv.c" ) target_include_directories( diff --git a/source/libs/tdb/src/db/tdb.c b/source/libs/tdb/src/db/tdb.c index 6021fba6ee..b82ed66017 100644 --- a/source/libs/tdb/src/db/tdb.c +++ b/source/libs/tdb/src/db/tdb.c @@ -15,6 +15,7 @@ #include "tdbInt.h" +#if 0 struct STDb { char dbname[TDB_MAX_DBNAME_LEN]; SBTree * pBt; // current access method (may extend) @@ -202,4 +203,5 @@ static int tdbDefaultKeyCmprFn(int keyLen1, const void *pKey1, int keyLen2, cons } } return cret; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index d84832226b..0f096ce664 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -17,10 +17,51 @@ struct STEnv { char * rootDir; - SPCache *pCache; int jfd; + SPCache *pCache; }; +int tdbEnvOpen(const char *rootDir, STEnv **ppEnv) { + STEnv * pEnv; + int dsize; + int zsize; + uint8_t *pPtr; + + *ppEnv = NULL; + + dsize = strlen(rootDir); + zsize = sizeof(*pEnv) + dsize + 1; + + pPtr = (uint8_t *)calloc(1, zsize); + if (pPtr == NULL) { + return -1; + } + + pEnv = (STEnv *)pPtr; + pPtr += sizeof(*pEnv); + pEnv->rootDir = pPtr; + memcpy(pEnv->rootDir, rootDir, dsize); + pEnv->rootDir[dsize] = '\0'; + + *ppEnv = pEnv; + return 0; +} + +int tdbEnvClose(STEnv *pEnv) { + // TODO + return 0; +} + +int tdbEnvBegin(STEnv *pEnv) { + // TODO + return 0; +} + +int tdbEnvCommit(STEnv *pEnv) { + // TODO + return 0; +} + #if 0 struct STDbEnv { char * rootDir; // root directory of the environment diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 9de9e4a0e4..04f91c6487 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -22,7 +22,7 @@ extern "C" { typedef struct STEnv STEnv; -int tdbEnvOpen(STEnv **ppEnv); +int tdbEnvOpen(const char *rootDir, STEnv **ppEnv); int tdbEnvClose(STEnv *pEnv); int tdbEnvBegin(STEnv *pEnv);