From 8e491c307fec09033b0ceb7b0cda68f7be58de00 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 30 Jun 2023 08:32:39 +0800 Subject: [PATCH] tdb/recyle-ofp: nullize ofp's pager to mark uninitailized --- source/libs/tdb/src/db/tdbBtree.c | 37 ++++++++++++++++++++++--------- source/libs/tdb/src/db/tdbPager.c | 5 +++-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 6921a26f19..382c25bfd5 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1320,6 +1320,10 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, return -1; } + if (pDecoder->ofps) { + taosArrayPush(pDecoder->ofps, &ofp); + } + ofpCell = tdbPageGetCell(ofp, 0); if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { @@ -1354,11 +1358,16 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, int lastKeyPageSpace = 0; // load left key & val to ovpages while (pgno != 0) { + tdbTrace("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p", pTxn, pgno, pCell); ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } + if (pDecoder->ofps) { + taosArrayPush(pDecoder->ofps, &ofp); + } + ofpCell = tdbPageGetCell(ofp, 0); int lastKeyPage = 0; @@ -1567,27 +1576,21 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN * bytes = ofp->maxLocal - sizeof(SPgno); } - SPgno origPgno = pgno; + // SPgno origPgno = pgno; memcpy(&pgno, ofpCell + bytes, sizeof(pgno)); - + /* ret = tdbPagerWrite(pBt->pPager, ofp); if (ret < 0) { tdbError("failed to write page since %s", terrstr()); return -1; } - // tdbPageDropCell(ofp, 0, pTxn, pBt); - // tdbPageZero(ofp, sizeof(SLeafHdr), tdbBtreeCellSize); - // tdbPageZero(ofp, sizeof(SIntHdr), tdbBtreeCellSize); + tdbPageDropCell(ofp, 0, pTxn, pBt); + */ // SIntHdr *pIntHdr = (SIntHdr *)(ofp->pData); // pIntHdr->flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL); // pIntHdr->pgno = 0; // ofp->pPager = NULL; - tdbPagerInsertFreePage(pBt->pPager, ofp, pTxn); - - // printf("tdb recycle, pTxn: %p, pgno:%u\n", pTxn, pgno); - tdbTrace("tdb recycle, pTxn: %p, pgno:%u", pTxn, origPgno); - tdbPagerReturnPage(pPage->pPager, ofp, pTxn); nLeft -= bytes; @@ -2100,6 +2103,9 @@ int tdbBtcDelete(SBTC *pBtc) { return -1; } + // btc.coder.ofps = taosArrayInit(8, sizeof(SPgno)); + pBtc->coder.ofps = taosArrayInit(8, sizeof(SPage *)); + tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); // update interior page or do balance @@ -2155,6 +2161,17 @@ int tdbBtcDelete(SBTC *pBtc) { } } + SArray *ofps = pBtc->coder.ofps; + if (ofps) { + for (int i = 0; i < TARRAY_SIZE(ofps); ++i) { + SPage *ofp = *(SPage **)taosArrayGet(ofps, i); + // tdbPagerInsertFreePage(pBtc->pBt->pPager, ofp, pBtc->pTxn); + } + + taosArrayDestroy(ofps); + pBtc->coder.ofps = NULL; + } + return 0; } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 62702cbf40..5bfcdfa344 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -720,7 +720,8 @@ int tdbPagerInsertFreePage(SPager *pPager, SPage *pPage, TXN *pTxn) { int code = 0; SPgno pgno = TDB_PAGE_PGNO(pPage); - // tdbError("tdb/insert-free-page: tbc get page: %d.", pgno); + // memset(pPage->pData, 0, pPage->pageSize); + tdbTrace("tdb/insert-free-page: tbc recycle page: %d.", pgno); code = tdbTbInsert(pPager->pEnv->pFreeDb, &pgno, sizeof(pgno), NULL, 0, pTxn); if (code < 0) { tdbError("tdb/insert-free-page: tb insert failed with ret: %d.", code); @@ -763,7 +764,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) { } *pPgno = *(SPgno *)pKey; - // tdbError("tdb/remove-free-page: tbc get page: %d.", *pPgno); + tdbTrace("tdb/remove-free-page: tbc get page: %d.", *pPgno); code = tdbTbcDelete(pCur); if (code < 0) { -- GitLab