diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 93fc75269c..aa3e4c6b90 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -690,7 +690,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nNews = 0; int cntNews[5] = {0}; // TODO: maybe 5 is not enough int szNews[5] = {0}; - int maxPageCapacity; // TODO { // Get how many new pages are needed and the new distribution @@ -699,11 +698,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SPage *pPage = pOlds[i]; SCell *pCell; int cellBytes; + for (int cIdx = 0; cIdx < TDB_PAGE_TOTAL_CELLS(pPage); cIdx++) { pCell = tdbPageGetCell(pPage, cIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - if (szNews[nNews] + cellBytes > maxPageCapacity) { + if (szNews[nNews] + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { nNews++; } cntNews[nNews]++; diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 479c7603e1..258eafcf63 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -99,6 +99,7 @@ struct SPage { // APIs #define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) +#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) #define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);