This commit is contained in:
Hongze Cheng 2022-02-16 07:54:11 +00:00
parent 8f6781a7bb
commit cada7c3912
3 changed files with 11 additions and 3 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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