From afe0f1b6e0c20c5d02b35f6d0f2d0681dbf8eaf7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 1 Mar 2022 03:46:40 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbDb.c | 5 +++++ source/libs/tdb/src/db/tdbPFile.c | 10 ++++++++-- source/libs/tdb/src/inc/tdbDb.h | 1 + source/libs/tdb/test/tdbTest.cpp | 11 ++++++++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 0887971dd3..3532379433 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -69,6 +69,11 @@ int tdbDbClose(STDb *pDb) { return 0; } +int tdbDbDrop(STDb *pDb) { + // TODO + return 0; +} + int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { // TODO return 0; diff --git a/source/libs/tdb/src/db/tdbPFile.c b/source/libs/tdb/src/db/tdbPFile.c index d8607646c1..39e75dfb80 100644 --- a/source/libs/tdb/src/db/tdbPFile.c +++ b/source/libs/tdb/src/db/tdbPFile.c @@ -31,10 +31,16 @@ struct SPFile { u8 inTran; }; -typedef struct { - /* TODO */ +typedef struct __attribute__((__packed__)) { + u8 hdrString[16]; + u16 pageSize; + SPgno freePage; + u32 nFreePages; + u8 reserved[102]; } SFileHdr; +TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct"); + static int tdbPFileReadPage(SPFile *pFile, SPage *pPage); int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile) { diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index e3bc7eec2c..06ea74a83e 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -24,6 +24,7 @@ typedef struct STDb STDb; int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb); int tdbDbClose(STDb *pDb); +int tdbDbDrop(STDb *pDb); int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); #ifdef __cplusplus diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index a8445c0e9b..952233a683 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -15,9 +15,14 @@ TEST(tdb_test, simple_test) { ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); - // Insert some data - ret = tdbDbInsert(pDb, "1", 1, "world", 5); - GTEST_ASSERT_EQ(ret, 0); + // // Insert some data + // ret = tdbDbInsert(pDb, "1", 1, "world", 5); + // GTEST_ASSERT_EQ(ret, 0); + + ret = tdbDbDrop(pDb); + if (pDb == NULL) { + return -1; + } // Close a database tdbDbClose(pDb); -- GitLab