提交 a59e98b8 编写于 作者: M Minglei Jin

fix(tdb): rollback in-memory pages

上级 a678d632
......@@ -192,6 +192,28 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
return pPage;
}
void tdbPCacheMarkFree(SPCache *pCache, SPage *pPage) {
tdbPCacheLock(pCache);
tdbPCacheRemovePageFromHash(pCache, pPage);
pPage->isFree = 1;
tdbPCacheUnlock(pCache);
}
static void tdbPCacheFreePage(SPCache *pCache, SPage *pPage) {
if (pPage->id < pCache->nPages) {
pPage->pFreeNext = pCache->pFree;
pCache->pFree = pPage;
pPage->isFree = 0;
++pCache->nFree;
tdbTrace("pcache/free page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
} else {
tdbTrace("pcache destroy page: %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
tdbPCacheRemovePageFromHash(pCache, pPage);
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
}
}
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
i32 nRef;
......@@ -209,7 +231,11 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
// nRef = tdbGetPageRef(pPage);
// if (nRef == 0) {
if (pPage->isLocal) {
tdbPCacheUnpinPage(pCache, pPage);
if (!pPage->isFree) {
tdbPCacheUnpinPage(pCache, pPage);
} else {
tdbPCacheFreePage(pCache, pPage);
}
} else {
if (TDB_TXN_IS_WRITE(pTxn)) {
// remove from hash
......
......@@ -524,6 +524,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
tdbPCacheMarkFree(pPager->pCache, pPage);
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
}
......
......@@ -205,6 +205,7 @@ int tdbPagerRollback(SPager *pPager);
u8 isAnchor; \
u8 isLocal; \
u8 isDirty; \
u8 isFree; \
volatile i32 nRef; \
i32 id; \
SPage *pFreeNext; \
......@@ -222,6 +223,7 @@ int tdbPCacheClose(SPCache *pCache);
int tdbPCacheAlter(SPCache *pCache, int32_t nPage);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);
void tdbPCacheMarkFree(SPCache *pCache, SPage *pPage);
int tdbPCacheGetPageSize(SPCache *pCache);
// tdbPage.c ====================================
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册