tdb/ofp: recycle ofp cell on parent page
This commit is contained in:
parent
f89b43b64c
commit
c66524d87b
|
@ -608,7 +608,30 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
for (int i = 0; i < nOlds; i++) {
|
for (int i = 0; i < nOlds; i++) {
|
||||||
nCells = TDB_PAGE_TOTAL_CELLS(pParent);
|
nCells = TDB_PAGE_TOTAL_CELLS(pParent);
|
||||||
if (sIdx < nCells) {
|
if (sIdx < nCells) {
|
||||||
|
bool destroyOfps = false;
|
||||||
|
if (!childNotLeaf) {
|
||||||
|
if (!pParent->pPager->ofps) {
|
||||||
|
pParent->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
|
||||||
|
destroyOfps = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tdbPageDropCell(pParent, sIdx, pTxn, pBt);
|
tdbPageDropCell(pParent, sIdx, pTxn, pBt);
|
||||||
|
|
||||||
|
if (!childNotLeaf) {
|
||||||
|
SArray *ofps = pParent->pPager->ofps;
|
||||||
|
if (ofps) {
|
||||||
|
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
||||||
|
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
||||||
|
tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroyOfps) {
|
||||||
|
taosArrayDestroy(ofps);
|
||||||
|
pParent->pPager->ofps = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
((SIntHdr *)pParent->pData)->pgno = 0;
|
((SIntHdr *)pParent->pData)->pgno = 0;
|
||||||
}
|
}
|
||||||
|
@ -1372,6 +1395,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
||||||
// load left key & val to ovpages
|
// load left key & val to ovpages
|
||||||
while (pgno != 0) {
|
while (pgno != 0) {
|
||||||
tdbTrace("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p", pTxn, pgno, pCell);
|
tdbTrace("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p", pTxn, pgno, pCell);
|
||||||
|
// printf("tdb decode-ofp, pTxn: %p, pgno:%u by cell:%p\n", pTxn, pgno, pCell);
|
||||||
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2122,10 +2146,27 @@ int tdbBtcDelete(SBTC *pBtc) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
|
bool destroyOfps = false;
|
||||||
|
if (!pBtc->pPage->pPager->ofps) {
|
||||||
|
pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
|
||||||
|
destroyOfps = true;
|
||||||
|
}
|
||||||
|
|
||||||
tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
|
tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
|
||||||
|
|
||||||
|
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->pPage->pPager, ofp, pBtc->pTxn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroyOfps) {
|
||||||
|
taosArrayDestroy(ofps);
|
||||||
|
pBtc->pPage->pPager->ofps = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update interior page or do balance
|
// update interior page or do balance
|
||||||
if (idx == nCells - 1) {
|
if (idx == nCells - 1) {
|
||||||
if (idx) {
|
if (idx) {
|
||||||
|
@ -2179,17 +2220,6 @@ int tdbBtcDelete(SBTC *pBtc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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->pPage->pPager, ofp, pBtc->pTxn);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosArrayDestroy(ofps);
|
|
||||||
pBtc->pPage->pPager->ofps = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2250,7 +2280,13 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
tdbError("tdb/btc-upsert: page insert/update cell failed with ret: %d.", ret);
|
tdbError("tdb/btc-upsert: page insert/update cell failed with ret: %d.", ret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
bool destroyOfps = false;
|
||||||
|
if (!pBtc->pPage->pPager->ofps) {
|
||||||
|
pBtc->pPage->pPager->ofps = taosArrayInit(8, sizeof(SPage *));
|
||||||
|
destroyOfps = true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
// check balance
|
// check balance
|
||||||
if (pBtc->pPage->nOverflow > 0) {
|
if (pBtc->pPage->nOverflow > 0) {
|
||||||
ret = tdbBtreeBalance(pBtc);
|
ret = tdbBtreeBalance(pBtc);
|
||||||
|
@ -2259,7 +2295,20 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
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->pPage->pPager, ofp, pBtc->pTxn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroyOfps) {
|
||||||
|
taosArrayDestroy(ofps);
|
||||||
|
pBtc->pPage->pPager->ofps = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -766,3 +766,70 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) {
|
||||||
|
|
||||||
system("ls -l ./tdb");
|
system("ls -l ./tdb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEST(TdbPageRecycleTest, DISABLED_recycly_delete_interior_ofp_nocommit) {
|
||||||
|
TEST(TdbPageRecycleTest, recycly_delete_interior_ofp_nocommit) {
|
||||||
|
clearDb("tdb");
|
||||||
|
|
||||||
|
// open Env
|
||||||
|
int ret = 0;
|
||||||
|
int const pageSize = 4096;
|
||||||
|
int const pageNum = 64;
|
||||||
|
TDB *pEnv = openEnv("tdb", pageSize, pageNum);
|
||||||
|
GTEST_ASSERT_NE(pEnv, nullptr);
|
||||||
|
|
||||||
|
// open db
|
||||||
|
TTB *pDb = NULL;
|
||||||
|
tdb_cmpr_fn_t compFunc = NULL; // tKeyCmpr;
|
||||||
|
ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
|
||||||
|
GTEST_ASSERT_EQ(ret, 0);
|
||||||
|
|
||||||
|
// open the pool
|
||||||
|
SPoolMem *pPool = openPool();
|
||||||
|
|
||||||
|
// start a transaction
|
||||||
|
TXN *txn;
|
||||||
|
|
||||||
|
tdbBegin(pEnv, &txn, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||||
|
|
||||||
|
char key[1024] = {0};
|
||||||
|
int count = sizeof(key) / sizeof(key[0]);
|
||||||
|
for (int i = 0; i < count - 1; ++i) {
|
||||||
|
key[i] = 'a';
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert n ofp keys to form 2-layer btree
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 7; ++i) {
|
||||||
|
// sprintf(&key[count - 2], "%c", i);
|
||||||
|
key[count - 2] = '0' + i;
|
||||||
|
|
||||||
|
ret = tdbTbInsert(pDb, key, count, NULL, NULL, txn);
|
||||||
|
GTEST_ASSERT_EQ(ret, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// delete one interior key
|
||||||
|
{
|
||||||
|
sprintf(&key[count - 2], "%c", 2);
|
||||||
|
key[count - 2] = '0' + 2;
|
||||||
|
|
||||||
|
ret = tdbTbDelete(pDb, key, strlen(key) + 1, txn);
|
||||||
|
GTEST_ASSERT_EQ(ret, 0);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// commit current transaction
|
||||||
|
tdbCommit(pEnv, txn);
|
||||||
|
tdbPostCommit(pEnv, txn);
|
||||||
|
|
||||||
|
closePool(pPool);
|
||||||
|
|
||||||
|
// Close a database
|
||||||
|
tdbTbClose(pDb);
|
||||||
|
|
||||||
|
// Close Env
|
||||||
|
ret = tdbClose(pEnv);
|
||||||
|
GTEST_ASSERT_EQ(ret, 0);
|
||||||
|
|
||||||
|
system("ls -l ./tdb");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue