This commit is contained in:
Hongze Cheng 2022-04-02 05:16:32 +00:00
parent 08ed99b069
commit 9dea86249c
3 changed files with 11 additions and 18 deletions

View File

@ -36,7 +36,7 @@ struct SPCache {
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
static int tdbPCacheOpenImpl(SPCache *pCache);
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid);
static void tdbPCachePinPage(SPCache *pCache, SPage *pPage);
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
@ -78,12 +78,12 @@ int tdbPCacheClose(SPCache *pCache) {
return 0;
}
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) {
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid) {
SPage *pPage;
tdbPCacheLock(pCache);
pPage = tdbPCacheFetchImpl(pCache, pPgid, alcNewPage);
pPage = tdbPCacheFetchImpl(pCache, pPgid);
if (pPage) {
TDB_REF_PAGE(pPage);
}
@ -106,7 +106,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) {
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) {
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid) {
SPage *pPage;
// 1. Search the hash table
@ -116,12 +116,10 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
pPage = pPage->pHashNext;
}
if (pPage || !alcNewPage) {
if (pPage) {
tdbPCachePinPage(pCache, pPage);
}
return pPage;
if (pPage) {
tdbPCachePinPage(pCache, pPage);
}
return pPage;
// 2. Try to allocate a new page from the free list
if (pCache->pFree) {
@ -261,17 +259,12 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
return 0;
}
static int tdbPCacheDestroyPage(SPage *pPage) {
// TODO
return 0;
}
static int tdbPCacheCloseImpl(SPCache *pCache) {
SPage *pPage;
for (pPage = pCache->pList; pPage; pPage = pCache->pList) {
pCache->pList = pPage->pCacheNext;
tdbPCacheDestroyPage(pPage);
tdbPageDestroy(pPage, NULL, NULL);
}
tdbPCacheDestroyLock(pCache);

View File

@ -227,7 +227,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage
// Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = pgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
pPage = tdbPCacheFetch(pPager->pCache, &pgid);
if (pPage == NULL) {
return -1;
}
@ -263,7 +263,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
// Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = *ppgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1);
pPage = tdbPCacheFetch(pPager->pCache, &pgid);
if (pPage == NULL) {
return -1;
}

View File

@ -48,7 +48,7 @@ extern "C" {
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
int tdbPCacheClose(SPCache *pCache);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid);
void tdbPCacheRelease(SPCache *pCache, SPage *pPage);
int tdbPCacheGetPageSize(SPCache *pCache);