From c653daf5dc41a519de203f7aafc80d48dda2aaf8 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 6 Dec 2024 11:37:45 +0800 Subject: [PATCH] Fix unit test. --- include/common/tglobal.h | 1 - source/common/src/tglobal.c | 5 - source/dnode/mgmt/test/sut/src/server.cpp | 5 +- source/dnode/mnode/impl/src/mndConfig.c | 73 ++++++++------- source/dnode/mnode/impl/src/mndDef.c | 2 +- tests/army/alter/test_alter_config.py | 106 +++++++++++++++++++++- tests/parallel_test/cases.task | 1 + 7 files changed, 145 insertions(+), 48 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 67bec995d2..7ae0f5caf1 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -54,7 +54,6 @@ extern uint16_t tsServerPort; extern int32_t tsVersion; extern int32_t tsForceReadConfig; extern int32_t tsdmConfigVersion; -extern int32_t tsmmConfigVersion; extern int32_t tsConfigInited; extern int32_t tsStatusInterval; extern int32_t tsNumOfSupportVnodes; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 9e35639ecf..a52edfa187 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -46,7 +46,6 @@ uint16_t tsServerPort = 6030; int32_t tsVersion = 30000000; int32_t tsForceReadConfig = 0; int32_t tsdmConfigVersion = -1; -int32_t tsmmConfigVersion = -1; int32_t tsConfigInited = 0; int32_t tsStatusInterval = 1; // second int32_t tsNumOfSupportVnodes = 256; @@ -2630,7 +2629,6 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { {"keepColumnName", &tsKeepColumnName}, {"logKeepDays", &tsLogKeepDays}, {"maxInsertBatchRows", &tsMaxInsertBatchRows}, - {"maxRetryWaitTime", &tsMaxRetryWaitTime}, {"minSlidingTime", &tsMinSlidingTime}, {"minIntervalTime", &tsMinIntervalTime}, {"numOfLogLines", &tsNumOfLogLines}, @@ -2641,13 +2639,10 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { {"queryNodeChunkSize", &tsQueryNodeChunkSize}, {"queryUseNodeAllocator", &tsQueryUseNodeAllocator}, {"smlDot2Underline", &tsSmlDot2Underline}, - {"shellActivityTimer", &tsShellActivityTimer}, {"useAdapter", &tsUseAdapter}, - {"experimental", &tsExperimental}, {"multiResultFunctionStarReturnTags", &tsMultiResultFunctionStarReturnTags}, {"maxTsmaCalcDelay", &tsMaxTsmaCalcDelay}, {"tsmaDataDeleteMark", &tsmaDataDeleteMark}, - {"safetyCheckLevel", &tsSafetyCheckLevel}, {"bypassFlag", &tsBypassFlag}}; if ((code = taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true)) != TSDB_CODE_SUCCESS) { diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index 52d697cb5d..e7dc45a0f8 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -17,10 +17,7 @@ void* serverLoop(void* param) { TestServer* server = (TestServer*)param; - - if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0){ - return NULL; - } + cfgInit(&tsCfg); if (dmInit() != 0) { return NULL; diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index d400f32d25..5f4dcd8278 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -32,7 +32,8 @@ enum CfgAlterType { static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pInMCfgReq, int32_t optLen, int32_t *pOutValue); static int32_t cfgUpdateItem(SConfigItem *pItem, SConfigObj *obj); -static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype); +static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype, + int32_t tsmmConfigVersion); static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq); static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp); static int32_t mndProcessConfigReq(SRpcMsg *pReq); @@ -229,10 +230,18 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) { mError("failed to deserialize config req, since %s", terrstr()); goto _OVER; } + + SConfigObj *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); + if (vObj == NULL) { + mInfo("failed to acquire mnd config version, since %s", terrstr()); + goto _OVER; + } + SArray *diffArray = taosArrayInit(16, sizeof(SConfigItem)); SConfigRsp configRsp = {0}; configRsp.forceReadConfig = configReq.forceReadConfig; - configRsp.cver = tsmmConfigVersion; + + configRsp.cver = vObj->i32; if (configRsp.forceReadConfig) { // compare config array from configReq with current config array if (compareSConfigItemArrays(taosGetGlobalCfg(tsCfg), configReq.array, diffArray)) { @@ -242,7 +251,7 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) { } } else { configRsp.array = taosGetGlobalCfg(tsCfg); - if (configReq.cver == tsmmConfigVersion) { + if (configReq.cver == vObj->i32) { configRsp.isVersionVerified = 1; } else { configRsp.array = taosGetGlobalCfg(tsCfg); @@ -316,11 +325,12 @@ int32_t mndInitReadCfg(SMnode *pMnode) { } SConfigObj *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); if (obj == NULL) { - mInfo("failed to acquire mnd config version, since %s", terrstr()); + code = mndInitWriteCfg(pMnode); + if (code != 0) { + mError("failed to init write cfg, since %s", terrstr()); + } + mInfo("failed to acquire mnd config version, try to rebuild it , since %s", terrstr()); goto _OVER; - } else { - tsmmConfigVersion = obj->i32; - sdbRelease(pMnode->pSdb, obj); } sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); @@ -469,6 +479,11 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { int32_t lino = -1; SMnode *pMnode = pReq->info.node; SMCfgDnodeReq cfgReq = {0}; + SConfigObj *vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); + if (vObj == NULL) { + mInfo("failed to acquire mnd config version, since %s", terrstr()); + TAOS_RETURN(terrno); + } TAOS_CHECK_RETURN(tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq)); int8_t updateIpWhiteList = 0; mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); @@ -521,21 +536,22 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { code = TSDB_CODE_CFG_NOT_FOUND; goto _err_out; } + +_send_req: if (pItem->category == CFG_CATEGORY_GLOBAL) { - TAOS_CHECK_GOTO(mndConfigUpdateTrans(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype), &lino, _err_out); + TAOS_CHECK_GOTO(mndConfigUpdateTrans(pMnode, dcfgReq.config, dcfgReq.value, pItem->dtype, ++vObj->i32), &lino, + _err_out); } -_send_req : + { // audit + char obj[50] = {0}; + (void)sprintf(obj, "%d", cfgReq.dnodeId); -{ // audit - char obj[50] = {0}; - (void)sprintf(obj, "%d", cfgReq.dnodeId); - - auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen); -} + auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", cfgReq.sql, cfgReq.sqlLen); + } tFreeSMCfgDnodeReq(&cfgReq); - dcfgReq.version = tsmmConfigVersion; + dcfgReq.version = vObj->i32; code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq); // dont care suss or succ; @@ -577,25 +593,15 @@ _err: TAOS_RETURN(code); } -static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype) { - int32_t code = -1; - int32_t lino = -1; - // SConfigObj *pVersion = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); - // if (pVersion == NULL) { - // mError("failed to acquire tsmmConfigVersion while update config, since %s", terrstr()); - // code = terrno; - // goto _OVER; - // } - // pVersion->i32 = ++tsmmConfigVersion; - // SConfigObj *pObj = sdbAcquire(pMnode->pSdb, SDB_CFG, name); - // if (pObj == NULL) { - // mError("failed to acquire mnd config:%s while update config, since %s", name, terrstr()); - // code = terrno; - // goto _OVER; - // } +static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue, ECfgDataType dtype, + int32_t tsmmConfigVersion) { + int32_t code = -1; + int32_t lino = -1; SConfigObj pVersion = {0}, pObj = {0}; - pVersion.i32 = ++tsmmConfigVersion; + strncpy(pVersion.name, "tsmmConfigVersion", CFG_NAME_MAX_LEN); + pVersion.i32 = tsmmConfigVersion; + pVersion.dtype = CFG_DTYPE_INT32; pObj.dtype = dtype; strncpy(pObj.name, name, CFG_NAME_MAX_LEN); @@ -613,7 +619,6 @@ static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pVal code = 0; _OVER: if (code != 0) { - --tsmmConfigVersion; mError("failed to update config:%s to value:%s, since %s", name, pValue, tstrerror(code)); } mndTransDrop(pTrans); diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index f257991381..6d66addd6e 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -822,7 +822,7 @@ SConfigObj *mndInitConfigVersion() { } strncpy(pObj->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN); pObj->dtype = CFG_DTYPE_INT32; - pObj->i32 = ++tsmmConfigVersion; + pObj->i32 = 0; return pObj; } diff --git a/tests/army/alter/test_alter_config.py b/tests/army/alter/test_alter_config.py index 7395268549..3f07ca4e06 100644 --- a/tests/army/alter/test_alter_config.py +++ b/tests/army/alter/test_alter_config.py @@ -37,6 +37,107 @@ class TDTestCase: self.configration_dic = { "cli": [ + { + "name": "asyncLog", + "value": 0, + "category": "local", + }, + { + "name": "enableQueryHb", + "value": 0, + "category": "local", + }, + { + "name": "keepColumnName", + "value": 1, + "category": "local", + }, + { + "name": "logKeepDays", + "value": 30, + "category": "local", + }, + { + "name": "maxInsertBatchRows", + "value": 2000000, + "category": "local", + }, + { + "name": "minSlidingTime", + "value": 10000, + "category": "local", + }, + { + "name": "minIntervalTime", + "value": 2, + "category": "local", + }, + { + "name": "numOfLogLines", + "value": 20000000, + "category": "local", + + }, + { + "name": "querySmaOptimize", + "value": 1, + "category": "local", + }, + { + "name": "queryPolicy", + "value": 3, + "category": "local", + }, + { + "name": "queryTableNotExistAsEmpty", + "value": 1, + "category": "local", + }, + { + "name": "queryPlannerTrace", + "value": 1, + "category": "local", + }, + { + "name": "queryNodeChunkSize", + "value": 16 * 1024, + "category": "local", + }, + { + "name": "queryUseNodeAllocator", + "value": 0, + "category": "local", + }, + { + "name": "smlDot2Underline", + "value": 0, + "category": "local", + }, + { + "name": "useAdapter", + "value": 1, + "category": "local", + }, + # { + # "name": "multiResultFunctionStarReturnTags", + # "value": 1, + # "category": "local", + # }, + { + "name": "maxTsmaCalcDelay", + "value": 1200, + "category": "local", + }, + { + "name": "tsmaDataDeleteMark", + "value": 1000 * 60 * 60 * 12, + "category": "local", + }, + { + "name": "bypassFlag", + "value": 4, + "category": "local", + } ], "svr": [ { @@ -528,18 +629,17 @@ class TDTestCase: tdLog.info("success to alter all configurations") tdLog.info("stop and restart taosd") - time.sleep(3) + sc.dnodeStopAll() sc.dnodeStart(1) sc.dnodeStart(2) sc.dnodeStart(3) - time.sleep(10) for key in self.configration_dic: if "cli" == key: for item in self.configration_dic[key]: actVal = self.cli_get_param_value(item["name"]) - assert str(actVal) == str(item["oldVal"]), f"item name: {item['name']}, Expected value: {item['value']}, actual value: {actVal}" + assert str(actVal) == str(item["value"]), f"item name: {item['name']}, Expected value: {item['value']}, actual value: {actVal}" elif "svr" == key: for item in self.configration_dic[key]: actVal = self.svr_get_param_value(item["name"]) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index b9dc38d41f..4b189573c1 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -41,6 +41,7 @@ ,,n,army,python3 ./test.py -f cmdline/fullopt.py ,,y,army,./pytest.sh python3 ./test.py -f query/show.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f alter/alterConfig.py -N 3 +,,y,army,./pytest.sh python3 ./test.py -f alter/test_alter_config.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/subquery/subqueryBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f storage/oneStageComp.py -N 3 -L 3 -D 1 ,,y,army,./pytest.sh python3 ./test.py -f storage/compressBasic.py -N 3