more tdb delte
This commit is contained in:
parent
b2e5a36419
commit
52d157718b
|
@ -1394,29 +1394,76 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbBtcDelete(SBTC *pBtc) {
|
int tdbBtcDelete(SBTC *pBtc) {
|
||||||
#if 0
|
int idx = pBtc->idx;
|
||||||
// check transaction
|
int nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||||
if (!TDB_TXN_IS_WRITE(pBtc->pTxn)) {
|
SPager *pPager = pBtc->pBt->pPager;
|
||||||
|
const void *pKey;
|
||||||
|
i8 iPage;
|
||||||
|
SPage *pPage;
|
||||||
|
SPgno pgno;
|
||||||
|
SCell *pCell;
|
||||||
|
int szCell;
|
||||||
|
int nKey;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ASSERT(idx >= 0 && idx < nCells);
|
||||||
|
|
||||||
|
// drop the cell on the leaf
|
||||||
|
ret = tdbPagerWrite(pPager, pBtc->pPage);
|
||||||
|
if (ret < 0) {
|
||||||
|
ASSERT(0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = pBtc->idx;
|
|
||||||
int nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
|
||||||
|
|
||||||
tdbPagerWrite(pBtc->pBt->pPager, pBtc->pPage);
|
|
||||||
|
|
||||||
tdbPageDropCell(pBtc->pPage, idx);
|
tdbPageDropCell(pBtc->pPage, idx);
|
||||||
|
|
||||||
|
// update interior page or do balance
|
||||||
if (idx == nCells - 1) {
|
if (idx == nCells - 1) {
|
||||||
// drop cells above
|
if (idx) {
|
||||||
for (;;) {
|
pBtc->idx--;
|
||||||
/* code */
|
tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL);
|
||||||
|
|
||||||
|
// loop to update the interial page
|
||||||
|
pgno = TDB_PAGE_PGNO(pBtc->pPage);
|
||||||
|
for (iPage = pBtc->iPage - 1; iPage >= 0; iPage--) {
|
||||||
|
pPage = pBtc->pgStack[iPage];
|
||||||
|
idx = pBtc->idxStack[iPage];
|
||||||
|
nCells = TDB_PAGE_TOTAL_CELLS(pPage);
|
||||||
|
|
||||||
|
if (idx < nCells) {
|
||||||
|
ret = tdbPagerWrite(pPager, pPage);
|
||||||
|
if (ret < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do balance
|
// update the cell with new key
|
||||||
}
|
pCell = tdbOsMalloc(nKey + 9);
|
||||||
#endif
|
tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell);
|
||||||
|
|
||||||
|
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbOsFree(pCell);
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tdbOsFree(pCell);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
pgno = TDB_PAGE_PGNO(pPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// delete the leaf page and do balance (TODO)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tdbBtcUpsert(SBTC *pBtc) {
|
||||||
|
ASSERT(0);
|
||||||
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,11 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
|
||||||
|
tdbPageDropCell(pPage, idx);
|
||||||
|
return tdbPageInsertCell(pPage, idx, pCell, szCell, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int tdbPageDropCell(SPage *pPage, int idx) {
|
int tdbPageDropCell(SPage *pPage, int idx) {
|
||||||
int lidx;
|
int lidx;
|
||||||
SCell *pCell;
|
SCell *pCell;
|
||||||
|
|
|
@ -143,6 +143,7 @@ int tdbBtcMoveToPrev(SBTC *pBtc);
|
||||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||||
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
||||||
int tdbBtcDelete(SBTC *pBtc);
|
int tdbBtcDelete(SBTC *pBtc);
|
||||||
|
int tdbBtcUpsert(SBTC *pBtc);
|
||||||
|
|
||||||
// tdbPager.c ====================================
|
// tdbPager.c ====================================
|
||||||
|
|
||||||
|
@ -280,6 +281,7 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
|
||||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||||
int tdbPageDropCell(SPage *pPage, int idx);
|
int tdbPageDropCell(SPage *pPage, int idx);
|
||||||
|
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell);
|
||||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
||||||
int tdbPageCapacity(int pageSize, int amHdrSize);
|
int tdbPageCapacity(int pageSize, int amHdrSize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue