From 28d3a1dbe851ab62cc1da3f01035edd57fba669a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 15 Mar 2022 09:52:31 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index e4fe97073a..cd3447de6b 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -36,6 +36,7 @@ struct SBTree { int minLocal; int maxLeaf; int minLeaf; + u8 *pTmp; }; typedef struct __attribute__((__packed__)) { @@ -125,6 +126,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p SCell *pCell; int szCell; int cret; + SBTree *pBt; ret = tdbBtCursorMoveTo(pCur, pKey, kLen, &cret); if (ret < 0) { @@ -146,6 +148,17 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p } } + // TODO: refact code here + pBt = pCur->pBt; + if (!pBt->pTmp) { + pBt->pTmp = (u8 *)malloc(pBt->pageSize); + if (pBt->pTmp == NULL) { + return -1; + } + } + + pCell = pBt->pTmp; + // Encode the cell ret = tdbBtreeEncodeCell(pCur->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); if (ret < 0) { @@ -349,6 +362,9 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { pPage->minLocal = pBt->minLocal; } + // TODO: need to update the SPage.nFree + pPage->nFree = pPage->pFreeEnd - pPage->pFreeStart; + return 0; }