fix: dirty new allocated non-dirty page (root leaf without writings)
This commit is contained in:
parent
6af95b3b65
commit
06af04675a
|
@ -321,7 +321,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// 1. TODO: Search the main DB to check if the DB exists
|
// 1. TODO: Search the main DB to check if the DB exists
|
||||||
ret = tdbPagerOpenDB(pBt->pPager, &pgno, true);
|
ret = tdbPagerOpenDB(pBt->pPager, &pgno, true, pBt);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +721,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
int szNewCell;
|
int szNewCell;
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
||||||
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn, pBt);
|
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn,
|
||||||
|
pBt);
|
||||||
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
||||||
tdbOsFree(pNewCell);
|
tdbOsFree(pNewCell);
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1143,8 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt) {
|
static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder, TXN *pTxn,
|
||||||
|
SBTree *pBt) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nPayload;
|
int nPayload;
|
||||||
int maxLocal = pPage->maxLocal;
|
int maxLocal = pPage->maxLocal;
|
||||||
|
|
|
@ -98,7 +98,7 @@ int tdbPagerClose(SPager *pPager) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
|
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt) {
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
SPage *pPage;
|
SPage *pPage;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -114,19 +114,35 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
|
||||||
// pgno = 0;
|
// pgno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (pgno == 0 && toCreate) {
|
if (pgno == 0 && toCreate) {
|
||||||
|
// allocate a new child page
|
||||||
|
TXN txn;
|
||||||
|
tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, 0);
|
||||||
|
|
||||||
|
pPager->inTran = 1;
|
||||||
|
|
||||||
|
SBtreeInitPageArg zArg;
|
||||||
|
zArg.flags = 0x1 | 0x2; // root leaf node;
|
||||||
|
zArg.pBt = pBt;
|
||||||
|
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, &txn);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// ret = tdbPagerAllocPage(pPager, &pPage, &pgno);
|
// ret = tdbPagerAllocPage(pPager, &pPage, &pgno);
|
||||||
// if (ret < 0) {
|
// if (ret < 0) {
|
||||||
// return -1;
|
// return -1;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// // TODO: Need to zero the page
|
// TODO: Need to zero the page
|
||||||
|
|
||||||
// ret = tdbPagerWrite(pPager, pPage);
|
ret = tdbPagerWrite(pPager, pPage);
|
||||||
// if (ret < 0) {
|
if (ret < 0) {
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
tdbTxnClose(&txn);
|
||||||
|
}
|
||||||
|
|
||||||
*ppgno = pgno;
|
*ppgno = pgno;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -184,7 +184,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
|
|
||||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
||||||
int tdbPagerClose(SPager *pPager);
|
int tdbPagerClose(SPager *pPager);
|
||||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
|
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt);
|
||||||
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
||||||
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
||||||
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
||||||
|
@ -318,15 +318,14 @@ static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
|
||||||
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
||||||
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||||
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
||||||
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell, 0, NULL, NULL) + (pPage)->pPageMethods->szOffset)
|
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) \
|
||||||
|
((*(pPage)->xCellSize)(pPage, pCell, 0, NULL, NULL) + (pPage)->pPageMethods->szOffset)
|
||||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
#define TDB_PAGE_OFFSET_SIZE(pPage) ((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);
|
||||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int,
|
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt));
|
||||||
TXN *, SBTree *pBt));
|
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt));
|
||||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int,
|
|
||||||
TXN *, SBTree *pBt));
|
|
||||||
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, TXN *pTxn, SBTree *pBt);
|
int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt);
|
||||||
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt);
|
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt);
|
||||||
|
|
Loading…
Reference in New Issue