diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 05d3b748e0ab9ca2ff16a822911bd0f4568698f0..2783108c6d3f0502c535b20b754988efc57b0552 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -526,10 +526,42 @@ static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) { static int tdbBtreeBalanceStep2(SBtreeBalanceHelper *pBlh) { SPage *pPage; + int oidx; + int cidx; + int limit; + SCell *pCell; for (int i = 0; i < pBlh->nOldPages; i++) { pPage = pBlh->pOldPages[i]; - /* code */ + oidx = 0; + cidx = 0; + + if (oidx < pPage->nOverflow) { + limit = pPage->aiOvfl[oidx]; + } else { + limit = pPage->pPageHdr->nCells; + } + + // Loop to copy each cell pointer out + for (;;) { + if (oidx >= pPage->nOverflow && cidx >= pPage->pPageHdr->nCells) break; + + if (cidx < limit) { + // Get local cells + pCell = TDB_PAGE_CELL_AT(pPage, cidx); + } else if (cidx == limit) { + // Get overflow cells + pCell = pPage->apOvfl[oidx++]; + + if (oidx < pPage->nOverflow) { + limit = pPage->aiOvfl[oidx]; + } else { + limit = pPage->pPageHdr->nCells; + } + } else { + ASSERT(0); + } + } } /* TODO */ diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 42656cfc9aeb5c615dcd9444271855f84a234dcd..ee35d0df1dfb94f1bb80969fece9dd255c25b2fa 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -49,7 +49,7 @@ struct SPage { int maxLocal; int minLocal; int nOverflow; - void *apOvfl[4]; + SCell *apOvfl[4]; int aiOvfl[4]; // Fields used by SPCache TDB_PCACHE_PAGE