提交 9dea8624 编写于 作者: H Hongze Cheng

refact

上级 08ed99b0
...@@ -36,7 +36,7 @@ struct SPCache { ...@@ -36,7 +36,7 @@ struct SPCache {
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) #define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
static int tdbPCacheOpenImpl(SPCache *pCache); 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 tdbPCachePinPage(SPCache *pCache, SPage *pPage);
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage); static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage); static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
...@@ -78,12 +78,12 @@ int tdbPCacheClose(SPCache *pCache) { ...@@ -78,12 +78,12 @@ int tdbPCacheClose(SPCache *pCache) {
return 0; return 0;
} }
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) { SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid) {
SPage *pPage; SPage *pPage;
tdbPCacheLock(pCache); tdbPCacheLock(pCache);
pPage = tdbPCacheFetchImpl(pCache, pPgid, alcNewPage); pPage = tdbPCacheFetchImpl(pCache, pPgid);
if (pPage) { if (pPage) {
TDB_REF_PAGE(pPage); TDB_REF_PAGE(pPage);
} }
...@@ -106,7 +106,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { ...@@ -106,7 +106,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) {
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; } 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; SPage *pPage;
// 1. Search the hash table // 1. Search the hash table
...@@ -116,12 +116,10 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe ...@@ -116,12 +116,10 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
pPage = pPage->pHashNext; pPage = pPage->pHashNext;
} }
if (pPage || !alcNewPage) {
if (pPage) { if (pPage) {
tdbPCachePinPage(pCache, pPage); tdbPCachePinPage(pCache, pPage);
} }
return pPage; return pPage;
}
// 2. Try to allocate a new page from the free list // 2. Try to allocate a new page from the free list
if (pCache->pFree) { if (pCache->pFree) {
...@@ -261,17 +259,12 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { ...@@ -261,17 +259,12 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
return 0; return 0;
} }
static int tdbPCacheDestroyPage(SPage *pPage) {
// TODO
return 0;
}
static int tdbPCacheCloseImpl(SPCache *pCache) { static int tdbPCacheCloseImpl(SPCache *pCache) {
SPage *pPage; SPage *pPage;
for (pPage = pCache->pList; pPage; pPage = pCache->pList) { for (pPage = pCache->pList; pPage; pPage = pCache->pList) {
pCache->pList = pPage->pCacheNext; pCache->pList = pPage->pCacheNext;
tdbPCacheDestroyPage(pPage); tdbPageDestroy(pPage, NULL, NULL);
} }
tdbPCacheDestroyLock(pCache); tdbPCacheDestroyLock(pCache);
......
...@@ -227,7 +227,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage ...@@ -227,7 +227,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage
// Fetch a page container from the page cache // Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN); memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = pgno; pgid.pgno = pgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1); pPage = tdbPCacheFetch(pPager->pCache, &pgid);
if (pPage == NULL) { if (pPage == NULL) {
return -1; return -1;
} }
...@@ -263,7 +263,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage ...@@ -263,7 +263,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
// Fetch a page container from the page cache // Fetch a page container from the page cache
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN); memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = *ppgno; pgid.pgno = *ppgno;
pPage = tdbPCacheFetch(pPager->pCache, &pgid, 1); pPage = tdbPCacheFetch(pPager->pCache, &pgid);
if (pPage == NULL) { if (pPage == NULL) {
return -1; return -1;
} }
......
...@@ -48,7 +48,7 @@ extern "C" { ...@@ -48,7 +48,7 @@ extern "C" {
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache); int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
int tdbPCacheClose(SPCache *pCache); 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); void tdbPCacheRelease(SPCache *pCache, SPage *pPage);
int tdbPCacheGetPageSize(SPCache *pCache); int tdbPCacheGetPageSize(SPCache *pCache);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册