more TDB
This commit is contained in:
parent
f3c10f886c
commit
df12ae0d79
|
@ -598,10 +598,56 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: sort the page according to the page number
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ // Do the actual cell distribution
|
||||||
// Do the actual redistribute
|
|
||||||
|
SPage *pTPage[2];
|
||||||
|
int tPage, tIdx, iOld;
|
||||||
|
SCell *pCell;
|
||||||
|
int szCell;
|
||||||
|
SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt};
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
ret = tdbPageCreate(pOlds[0]->pageSize, &pTPage[i], NULL, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tPage = 0;
|
||||||
|
tIdx = 0;
|
||||||
|
iOld = 0;
|
||||||
|
tdbBtreeZeroPage(pTPage[tPage], &iarg);
|
||||||
|
tdbPageCopy(pOlds[iOld++], pTPage[tPage]);
|
||||||
|
|
||||||
|
for (int iNew = 0; iNew < nNews; iNew++) {
|
||||||
|
// fill the iNew page
|
||||||
|
tdbBtreeZeroPage(pNews[iNew], &iarg);
|
||||||
|
|
||||||
|
for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) {
|
||||||
|
while (tIdx >= TDB_PAGE_TOTAL_CELLS(pTPage[tPage])) {
|
||||||
|
tPage = (tPage + 1) % 2;
|
||||||
|
tIdx = 0;
|
||||||
|
|
||||||
|
tdbBtreeZeroPage(pTPage[tPage], &iarg);
|
||||||
|
tdbPageCopy(pOlds[iOld++], pTPage[tPage]);
|
||||||
|
}
|
||||||
|
|
||||||
|
pCell = tdbPageGetCell(pTPage[tPage], tIdx);
|
||||||
|
szCell = tdbBtreeCellSize(pTPage[tPage], pCell);
|
||||||
|
|
||||||
|
tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell);
|
||||||
|
|
||||||
|
tIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
tdbPageDestroy(pTPage[i], NULL, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -57,8 +57,6 @@ static void tdbPCachePinPage(SPage *pPage);
|
||||||
static void tdbPCacheRemovePageFromHash(SPage *pPage);
|
static void tdbPCacheRemovePageFromHash(SPage *pPage);
|
||||||
static void tdbPCacheAddPageToHash(SPage *pPage);
|
static void tdbPCacheAddPageToHash(SPage *pPage);
|
||||||
static void tdbPCacheUnpinPage(SPage *pPage);
|
static void tdbPCacheUnpinPage(SPage *pPage);
|
||||||
static void *tdbOsMalloc(void *arg, size_t size);
|
|
||||||
static void tdbOsFree(void *arg, void *ptr);
|
|
||||||
|
|
||||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
||||||
SPCache *pCache;
|
SPCache *pCache;
|
||||||
|
@ -257,7 +255,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
||||||
pCache->nFree = 0;
|
pCache->nFree = 0;
|
||||||
pCache->pFree = NULL;
|
pCache->pFree = NULL;
|
||||||
for (int i = 0; i < pCache->cacheSize; i++) {
|
for (int i = 0; i < pCache->cacheSize; i++) {
|
||||||
ret = tdbPageCreate(pCache->pageSize, &pPage, tdbOsMalloc, NULL);
|
ret = tdbPageCreate(pCache->pageSize, &pPage, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -297,13 +295,3 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
|
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
|
||||||
|
|
||||||
static void *tdbOsMalloc(void *arg, size_t size) {
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
ptr = malloc(size);
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tdbOsFree(void *arg, void *ptr) { free(ptr); }
|
|
|
@ -39,6 +39,16 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize);
|
||||||
|
|
||||||
int tdbPRead(int fd, void *pData, int count, i64 offset);
|
int tdbPRead(int fd, void *pData, int count, i64 offset);
|
||||||
|
|
||||||
|
static inline void *tdbOsMalloc(void *arg, size_t size) {
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
ptr = malloc(size);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void tdbOsFree(void *arg, void *ptr) { free(ptr); }
|
||||||
|
|
||||||
static inline int tdbPutVarInt(u8 *p, int v) {
|
static inline int tdbPutVarInt(u8 *p, int v) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
|
||||||
|
|
||||||
*ppPage = NULL;
|
*ppPage = NULL;
|
||||||
size = pageSize + sizeof(*pPage);
|
size = pageSize + sizeof(*pPage);
|
||||||
|
if (xMalloc == NULL) {
|
||||||
|
xMalloc = tdbOsMalloc;
|
||||||
|
}
|
||||||
|
|
||||||
ptr = (u8 *)((*xMalloc)(arg, size));
|
ptr = (u8 *)((*xMalloc)(arg, size));
|
||||||
if (pPage == NULL) {
|
if (pPage == NULL) {
|
||||||
|
@ -73,6 +76,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
|
||||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) {
|
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) {
|
||||||
u8 *ptr;
|
u8 *ptr;
|
||||||
|
|
||||||
|
if (!xFree) {
|
||||||
|
xFree = tdbOsFree;
|
||||||
|
}
|
||||||
|
|
||||||
ptr = pPage->pData;
|
ptr = pPage->pData;
|
||||||
(*xFree)(arg, ptr);
|
(*xFree)(arg, ptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue