From a3c9b17212a1a58aebd00f95905226a88396f339 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 28 Jun 2023 10:46:01 +0800 Subject: [PATCH] tdb/ofp: recycl ofps --- source/libs/tdb/src/db/tdbBtree.c | 17 +++++++++++++++++ source/libs/tdb/src/inc/tdbInt.h | 15 ++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 64ae8d1c3f..65d1c30328 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1317,6 +1317,11 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, return -1; } + if (!pDecoder->ofps) { + pDecoder->ofps = taosArrayInit(8, sizeof(SPgno)); + } + taosArrayPush(pDecoder->ofps, &pgno); + ofpCell = tdbPageGetCell(ofp, 0); if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { @@ -2075,6 +2080,14 @@ int tdbBtcDelete(SBTC *pBtc) { tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); + // recycle ofps if any + if (pBtc->coder.ofps) { + for (int i = 0; i < TARRAY_SIZE(pBtc->coder.ofps); ++i) { + SPgno *pgno = taosArrayGet(pBtc->coder.ofps, i); + tdbPagerInsertFreePage(pBtc->pBt->pPager, *pgno, pBtc->pTxn); + } + } + // update interior page or do balance if (idx == nCells - 1) { if (idx) { @@ -2370,6 +2383,10 @@ int tdbBtcClose(SBTC *pBtc) { tdbTxnClose(pBtc->pTxn); } + if (pBtc->coder.ofps) { + taosArrayDestroy(pBtc->coder.ofps); + } + return 0; } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index bd680da09e..7b08da4ca8 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -131,13 +131,14 @@ typedef struct SBtInfo { #define TDB_CELLDECODER_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV & TDB_CELLD_F_VAL) typedef struct { - int kLen; - u8 *pKey; - int vLen; - u8 *pVal; - SPgno pgno; - u8 *pBuf; - u8 freeKV; + int kLen; + u8 *pKey; + int vLen; + u8 *pVal; + SPgno pgno; + u8 *pBuf; + u8 freeKV; + SArray *ofps; } SCellDecoder; struct SBTC { -- GitLab