Merge pull request #25570 from taosdata/fix/TS-4728-3.0

fix: TDB upsert no page recycled
This commit is contained in:
Hongze Cheng 2024-04-29 16:58:56 +08:00 committed by GitHub
commit 052c79125a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 2 deletions

View File

@ -274,6 +274,7 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
return 0; return 0;
} }
#if 0
int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn) { int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn) {
SBTC btc = {0}; SBTC btc = {0};
int c; int c;
@ -317,6 +318,7 @@ int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, i
tdbBtcClose(&btc); tdbBtcClose(&btc);
return 0; return 0;
} }
#endif
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) { int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) {
return tdbBtreePGet(pBt, pKey, kLen, NULL, NULL, ppVal, vLen); return tdbBtreePGet(pBt, pKey, kLen, NULL, NULL, ppVal, vLen);
@ -2490,6 +2492,10 @@ int tdbBtcClose(SBTC *pBtc) {
pBtc->idx = pBtc->idxStack[pBtc->iPage]; pBtc->idx = pBtc->idxStack[pBtc->iPage];
} }
if (TDB_CELLDECODER_FREE_KEY(&pBtc->coder)) {
tdbFree(pBtc->coder.pKey);
}
if (TDB_CELLDECODER_FREE_VAL(&pBtc->coder)) { if (TDB_CELLDECODER_FREE_VAL(&pBtc->coder)) {
tdbDebug("tdb btc/close decoder: %p pVal free: %p", &pBtc->coder, pBtc->coder.pVal); tdbDebug("tdb btc/close decoder: %p pVal free: %p", &pBtc->coder, pBtc->coder.pVal);

View File

@ -202,7 +202,8 @@ int tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int va
int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); } int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); }
int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) { int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) {
return tdbBtreeUpsert(pTb->pBt, pKey, kLen, pVal, vLen, pTxn); tdbTbDelete(pTb, pKey, kLen, pTxn);
return tdbTbInsert(pTb, pKey, kLen, pVal, vLen, pTxn);
} }
int tdbTbGet(TTB *pTb, const void *pKey, int kLen, void **ppVal, int *vLen) { int tdbTbGet(TTB *pTb, const void *pKey, int kLen, void **ppVal, int *vLen) {

View File

@ -160,7 +160,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, char const *tbname, SPgn
int tdbBtreeClose(SBTree *pBt); int tdbBtreeClose(SBTree *pBt);
int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn); int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn); int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn);
int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn); // int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn);
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);

View File

@ -479,6 +479,45 @@ TEST(tdb_test, DISABLED_simple_upsert1) {
tdbClose(pEnv); tdbClose(pEnv);
} }
TEST(tdb_test, simple_upsert2) {
int ret;
TDB *pEnv;
TTB *pDb;
int nData = 10000;
const char *key = "key";
int32_t dataSize = 256 * 1024;
void *data = taosMemoryMalloc(dataSize);
void *pData = NULL;
SPoolMem *pPool;
TXN *txn;
taosRemoveDir("tdb");
memset(data, 'a', dataSize);
// open env
ret = tdbOpen("tdb", 4096, 64, &pEnv, 0, 0, 0);
GTEST_ASSERT_EQ(ret, 0);
// open database
ret = tdbTbOpen("db.db", -1, -1, NULL, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
pPool = openPool();
for (int iData = 0; iData < nData; iData++) {
tdbBegin(pEnv, &txn, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
ret = tdbTbUpsert(pDb, key, strlen(key), data, dataSize, txn);
GTEST_ASSERT_EQ(ret, 0);
tdbCommit(pEnv, txn);
tdbPostCommit(pEnv, txn);
}
tdbTbClose(pDb);
tdbClose(pEnv);
}
TEST(tdb_test, multi_thread_query) { TEST(tdb_test, multi_thread_query) {
int ret; int ret;
TDB *pEnv; TDB *pEnv;