From 04f941982995eac77060502dc0382d89a303b3fa Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 25 Aug 2022 21:57:45 +0800 Subject: [PATCH] fix: free stream/sma obj in trans --- source/dnode/mnode/impl/src/mndTrans.c | 8 ++++++++ source/dnode/mnode/sdb/inc/sdb.h | 1 + source/dnode/mnode/sdb/src/sdb.c | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 1d8d62e534..e2ed6342a7 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -800,6 +800,11 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) { return conflict; } + static void mndTransFreeObj(SSdb *pSdb) { + sdbFreeRowsByType(pSdb, SDB_STREAM); + sdbFreeRowsByType(pSdb, SDB_SMA); +} + int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) { if (strlen(pTrans->dbname1) == 0 && strlen(pTrans->dbname2) == 0) { @@ -826,6 +831,9 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); return -1; } + + mndTransFreeObj(pMnode->pSdb); + mDebug("trans:%d, prepare finished", pTrans->id); STrans *pNew = mndAcquireTrans(pMnode, pTrans->id); diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index f922baf329..794011b3b2 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -367,6 +367,7 @@ int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type); */ void sdbSetApplyInfo(SSdb *pSdb, int64_t index, int64_t term, int64_t config); void sdbGetCommitInfo(SSdb *pSdb, int64_t *index, int64_t *term, int64_t *config); +void sdbFreeRowsByType(SSdb *pSdb, ESdbType type); SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); void sdbFreeRaw(SSdbRaw *pRaw); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 3db0087334..d0d79f9670 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -65,6 +65,25 @@ SSdb *sdbInit(SSdbOpt *pOption) { return pSdb; } +void sdbFreeRowsByType(SSdb *pSdb, ESdbType type) { + SHashObj *hash = pSdb->hashObjs[type]; + if (hash == NULL || !taosHashGetSize(hash)) { + return; + } + + SSdbRow **ppRow = taosHashIterate(hash, NULL); + while (ppRow != NULL) { + SSdbRow *pRow = *ppRow; + if (pRow == NULL) { + ppRow = taosHashIterate(hash, ppRow); + continue; + } + sdbFreeRow(pSdb, pRow, false); + ppRow = taosHashIterate(hash, ppRow); + } + taosHashClear(hash); +} + void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); -- GitLab