From 04f941982995eac77060502dc0382d89a303b3fa Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 25 Aug 2022 21:57:45 +0800 Subject: [PATCH 1/6] 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"); From b39c80940fbfd9c3bac0a86cbf6a726c1d6f6883 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 26 Aug 2022 10:38:14 +0800 Subject: [PATCH 2/6] fix: release SStreamObj when dropping --- include/common/tmsg.h | 9 --------- source/dnode/mnode/impl/src/mndSma.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 7 ------- source/dnode/mnode/sdb/inc/sdb.h | 1 - source/dnode/mnode/sdb/src/sdb.c | 19 ------------------- 5 files changed, 1 insertion(+), 37 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 47bd0d0b02..c0ea5e79c7 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2677,15 +2677,6 @@ typedef struct { int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq); int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq); -typedef struct { - int32_t vgId; - SEpSet epSet; -} SVgEpSet; - -typedef struct { - int32_t padding; -} SRSmaExecMsg; - typedef struct { int8_t version; // for compatibility(default 0) int8_t intervalUnit; // MACRO: TIME_UNIT_XXX diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 2fb934aaad..7a3b06f83a 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -38,7 +38,6 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw); static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma); static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSpSmatb); static int32_t mndSmaActionUpdate(SSdb *pSdb, SSmaObj *pOld, SSmaObj *pNew); -static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpSet, int32_t *numOfVgroups); static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq); static int32_t mndProcessDropSmaReq(SRpcMsg *pReq); static int32_t mndProcessGetSmaReq(SRpcMsg *pReq); @@ -840,6 +839,7 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p code = 0; _OVER: + mndReleaseStream(pMnode, pStream); mndTransDrop(pTrans); mndReleaseVgroup(pMnode, pVgroup); mndReleaseStb(pMnode, pStb); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index e2ed6342a7..b0cec23a3f 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -800,11 +800,6 @@ 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) { @@ -832,8 +827,6 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { 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 794011b3b2..f922baf329 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -367,7 +367,6 @@ 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 d0d79f9670..3db0087334 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -65,25 +65,6 @@ 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"); From f6c6e18554e8b35f05ff78c57de2781cf95f522d Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 26 Aug 2022 10:39:29 +0800 Subject: [PATCH 3/6] other: revert the code --- source/dnode/mnode/impl/src/mndTrans.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index b0cec23a3f..1d8d62e534 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -826,7 +826,6 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); return -1; } - mDebug("trans:%d, prepare finished", pTrans->id); STrans *pNew = mndAcquireTrans(pMnode, pTrans->id); From 0afb60dc181bfb96245f702f19428194737c80f9 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 26 Aug 2022 10:47:11 +0800 Subject: [PATCH 4/6] fix: release SSmaObj/SStreamObj when dropping sma --- source/dnode/mnode/impl/src/mndSma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 7a3b06f83a..f45e5c26b6 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -839,10 +839,11 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p code = 0; _OVER: - mndReleaseStream(pMnode, pStream); mndTransDrop(pTrans); mndReleaseVgroup(pMnode, pVgroup); mndReleaseStb(pMnode, pStb); + mndReleaseStream(pMnode, pStream); + mndReleaseSma(pMnode, pSma); return code; } From c2c41d89d5bbd5fadd5f4ea78e80ac6e3b031daf Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 26 Aug 2022 10:58:40 +0800 Subject: [PATCH 5/6] fix: release SSmaObj/SStreamObj when dropping sma --- source/dnode/mnode/impl/src/mndSma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index f45e5c26b6..59eb94a3c9 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -840,10 +840,9 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p _OVER: mndTransDrop(pTrans); + mndReleaseStream(pMnode, pStream); mndReleaseVgroup(pMnode, pVgroup); mndReleaseStb(pMnode, pStb); - mndReleaseStream(pMnode, pStream); - mndReleaseSma(pMnode, pSma); return code; } @@ -963,6 +962,7 @@ _OVER: } mndReleaseDb(pMnode, pDb); + mndReleaseSma(pMnode, pSma); return code; } From 4c6a511ccf63548acb0a128c9f8353b98429aa25 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 26 Aug 2022 11:02:20 +0800 Subject: [PATCH 6/6] fix: release SSmaObj/SStreamObj when dropping sma --- source/dnode/mnode/impl/src/mndSma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 59eb94a3c9..8638cc5118 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -961,8 +961,8 @@ _OVER: mError("sma:%s, failed to drop since %s", dropReq.name, terrstr()); } - mndReleaseDb(pMnode, pDb); mndReleaseSma(pMnode, pSma); + mndReleaseDb(pMnode, pDb); return code; }