This commit is contained in:
Hongze Cheng 2022-03-02 08:36:19 +00:00
parent a95d66907a
commit ccef4b0f63
4 changed files with 4 additions and 24 deletions

View File

@ -119,7 +119,6 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
if (pPage || !alcNewPage) { if (pPage || !alcNewPage) {
if (pPage) { if (pPage) {
ASSERT(pPage->isLoad == 1);
tdbPCachePinPage(pPage); tdbPCachePinPage(pPage);
} }
return pPage; return pPage;
@ -148,7 +147,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
if (pPage) { if (pPage) {
memcpy(&(pPage->pgid), pPgid, sizeof(*pPgid)); memcpy(&(pPage->pgid), pPgid, sizeof(*pPgid));
pPage->pLruNext = NULL; pPage->pLruNext = NULL;
pPage->isLoad = 0; pPage->pPager = NULL;
tdbPCacheAddPageToHash(pPage); tdbPCacheAddPageToHash(pPage);
} }

View File

@ -133,26 +133,11 @@ SPage *tdbPagerGet(SPager *pPager, SPgno pgno) {
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1); pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
if (pPage == NULL) { if (pPage == NULL) {
// TODO // TODO: handle error
ASSERT(0); return NULL;
} }
tdbPCacheFetchFinish(pPager->pCache, pPage); tdbPCacheFetchFinish(pPager->pCache, pPage);
if (!(pPage->isLoad)) {
if (pgno > pPager->dbFileSize /*TODO*/) {
memset(pPage->pData, 0, pPager->pageSize);
} else {
if (tdbPagerReadPage(pPager, pPage) < 0) {
// TODO: handle error
return NULL;
}
}
pPage->isLoad = 1;
}
ASSERT(pPage->isLoad);
return pPage; return pPage;
} }

View File

@ -70,9 +70,6 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
#define TDB_IS_SAME_PAGE(pPgid1, pPgid2) (tdbCmprPgId(pPgid1, pPgid2) == 0) #define TDB_IS_SAME_PAGE(pPgid1, pPgid2) (tdbCmprPgId(pPgid1, pPgid2) == 0)
// framd_id_t
typedef int32_t frame_id_t;
// pgsz_t // pgsz_t
#define TDB_MIN_PGSIZE 512 #define TDB_MIN_PGSIZE 512
#define TDB_MAX_PGSIZE 65536 #define TDB_MAX_PGSIZE 65536
@ -131,7 +128,6 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
#define BTREE_MAX_DEPTH 20 #define BTREE_MAX_DEPTH 20
#include "tdbUtil.h" #include "tdbUtil.h"
#include "tdbPage.h" #include "tdbPage.h"

View File

@ -29,7 +29,6 @@ struct SPage {
SPgid pgid; SPgid pgid;
u8 isAnchor; u8 isAnchor;
u8 isLocalPage; u8 isLocalPage;
u8 isLoad;
u8 isDirty; u8 isDirty;
i32 nRef; i32 nRef;
SPCache *pCache; SPCache *pCache;
@ -38,6 +37,7 @@ struct SPage {
SPage * pLruNext; SPage * pLruNext;
SPage * pLruPrev; SPage * pLruPrev;
SPage * pDirtyNext; SPage * pDirtyNext;
SPage * pPager;
}; };
int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache); int tdbPCacheOpen(int pageSize, int cacheSize, int extraSize, SPCache **ppCache);