more TDB
This commit is contained in:
parent
b3b5298510
commit
1075c230ed
|
@ -644,19 +644,11 @@ static int tdbBtreeBalanceStep6(SBtreeBalanceHelper *pBlh) {
|
||||||
|
|
||||||
static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
|
static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
|
||||||
int ret;
|
int ret;
|
||||||
#if 0
|
|
||||||
SBtreeBalanceHelper blh;
|
|
||||||
|
|
||||||
blh.pBt = pBt;
|
|
||||||
blh.pParent = pParent;
|
|
||||||
blh.idx = idx;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int nOlds;
|
int nOlds;
|
||||||
SPage *pOlds[3];
|
SPage *pOlds[3];
|
||||||
|
|
||||||
{
|
{ // Find 3 child pages at most to do balance
|
||||||
// Find 3 child pages at most to do balance
|
|
||||||
int nCells = TDB_PAGE_TOTAL_CELLS(pParent);
|
int nCells = TDB_PAGE_TOTAL_CELLS(pParent);
|
||||||
int sIdx;
|
int sIdx;
|
||||||
if (nCells <= 2) {
|
if (nCells <= 2) {
|
||||||
|
@ -695,7 +687,32 @@ 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
|
||||||
|
|
||||||
|
// loop to find number of pages needed
|
||||||
|
for (int i = 0; i < nOlds; i++) {
|
||||||
|
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) {
|
||||||
|
nNews++;
|
||||||
|
}
|
||||||
|
cntNews[nNews]++;
|
||||||
|
szNews[nNews] = szNews[nNews] + cellBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop to make the distribution even
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Step 1: find two sibling pages and get engough info about the old pages
|
// Step 1: find two sibling pages and get engough info about the old pages
|
||||||
|
|
|
@ -99,6 +99,7 @@ struct SPage {
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
||||||
|
#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);
|
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
||||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
||||||
|
|
Loading…
Reference in New Issue