提交 eb5b10d1 编写于 作者: H Hongze Cheng

more TDB

上级 ec3f723d
...@@ -86,8 +86,12 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) { ...@@ -86,8 +86,12 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) {
} }
void tdbPCacheRelease(SPage *pPage) { void tdbPCacheRelease(SPage *pPage) {
pPage->nRef--; i32 nRef;
if (pPage->nRef == 0) {
nRef = TDB_UNREF_PAGE(pPage);
ASSERT(nRef >= 0);
if (nRef == 0) {
if (1 /*TODO: page still clean*/) { if (1 /*TODO: page still clean*/) {
tdbPCacheUnpinPage(pPage); tdbPCacheUnpinPage(pPage);
} else { } else {
...@@ -125,6 +129,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe ...@@ -125,6 +129,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
if (pPage) { if (pPage) {
tdbPCachePinPage(pPage); tdbPCachePinPage(pPage);
} }
TDB_REF_PAGE(pPage);
return pPage; return pPage;
} }
...@@ -153,6 +158,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe ...@@ -153,6 +158,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
pPage->pLruNext = NULL; pPage->pLruNext = NULL;
pPage->pPager = NULL; pPage->pPager = NULL;
tdbPCacheAddPageToHash(pPage); tdbPCacheAddPageToHash(pPage);
TDB_REF_PAGE(pPage);
} }
return pPage; return pPage;
...@@ -172,15 +178,28 @@ static void tdbPCachePinPage(SPage *pPage) { ...@@ -172,15 +178,28 @@ static void tdbPCachePinPage(SPage *pPage) {
} }
static void tdbPCacheUnpinPage(SPage *pPage) { static void tdbPCacheUnpinPage(SPage *pPage) {
// Add current page to the LRU list
SPCache *pCache; SPCache *pCache;
i32 nRef;
pCache = pPage->pCache;
tdbPCacheLock(pCache);
nRef = TDB_PAGE_REF(pPage);
ASSERT(nRef >= 0);
if (nRef == 0) {
// Add the page to LRU list
ASSERT(pPage->pLruNext == NULL);
pPage->pLruPrev = &(pCache->lru); pPage->pLruPrev = &(pCache->lru);
pPage->pLruNext = pCache->lru.pLruNext; pPage->pLruNext = pCache->lru.pLruNext;
pCache->lru.pLruNext->pLruPrev = pPage; pCache->lru.pLruNext->pLruPrev = pPage;
pCache->lru.pLruNext = pPage; pCache->lru.pLruNext = pPage;
}
pCache->nRecyclable++; pCache->nRecyclable++;
tdbPCacheUnlock(pCache);
} }
static void tdbPCacheRemovePageFromHash(SPage *pPage) { static void tdbPCacheRemovePageFromHash(SPage *pPage) {
...@@ -236,6 +255,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { ...@@ -236,6 +255,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pPage->isAnchor = 0; pPage->isAnchor = 0;
pPage->isLocalPage = 1; pPage->isLocalPage = 1;
pPage->pCache = pCache; pPage->pCache = pCache;
TDB_INIT_PAGE_REF(pPage);
pPage->pHashNext = NULL; pPage->pHashNext = NULL;
pPage->pLruNext = NULL; pPage->pLruNext = NULL;
pPage->pLruPrev = NULL; pPage->pLruPrev = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册