From 815233ae338724cf2620b9ab3a66c7192abf97b9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Feb 2022 09:28:29 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 23 +++++++++++++++++++++++ source/libs/tdb/src/db/tdbEnv.c | 6 +++++- source/libs/tdb/src/db/tdbPCache.c | 2 +- source/libs/tdb/src/inc/tdbEnv.h | 2 +- source/libs/tdb/src/inc/tdbPCache.h | 2 +- source/libs/tdb/src/inc/tdbPFile.h | 11 ++++++----- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index d35d6a7abd..a3d8c3f53b 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -15,6 +15,29 @@ #include "tdbInt.h" +struct SBTree { + SPgno root; + int keyLen; + int valLen; + SPFile *pFile; + int (*FKeyComparator)(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); +}; + +struct SBtCursor { + SBTree *pBt; +}; + +int tdbBtreeOpen(SPgno root, SBTree **ppBt) { + *ppBt = NULL; + /* TODO */ + return 0; +} + +int tdbBtreeClose(SBTree *pBt) { + // TODO + return 0; +} + #if 0 struct SBtCursor { SBTree *pBtree; diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 0f096ce664..96427f1430 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -21,7 +21,7 @@ struct STEnv { SPCache *pCache; }; -int tdbEnvOpen(const char *rootDir, STEnv **ppEnv) { +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) { STEnv * pEnv; int dsize; int zsize; @@ -43,6 +43,10 @@ int tdbEnvOpen(const char *rootDir, STEnv **ppEnv) { memcpy(pEnv->rootDir, rootDir, dsize); pEnv->rootDir[dsize] = '\0'; + pEnv->jfd = -1; + + tdbPCacheOpen(pageSize, cacheSize, 0, &(pEnv->pCache)); + *ppEnv = pEnv; return 0; } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 4691a46bb8..d2b893c85a 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -89,7 +89,7 @@ SPgHdr *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) { return pPage; } -void tdbFetchFinish(SPCache *pCache, SPgHdr *pPage) { +void tdbPCacheFetchFinish(SPCache *pCache, SPgHdr *pPage) { // TODO } diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 04f91c6487..a45745b4a0 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(const char *rootDir, STEnv **ppEnv); +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv); int tdbEnvClose(STEnv *pEnv); int tdbEnvBegin(STEnv *pEnv); diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h index 4474a603a4..b543815799 100644 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ b/source/libs/tdb/src/inc/tdbPCache.h @@ -39,7 +39,7 @@ struct SPgHdr { int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache); int tdbPCacheClose(SPCache *pCache); SPgHdr *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); -void tdbFetchFinish(SPCache *pCache, SPgHdr *pPage); +void tdbPCacheFetchFinish(SPCache *pCache, SPgHdr *pPage); void tdbPCacheRelease(SPgHdr *pHdr); #ifdef __cplusplus diff --git a/source/libs/tdb/src/inc/tdbPFile.h b/source/libs/tdb/src/inc/tdbPFile.h index a6b4620f14..e1133b9951 100644 --- a/source/libs/tdb/src/inc/tdbPFile.h +++ b/source/libs/tdb/src/inc/tdbPFile.h @@ -22,11 +22,12 @@ extern "C" { typedef struct SPFile SPFile; -int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile); -int tdbPFileClose(SPFile *pFile); -int tdbPFileBegin(SPFile *pFile); -int tdbPFileCommit(SPFile *pFile); -int tdbPFileRollback(SPFile *pFile); +int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile); +int tdbPFileClose(SPFile *pFile); +void *tdbPFileGet(SPFile *pFile, SPgno pgno); +int tdbPFileBegin(SPFile *pFile); +int tdbPFileCommit(SPFile *pFile); +int tdbPFileRollback(SPFile *pFile); #ifdef __cplusplus } -- GitLab