From 0b752392aa482ab45cd38d6d78a4112c84782042 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 06:24:16 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a05202f456..da11eb099a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -495,17 +495,17 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } nOlds = 3; } - for (int i = 0; i < nOlds; i++, sIdx++) { - ASSERT(sIdx <= nCells); + for (int i = 0; i < nOlds; i++) { + ASSERT(sIdx + i <= nCells); SPgno pgno; - if (sIdx == nCells) { + if (sIdx + i == nCells) { ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); pgno = ((SIntHdr *)(pParent->pData))->pgno; } else { SCell *pCell; - pCell = tdbPageGetCell(pParent, sIdx); + pCell = tdbPageGetCell(pParent, sIdx + i); pgno = *(SPgno *)pCell; } @@ -515,6 +515,15 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return -1; } } + // drop the cells + for (int i = 0; i < nOlds; i++) { + nCells = TDB_PAGE_TOTAL_CELLS(pParent); + if (sIdx < nCells) { + tdbPageDropCell(pParent, sIdx); + } else { + ((SIntHdr *)pParent->pData)->pgno = 0; + } + } } int nNews = 0; @@ -657,6 +666,16 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SCellDecoder cd; for (int iNew = 0; iNew < nNews; iNew++) { + if (iNew == nNews - 1) { + // The last new page + + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + if (pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + break; + } + } + tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); @@ -664,6 +683,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + int k = 0; + return 0; } -- GitLab