diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 64ae8d1c3f34429298f2cb656ae7d7a704b0be5d..65d1c303284d706d60c0dd05a1037831ce9a6745 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 bd680da09ede6a99517ce0ee1ba2bb128b2a1445..7b08da4ca84791e6ed12509ef32d0726aefd30c2 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 {