From cada7c3912ea9688dbcddc41bbdde878be0e03bc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 16 Feb 2022 07:54:11 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbEnv.c | 4 ++-- source/libs/tdb/src/db/tdbJournal.c | 6 +++++- source/libs/tdb/test/tdbTest.cpp | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 8a4cab1e29..241c21cb9b 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -45,12 +45,12 @@ int tdbEnvCreate(TENV **ppEnv, const char *rootDir) { *ppEnv = NULL; slen = strlen(rootDir); - pEnv = (TENV *)calloc(1, sizeof(*pEnv) + slen + 1); + pEnv = (TENV *)calloc(1, sizeof(*pEnv) + sizeof(SJournal) + slen + 1); if (pEnv == NULL) { return -1; } - pEnv->rootDir = (char *)(&pEnv[1]); + pEnv->rootDir = (char *)(&pEnv[1]) + sizeof(SJournal); pEnv->pgSize = TDB_DEFAULT_PGSIZE; pEnv->cacheSize = TDB_DEFAULT_CACHE_SIZE; diff --git a/source/libs/tdb/src/db/tdbJournal.c b/source/libs/tdb/src/db/tdbJournal.c index 80e29dd09e..80b28a3855 100644 --- a/source/libs/tdb/src/db/tdbJournal.c +++ b/source/libs/tdb/src/db/tdbJournal.c @@ -16,11 +16,15 @@ #include "tdbInt.h" int tdbOpenJournal(SJournal *pJournal) { - // pJournal->fd = open(); + TENV *pEnv; + char *jname; + + pJournal->fd = open(jname, O_CREAT | O_RDWR, 0755); if (pJournal->fd < 0) { // TODO: handle error return -1; } + return 0; } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index db6a27b3e9..4433d3288d 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -20,6 +20,8 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(tdbEnvOpen(pEnv), 0); #if 1 + + tdbEnvBeginTxn(pEnv); // DB GTEST_ASSERT_EQ(tdbCreate(&pDb1), 0); @@ -39,6 +41,8 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(tdbOpen(pDb1, "db.db", "db1", pEnv), 0); + tdbEnvCommit(pEnv); + #if 0 // Insert -- GitLab