From 16e7fa2e9edff27d12dbcbad60bf992cec06352e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 16 Mar 2022 08:31:51 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 5 +---- source/libs/tdb/src/db/tdbPage.c | 8 ++++++-- source/libs/tdb/test/tdbTest.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 5bdb80e374..47bc7586d7 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -65,6 +65,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg); static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); +static int tdbBtreeBalance(SBtCursor *pCur); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { SBTree *pBt; @@ -180,8 +181,6 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p return -1; } - { -#if 0 // If page is overflow, balance the tree if (pCur->pPage->nOverflow > 0) { ret = tdbBtreeBalance(pCur); @@ -189,8 +188,6 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p return -1; } } -#endif - } return 0; } diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 0529e8b671..df158de756 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -126,10 +126,14 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { int ret; SCell *pTarget; u8 *pTmp; + int j; if (pPage->nOverflow || szCell + pPage->szOffset > pPage->nFree) { - // TODO: Page is full - ASSERT(0); + // TODO: need to figure out if pCell may be used by outside of this function + j = pPage->nOverflow++; + + pPage->apOvfl[j] = pCell; + pPage->aiOvfl[j] = idx; } else { ret = tdbPageAllocate(pPage, szCell, &pTarget); if (ret < 0) { diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index ef6e8de0a7..c68535bdda 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -19,7 +19,7 @@ TEST(tdb_test, simple_test) { char key[64]; char val[64]; - for (int i = 1; i <= 64; i++) { + for (int i = 1; i <= 65; i++) { sprintf(key, "key%d", i); sprintf(val, "value%d", i); ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val));