From ff1ecebdf2106b187fd4607c2a0ced921d6a06bc Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Wed, 8 Jan 2025 18:05:11 +0800 Subject: [PATCH 1/5] Test(cfg): add alter config to compatibility.py. --- tests/system-test/0-others/compatibility.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/system-test/0-others/compatibility.py b/tests/system-test/0-others/compatibility.py index 6a78a051ab..d10e8e8ced 100644 --- a/tests/system-test/0-others/compatibility.py +++ b/tests/system-test/0-others/compatibility.py @@ -450,6 +450,11 @@ class TDTestCase: tdsql.checkData(0,2,180) tdsql.checkData(0,3,0.53) + # check alter config + tdsql.execute('alter all dnodes "debugFlag 131"') + tdsql.execute('alter dnode 1 "debugFlag 143"') + tdsql.execute('alter local "debugFlag 131"') + # check tmq conn = taos.connect() From 9eb12397836da4153d32ead7436d1b984730fbd8 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 9 Jan 2025 10:50:23 +0800 Subject: [PATCH 2/5] Fix mem leak. --- source/dnode/mnode/impl/src/mndConfig.c | 28 +++++++++++-------------- source/dnode/mnode/impl/src/mndDef.c | 14 ++++++------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 0729b2a26e..2c59840c86 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -312,28 +312,24 @@ int32_t mndInitWriteCfg(SMnode *pMnode) { if ((code = mndSetCreateConfigCommitLogs(pTrans, versionObj)) != 0) { mError("failed to init mnd config version, since %s", tstrerror(code)); tFreeSConfigObj(versionObj); - taosMemoryFree(versionObj); goto _OVER; } tFreeSConfigObj(versionObj); - taosMemoryFree(versionObj); sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); for (int i = 0; i < sz; ++i) { SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); - SConfigObj *obj = mndInitConfigObj(item); - if (obj == NULL) { + SConfigObj *pObj = mndInitConfigObj(item); + if (pObj == NULL) { code = terrno; goto _OVER; } - if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) { + if ((code = mndSetCreateConfigCommitLogs(pTrans, pObj)) != 0) { mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code)); - tFreeSConfigObj(obj); - taosMemoryFree(obj); + tFreeSConfigObj(pObj); goto _OVER; } - tFreeSConfigObj(obj); - taosMemoryFree(obj); + tFreeSConfigObj(pObj); } if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER; @@ -372,11 +368,11 @@ static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) { if (!mndIsLeader(pMnode)) { return TSDB_CODE_SUCCESS; } - int32_t code = 0; - int32_t sz = -1; - STrans *pTrans = NULL; - SAcctObj *vObj = NULL, *obj = NULL; - SArray *addArray = NULL; + int32_t code = 0; + int32_t sz = -1; + STrans *pTrans = NULL; + SConfigObj *vObj = NULL; + SArray *addArray = NULL; vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); if (vObj == NULL) { @@ -387,8 +383,9 @@ static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) { addArray = taosArrayInit(4, sizeof(SConfigObj)); for (int i = 0; i < sz; ++i) { SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); - obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name); + SConfigObj *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name); if (obj == NULL) { + mInfo("config:%s, not exist in sdb, try to add it", item->name); SConfigObj *newObj = mndInitConfigObj(item); if (newObj == NULL) { code = terrno; @@ -422,7 +419,6 @@ _exit: mError("failed to try rebuild config in sdb, since %s", tstrerror(code)); } sdbRelease(pMnode->pSdb, vObj); - sdbRelease(pMnode->pSdb, obj); cfgObjArrayCleanUp(addArray); mndTransDrop(pTrans); TAOS_RETURN(code); diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 92ad4eb5b8..f58c377d3b 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -731,10 +731,9 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) { } SConfigObj *mndInitConfigObj(SConfigItem *pItem) { - SConfigObj *pObj = taosMemoryCalloc(1, sizeof(SConfigObj)); - if (pObj == NULL) { - return NULL; - } + SConfigObj *pObj; + memset(pObj, 0, sizeof(SConfigObj)); + tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN); pObj->dtype = pItem->dtype; switch (pItem->dtype) { @@ -823,10 +822,9 @@ int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) { } SConfigObj *mndInitConfigVersion() { - SConfigObj *pObj = taosMemoryCalloc(1, sizeof(SConfigObj)); - if (pObj == NULL) { - return NULL; - } + SConfigObj *pObj; + memset(pObj, 0, sizeof(SConfigObj)); + tstrncpy(pObj->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN); pObj->dtype = CFG_DTYPE_INT32; pObj->i32 = 0; From c1732ba41d11e6823cee588d57aa730e07814b1c Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 9 Jan 2025 13:36:23 +0800 Subject: [PATCH 3/5] Fix asan problems at ci test. --- source/dnode/mnode/impl/inc/mndDef.h | 12 +++++------ source/dnode/mnode/impl/src/mndConfig.c | 28 +++++++++++-------------- source/dnode/mnode/impl/src/mndDef.c | 23 +++++++++----------- tests/parallel_test/cases.task | 2 +- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index e3d2ad6d34..90f1bd9b8e 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -328,12 +328,12 @@ typedef struct { }; } SConfigObj; -int32_t tEncodeSConfigObj(SEncoder* pEncoder, const SConfigObj* pObj); -int32_t tDecodeSConfigObj(SDecoder* pDecoder, SConfigObj* pObj); -SConfigObj* mndInitConfigObj(SConfigItem* pItem); -SConfigObj* mndInitConfigVersion(); -int32_t mndUpdateObj(SConfigObj* pObj, const char* name, char* value); -void tFreeSConfigObj(SConfigObj* obj); +int32_t tEncodeSConfigObj(SEncoder* pEncoder, const SConfigObj* pObj); +int32_t tDecodeSConfigObj(SDecoder* pDecoder, SConfigObj* pObj); +int32_t mndInitConfigObj(SConfigItem* pItem, SConfigObj* pObj); +SConfigObj mndInitConfigVersion(); +int32_t mndUpdateObj(SConfigObj* pObj, const char* name, char* value); +void tFreeSConfigObj(SConfigObj* obj); typedef struct { int32_t maxUsers; diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 2c59840c86..e388d7ca75 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -308,28 +308,27 @@ int32_t mndInitWriteCfg(SMnode *pMnode) { } // encode mnd config version - SConfigObj *versionObj = mndInitConfigVersion(); - if ((code = mndSetCreateConfigCommitLogs(pTrans, versionObj)) != 0) { + SConfigObj versionObj = mndInitConfigVersion(); + if ((code = mndSetCreateConfigCommitLogs(pTrans, &versionObj)) != 0) { mError("failed to init mnd config version, since %s", tstrerror(code)); - tFreeSConfigObj(versionObj); + tFreeSConfigObj(&versionObj); goto _OVER; } - tFreeSConfigObj(versionObj); + tFreeSConfigObj(&versionObj); sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); for (int i = 0; i < sz; ++i) { SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); - SConfigObj *pObj = mndInitConfigObj(item); - if (pObj == NULL) { - code = terrno; + SConfigObj pObj; + if ((code = mndInitConfigObj(item, &pObj)) != 0) { goto _OVER; } - if ((code = mndSetCreateConfigCommitLogs(pTrans, pObj)) != 0) { + if ((code = mndSetCreateConfigCommitLogs(pTrans, &pObj)) != 0) { mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code)); - tFreeSConfigObj(pObj); + tFreeSConfigObj(&pObj); goto _OVER; } - tFreeSConfigObj(pObj); + tFreeSConfigObj(&pObj); } if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER; @@ -386,12 +385,9 @@ static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) { SConfigObj *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name); if (obj == NULL) { mInfo("config:%s, not exist in sdb, try to add it", item->name); - SConfigObj *newObj = mndInitConfigObj(item); - if (newObj == NULL) { - code = terrno; - goto _exit; - } - if (NULL == taosArrayPush(addArray, newObj)) { + SConfigObj newObj; + if ((code = mndInitConfigObj(item, &newObj)) != 0) goto _exit; + if (NULL == taosArrayPush(addArray, &newObj)) { code = terrno; goto _exit; } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index f58c377d3b..a6602b392b 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -730,10 +730,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) { return (void *)buf; } -SConfigObj *mndInitConfigObj(SConfigItem *pItem) { - SConfigObj *pObj; - memset(pObj, 0, sizeof(SConfigObj)); - +int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) { tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN); pObj->dtype = pItem->dtype; switch (pItem->dtype) { @@ -760,11 +757,11 @@ SConfigObj *mndInitConfigObj(SConfigItem *pItem) { pObj->str = taosStrdup(pItem->str); if (pObj->str == NULL) { taosMemoryFree(pObj); - return NULL; + return TSDB_CODE_OUT_OF_MEMORY; } break; } - return pObj; + return TSDB_CODE_SUCCESS; } int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) { @@ -821,14 +818,14 @@ int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) { return code; } -SConfigObj *mndInitConfigVersion() { - SConfigObj *pObj; - memset(pObj, 0, sizeof(SConfigObj)); +SConfigObj mndInitConfigVersion() { + SConfigObj obj; + memset(&obj, 0, sizeof(SConfigObj)); - tstrncpy(pObj->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN); - pObj->dtype = CFG_DTYPE_INT32; - pObj->i32 = 0; - return pObj; + tstrncpy(obj.name, "tsmmConfigVersion", CFG_NAME_MAX_LEN); + obj.dtype = CFG_DTYPE_INT32; + obj.i32 = 0; + return obj; } int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) { diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 5fce3821da..ec97336f21 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -404,7 +404,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/view/non_marterial_view/test_view.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_show_table_distributed.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_show_disk_usage.py -,,n,system-test,python3 ./test.py -f 0-others/compatibility.py +,,n,system-test,python3 ./test.py -f 0-others/compatibility.py -N 3 -M 3 ,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py ,,n,system-test,python3 ./test.py -f 0-others/udfpy_main.py ,,n,system-test,python3 ./test.py -N 3 -f 0-others/walRetention.py From c3e025713b3e88bca6d95f0f28b83574bf5c4ddc Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 9 Jan 2025 13:38:20 +0800 Subject: [PATCH 4/5] Rename some vars. --- source/dnode/mnode/impl/src/mndConfig.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index e388d7ca75..0d4265f8e7 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -319,16 +319,16 @@ int32_t mndInitWriteCfg(SMnode *pMnode) { for (int i = 0; i < sz; ++i) { SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); - SConfigObj pObj; - if ((code = mndInitConfigObj(item, &pObj)) != 0) { + SConfigObj obj; + if ((code = mndInitConfigObj(item, &obj)) != 0) { goto _OVER; } - if ((code = mndSetCreateConfigCommitLogs(pTrans, &pObj)) != 0) { + if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) { mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code)); - tFreeSConfigObj(&pObj); + tFreeSConfigObj(&obj); goto _OVER; } - tFreeSConfigObj(&pObj); + tFreeSConfigObj(&obj); } if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER; From a3849bba47b17d20bddd06f5402606691fadc165 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 9 Jan 2025 15:08:13 +0800 Subject: [PATCH 5/5] Fix ci problems. --- tests/parallel_test/cases.task | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index ec97336f21..5fce3821da 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -404,7 +404,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/view/non_marterial_view/test_view.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_show_table_distributed.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_show_disk_usage.py -,,n,system-test,python3 ./test.py -f 0-others/compatibility.py -N 3 -M 3 +,,n,system-test,python3 ./test.py -f 0-others/compatibility.py ,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py ,,n,system-test,python3 ./test.py -f 0-others/udfpy_main.py ,,n,system-test,python3 ./test.py -N 3 -f 0-others/walRetention.py