tdb/ofp-recycle: new ofps list with pager
This commit is contained in:
parent
8e491c307f
commit
f89b43b64c
|
@ -234,7 +234,9 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
|
|||
|
||||
tdbBtcOpen(&btc, pBt, pTxn);
|
||||
/*
|
||||
btc.coder.ofps = taosArrayInit(8, sizeof(SPgno));
|
||||
btc.coder.ofps = taosArrayInit(8, sizeof(SPage *));
|
||||
// btc.coder.ofps = taosArrayInit(8, sizeof(SPgno));
|
||||
//pBtc->coder.ofps = taosArrayInit(8, sizeof(SPage *));
|
||||
*/
|
||||
tdbTrace("tdb delete, btc: %p, pTxn: %p", &btc, pTxn);
|
||||
|
||||
|
@ -256,7 +258,18 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
|
|||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
SArray *ofps = btc.coder.ofps;
|
||||
if (ofps) {
|
||||
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
||||
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
||||
tdbPagerInsertFreePage(btc.pBt->pPager, ofp, btc.pTxn);
|
||||
}
|
||||
|
||||
taosArrayDestroy(ofps);
|
||||
btc.coder.ofps = NULL;
|
||||
}
|
||||
*/
|
||||
tdbBtcClose(&btc);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1319,11 +1332,11 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (pDecoder->ofps) {
|
||||
taosArrayPush(pDecoder->ofps, &ofp);
|
||||
}
|
||||
|
||||
*/
|
||||
ofpCell = tdbPageGetCell(ofp, 0);
|
||||
|
||||
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
|
||||
|
@ -1363,11 +1376,11 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
|||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (pDecoder->ofps) {
|
||||
taosArrayPush(pDecoder->ofps, &ofp);
|
||||
}
|
||||
|
||||
*/
|
||||
ofpCell = tdbPageGetCell(ofp, 0);
|
||||
|
||||
int lastKeyPage = 0;
|
||||
|
@ -1578,12 +1591,13 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
|||
|
||||
// SPgno origPgno = pgno;
|
||||
memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
|
||||
/*
|
||||
|
||||
ret = tdbPagerWrite(pBt->pPager, ofp);
|
||||
if (ret < 0) {
|
||||
tdbError("failed to write page since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
tdbPageDropCell(ofp, 0, pTxn, pBt);
|
||||
*/
|
||||
// SIntHdr *pIntHdr = (SIntHdr *)(ofp->pData);
|
||||
|
@ -1591,6 +1605,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
|||
// pIntHdr->pgno = 0;
|
||||
// ofp->pPager = NULL;
|
||||
|
||||
SArray *ofps = pPage->pPager->ofps;
|
||||
if (ofps) {
|
||||
taosArrayPush(ofps, &ofp);
|
||||
}
|
||||
|
||||
tdbPagerReturnPage(pPage->pPager, ofp, pTxn);
|
||||
|
||||
nLeft -= bytes;
|
||||
|
@ -2103,8 +2122,7 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// btc.coder.ofps = taosArrayInit(8, sizeof(SPgno));
|
||||
pBtc->coder.ofps = taosArrayInit(8, sizeof(SPage *));
|
||||
pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
|
||||
|
||||
tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
|
||||
|
||||
|
@ -2161,15 +2179,15 @@ int tdbBtcDelete(SBTC *pBtc) {
|
|||
}
|
||||
}
|
||||
|
||||
SArray *ofps = pBtc->coder.ofps;
|
||||
SArray *ofps = pBtc->pPage->pPager->ofps;
|
||||
if (ofps) {
|
||||
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
||||
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
||||
// tdbPagerInsertFreePage(pBtc->pBt->pPager, ofp, pBtc->pTxn);
|
||||
tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
|
||||
}
|
||||
|
||||
taosArrayDestroy(ofps);
|
||||
pBtc->coder.ofps = NULL;
|
||||
pBtc->pPage->pPager->ofps = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -722,6 +722,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPage *pPage, TXN *pTxn) {
|
|||
|
||||
// memset(pPage->pData, 0, pPage->pageSize);
|
||||
tdbTrace("tdb/insert-free-page: tbc recycle page: %d.", pgno);
|
||||
// printf("tdb/insert-free-page: tbc recycle page: %d.\n", pgno);
|
||||
code = tdbTbInsert(pPager->pEnv->pFreeDb, &pgno, sizeof(pgno), NULL, 0, pTxn);
|
||||
if (code < 0) {
|
||||
tdbError("tdb/insert-free-page: tb insert failed with ret: %d.", code);
|
||||
|
@ -765,6 +766,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) {
|
|||
|
||||
*pPgno = *(SPgno *)pKey;
|
||||
tdbTrace("tdb/remove-free-page: tbc get page: %d.", *pPgno);
|
||||
// printf("tdb/remove-free-page: tbc get page: %d.\n", *pPgno);
|
||||
|
||||
code = tdbTbcDelete(pCur);
|
||||
if (code < 0) {
|
||||
|
|
|
@ -407,6 +407,7 @@ struct SPager {
|
|||
SRBTree rbt;
|
||||
// u8 inTran;
|
||||
TXN *pActiveTxn;
|
||||
SArray *ofps;
|
||||
SPager *pNext; // used by TDB
|
||||
SPager *pHashNext; // used by TDB
|
||||
#ifdef USE_MAINDB
|
||||
|
|
|
@ -730,15 +730,7 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) {
|
|||
char key[64];
|
||||
char val[(4083 - 4 - 3 - 2) + 1]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
|
||||
int64_t poolLimit = 4096; // 1M pool limit
|
||||
/*
|
||||
SPoolMem *pPool;
|
||||
|
||||
// open the pool
|
||||
pPool = openPool();
|
||||
|
||||
// start a transaction
|
||||
tdbBegin(pEnv, &txn, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
*/
|
||||
for (int iData = 0; iData < nData; ++iData) {
|
||||
sprintf(key, "key%03d", iData);
|
||||
sprintf(val, "value%03d", iData);
|
||||
|
@ -759,19 +751,6 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// generate value payload
|
||||
// char val[((4083 - 4 - 3 - 2) + 1) * 100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
|
||||
char val[32605];
|
||||
int valLen = sizeof(val) / sizeof(val[0]);
|
||||
generateBigVal(val, valLen);
|
||||
|
||||
// insert the generated big data
|
||||
// char const *key = "key1";
|
||||
char const *key = "key123456789";
|
||||
ret = tdbTbInsert(pDb, key, strlen(key) + 1, val, valLen, txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
*/
|
||||
// commit current transaction
|
||||
tdbCommit(pEnv, txn);
|
||||
tdbPostCommit(pEnv, txn);
|
||||
|
|
Loading…
Reference in New Issue