tdb/ofp-recycle: new ofps list with pager

This commit is contained in:
Minglei Jin 2023-06-30 10:05:17 +08:00
parent 8e491c307f
commit f89b43b64c
4 changed files with 32 additions and 32 deletions

View File

@ -234,7 +234,9 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
tdbBtcOpen(&btc, pBt, 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); 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); tdbBtcClose(&btc);
return -1; 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); tdbBtcClose(&btc);
return 0; return 0;
} }
@ -1319,11 +1332,11 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
/*
if (pDecoder->ofps) { if (pDecoder->ofps) {
taosArrayPush(pDecoder->ofps, &ofp); taosArrayPush(pDecoder->ofps, &ofp);
} }
*/
ofpCell = tdbPageGetCell(ofp, 0); ofpCell = tdbPageGetCell(ofp, 0);
if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { if (nLeft <= ofp->maxLocal - sizeof(SPgno)) {
@ -1363,11 +1376,11 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
/*
if (pDecoder->ofps) { if (pDecoder->ofps) {
taosArrayPush(pDecoder->ofps, &ofp); taosArrayPush(pDecoder->ofps, &ofp);
} }
*/
ofpCell = tdbPageGetCell(ofp, 0); ofpCell = tdbPageGetCell(ofp, 0);
int lastKeyPage = 0; int lastKeyPage = 0;
@ -1578,12 +1591,13 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
// SPgno origPgno = pgno; // SPgno origPgno = pgno;
memcpy(&pgno, ofpCell + bytes, sizeof(pgno)); memcpy(&pgno, ofpCell + bytes, sizeof(pgno));
/*
ret = tdbPagerWrite(pBt->pPager, ofp); ret = tdbPagerWrite(pBt->pPager, ofp);
if (ret < 0) { if (ret < 0) {
tdbError("failed to write page since %s", terrstr()); tdbError("failed to write page since %s", terrstr());
return -1; return -1;
} }
/*
tdbPageDropCell(ofp, 0, pTxn, pBt); tdbPageDropCell(ofp, 0, pTxn, pBt);
*/ */
// SIntHdr *pIntHdr = (SIntHdr *)(ofp->pData); // SIntHdr *pIntHdr = (SIntHdr *)(ofp->pData);
@ -1591,6 +1605,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
// pIntHdr->pgno = 0; // pIntHdr->pgno = 0;
// ofp->pPager = NULL; // ofp->pPager = NULL;
SArray *ofps = pPage->pPager->ofps;
if (ofps) {
taosArrayPush(ofps, &ofp);
}
tdbPagerReturnPage(pPage->pPager, ofp, pTxn); tdbPagerReturnPage(pPage->pPager, ofp, pTxn);
nLeft -= bytes; nLeft -= bytes;
@ -2103,8 +2122,7 @@ int tdbBtcDelete(SBTC *pBtc) {
return -1; return -1;
} }
// btc.coder.ofps = taosArrayInit(8, sizeof(SPgno)); pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
pBtc->coder.ofps = taosArrayInit(8, sizeof(SPage *));
tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); 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) { if (ofps) {
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) { for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
SPage *ofp = *(SPage **)taosArrayGet(ofps, i); SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
// tdbPagerInsertFreePage(pBtc->pBt->pPager, ofp, pBtc->pTxn); tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
} }
taosArrayDestroy(ofps); taosArrayDestroy(ofps);
pBtc->coder.ofps = NULL; pBtc->pPage->pPager->ofps = NULL;
} }
return 0; return 0;

View File

@ -722,6 +722,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPage *pPage, TXN *pTxn) {
// memset(pPage->pData, 0, pPage->pageSize); // memset(pPage->pData, 0, pPage->pageSize);
tdbTrace("tdb/insert-free-page: tbc recycle page: %d.", pgno); 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); code = tdbTbInsert(pPager->pEnv->pFreeDb, &pgno, sizeof(pgno), NULL, 0, pTxn);
if (code < 0) { if (code < 0) {
tdbError("tdb/insert-free-page: tb insert failed with ret: %d.", code); 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; *pPgno = *(SPgno *)pKey;
tdbTrace("tdb/remove-free-page: tbc get page: %d.", *pPgno); tdbTrace("tdb/remove-free-page: tbc get page: %d.", *pPgno);
// printf("tdb/remove-free-page: tbc get page: %d.\n", *pPgno);
code = tdbTbcDelete(pCur); code = tdbTbcDelete(pCur);
if (code < 0) { if (code < 0) {

View File

@ -407,6 +407,7 @@ struct SPager {
SRBTree rbt; SRBTree rbt;
// u8 inTran; // u8 inTran;
TXN *pActiveTxn; TXN *pActiveTxn;
SArray *ofps;
SPager *pNext; // used by TDB SPager *pNext; // used by TDB
SPager *pHashNext; // used by TDB SPager *pHashNext; // used by TDB
#ifdef USE_MAINDB #ifdef USE_MAINDB

View File

@ -730,15 +730,7 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) {
char key[64]; char key[64];
char val[(4083 - 4 - 3 - 2) + 1]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) char val[(4083 - 4 - 3 - 2) + 1]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4)
int64_t poolLimit = 4096; // 1M pool limit 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) { for (int iData = 0; iData < nData; ++iData) {
sprintf(key, "key%03d", iData); sprintf(key, "key%03d", iData);
sprintf(val, "value%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 // commit current transaction
tdbCommit(pEnv, txn); tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn); tdbPostCommit(pEnv, txn);