more TDB
This commit is contained in:
parent
ccef4b0f63
commit
8d7e5385cc
|
@ -211,7 +211,7 @@ static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
|
||||||
pBt = pCur->pBt;
|
pBt = pCur->pBt;
|
||||||
pPager = pBt->pPager;
|
pPager = pBt->pPager;
|
||||||
|
|
||||||
pPage = tdbPagerGet(pPager, pBt->root);
|
pPage = tdbPagerGet(pPager, pBt->root, true);
|
||||||
if (pPage == NULL) {
|
if (pPage == NULL) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,13 +124,15 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPage *tdbPagerGet(SPager *pPager, SPgno pgno) {
|
SPage *tdbPagerGet(SPager *pPager, SPgno pgno, bool toLoad) {
|
||||||
SPgid pgid;
|
SPgid pgid;
|
||||||
SPage *pPage;
|
SPage *pPage;
|
||||||
|
int ret;
|
||||||
|
|
||||||
memcpy(pgid.fileid, pPager->fid, TDB_FILE_ID_LEN);
|
memcpy(pgid.fileid, pPager->fid, TDB_FILE_ID_LEN);
|
||||||
pgid.pgno = pgno;
|
pgid.pgno = pgno;
|
||||||
|
|
||||||
|
// Get page frame from the SPCache
|
||||||
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
|
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
|
||||||
if (pPage == NULL) {
|
if (pPage == NULL) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
@ -138,6 +140,26 @@ SPage *tdbPagerGet(SPager *pPager, SPgno pgno) {
|
||||||
}
|
}
|
||||||
tdbPCacheFetchFinish(pPager->pCache, pPage);
|
tdbPCacheFetchFinish(pPager->pCache, pPage);
|
||||||
|
|
||||||
|
// Zero the page or load page content from backend
|
||||||
|
// according to the options
|
||||||
|
if (pPage->pPager == NULL || !toLoad) {
|
||||||
|
if (!toLoad || pgno >= pPager->dbFileSize) {
|
||||||
|
memset(pPage->pData, 0, pPager->pageSize);
|
||||||
|
} else {
|
||||||
|
ret = tdbPagerReadPage(pPager, pPage);
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO: Need to drop the page
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pPage->pPager) {
|
||||||
|
ASSERT(pPage->pPager == pPager);
|
||||||
|
} else {
|
||||||
|
pPage->pPager = pPager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return pPage;
|
return pPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +190,7 @@ int tdbPagerAllocPage(SPager *pPager, SPage **ppPage, SPgno *ppgno) {
|
||||||
|
|
||||||
if (1 /*TODO: no free page*/) {
|
if (1 /*TODO: no free page*/) {
|
||||||
pgno = ++pPager->dbFileSize;
|
pgno = ++pPager->dbFileSize;
|
||||||
pPage = tdbPagerGet(pPager, pgno);
|
pPage = tdbPagerGet(pPager, pgno, false);
|
||||||
ASSERT(pPage != NULL);
|
ASSERT(pPage != NULL);
|
||||||
} else {
|
} else {
|
||||||
/* TODO: allocate from the free list */
|
/* TODO: allocate from the free list */
|
||||||
|
|
|
@ -132,6 +132,8 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
|
||||||
|
|
||||||
#include "tdbPage.h"
|
#include "tdbPage.h"
|
||||||
|
|
||||||
|
typedef struct SPager SPager;
|
||||||
|
|
||||||
#include "tdbPCache.h"
|
#include "tdbPCache.h"
|
||||||
|
|
||||||
#include "tdbPager.h"
|
#include "tdbPager.h"
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct SPage {
|
||||||
SPage * pLruNext;
|
SPage * pLruNext;
|
||||||
SPage * pLruPrev;
|
SPage * pLruPrev;
|
||||||
SPage * pDirtyNext;
|
SPage * pDirtyNext;
|
||||||
SPage * pPager;
|
SPager * pPager;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache);
|
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache);
|
||||||
|
|
|
@ -20,12 +20,10 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct SPager SPager;
|
|
||||||
|
|
||||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppFile);
|
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppFile);
|
||||||
int tdbPagerClose(SPager *pFile);
|
int tdbPagerClose(SPager *pFile);
|
||||||
int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate);
|
int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate);
|
||||||
SPage *tdbPagerGet(SPager *pFile, SPgno pgno);
|
SPage *tdbPagerGet(SPager *pPager, SPgno pgno, bool toLoad);
|
||||||
int tdbPagerWrite(SPager *pFile, SPage *pPage);
|
int tdbPagerWrite(SPager *pFile, SPage *pPage);
|
||||||
int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno);
|
int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno);
|
||||||
int tdbPagerBegin(SPager *pFile);
|
int tdbPagerBegin(SPager *pFile);
|
||||||
|
|
Loading…
Reference in New Issue