From f1e2ca50749bce43dc466c014acbcb0e57a1a2d4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 16 Feb 2022 03:29:35 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbEnv.c | 22 ++++++++++++++++++++-- source/libs/tdb/src/db/tdbJournal.c | 19 +++++++++++++++---- source/libs/tdb/src/inc/tdbJournal.h | 7 +++++++ source/libs/tdb/src/inc/tdbPgFile.h | 3 ++- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 237220d155..8a4cab1e29 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -133,12 +133,30 @@ static int tdbEnvDestroy(TENV *pEnv) { } int tdbEnvBeginTxn(TENV *pEnv) { - // TODO + SJournal *pJournal; + int ret; + + ASSERT(pEnv->pJournal == NULL); + + pJournal = (SJournal *)(&(pEnv[1])); + ret = tdbOpenJournal(pJournal); + if (ret < 0) { + // TODO: handle error + return -1; + } + + pEnv->pJournal = pJournal; return 0; } int tdbEnvCommit(TENV *pEnv) { - // TODO + SJournal *pJournal; + + ASSERT(pEnv->pJournal != NULL); + + pJournal = pEnv->pJournal; + tdbCloseJournal(pJournal); + /* TODO */ return 0; } diff --git a/source/libs/tdb/src/db/tdbJournal.c b/source/libs/tdb/src/db/tdbJournal.c index ace622fd72..80e29dd09e 100644 --- a/source/libs/tdb/src/db/tdbJournal.c +++ b/source/libs/tdb/src/db/tdbJournal.c @@ -13,7 +13,18 @@ * along with this program. If not, see . */ -struct SJournal { - char *jname; - int fd; -}; \ No newline at end of file +#include "tdbInt.h" + +int tdbOpenJournal(SJournal *pJournal) { + // pJournal->fd = open(); + if (pJournal->fd < 0) { + // TODO: handle error + return -1; + } + return 0; +} + +int tdbCloseJournal(SJournal *pJournal) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbJournal.h b/source/libs/tdb/src/inc/tdbJournal.h index 685e2bcb16..918b2fa06d 100644 --- a/source/libs/tdb/src/inc/tdbJournal.h +++ b/source/libs/tdb/src/inc/tdbJournal.h @@ -21,6 +21,13 @@ extern "C" { #endif typedef struct SJournal SJournal; +struct SJournal { + char jname[64]; + int fd; +}; + +int tdbOpenJournal(SJournal *pJournal); +int tdbCloseJournal(SJournal *pJournal); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbPgFile.h b/source/libs/tdb/src/inc/tdbPgFile.h index 99fb811c9e..97f3fe289d 100644 --- a/source/libs/tdb/src/inc/tdbPgFile.h +++ b/source/libs/tdb/src/inc/tdbPgFile.h @@ -37,9 +37,10 @@ struct SPgFile { char * fname; // backend file name uint8_t fileid[TDB_FILE_ID_LEN]; // file id int fd; + pgno_t dbSize; + pgno_t dbNewSize; SPgFileListNode envHash; SPgFileListNode envPgfList; - // TDB * pDb; // For a SPgFile for multiple databases, this is the mapping DB. }; int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv); -- GitLab