From 748bb000b0cf60cbb2966a17fd83bf572b0d1f3d Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Wed, 13 Nov 2024 16:51:26 +0800 Subject: [PATCH] fix some error and rename some functions --- include/common/tglobal.h | 3 ++- include/util/tconfig.h | 7 +++++-- source/common/src/tglobal.c | 23 +++++++++++---------- source/common/src/tmsg.c | 3 +++ source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 11 +++++----- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 4 +++- source/dnode/mnode/impl/src/mndDnode.c | 12 +++++------ source/util/src/tconfig.c | 6 ++++-- 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 4095b650f2..5ebfd24d5e 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -53,7 +53,8 @@ extern char tsVersionName[]; extern uint16_t tsServerPort; extern int32_t tsVersion; extern int32_t tsForceReadConfig; -extern int32_t tsConfigVersion; +extern int32_t tsdmConfigVersion; +extern int32_t tsmmConfigVersion; extern int32_t tsConfigInited; extern int32_t tsStatusInterval; extern int32_t tsNumOfSupportVnodes; diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 197bf04c3c..98e0df9655 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -148,8 +148,11 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump); int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl); -SArray *cfgGetLocalCfg(SConfig *pCfg); -SArray *cfgGetGlobalCfg(SConfig *pCfg); +SArray *getLocalCfg(SConfig *pCfg); +SArray *getGlobalCfg(SConfig *pCfg); + +void setLocalCfg(SConfig *pCfg, SArray *pArray); +void setGlobalCfg(SConfig *pCfg, SArray *pArray); #ifdef __cplusplus } #endif diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 7462bfe1cd..c8b214ecfa 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -45,7 +45,8 @@ char tsVersionName[16] = "community"; uint16_t tsServerPort = 6030; int32_t tsVersion = 30000000; int32_t tsForceReadConfig = 0; -int32_t tsConfigVersion = 0; +int32_t tsdmConfigVersion = -1; +int32_t tsmmConfigVersion = 0; int32_t tsConfigInited = 0; int32_t tsStatusInterval = 1; // second int32_t tsNumOfSupportVnodes = 256; @@ -1917,7 +1918,7 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { cJSON_Delete(pRoot); return TSDB_CODE_OUT_OF_MEMORY; } - tsConfigVersion = pItem->valueint; + tsdmConfigVersion = pItem->valueint; } int32_t sz = taosArrayGetSize(array); @@ -1968,10 +1969,10 @@ int32_t readCfgFile(const char *path, bool isGlobal) { char filename[CONFIG_FILE_LEN] = {0}; SArray *array = NULL; if (isGlobal) { - array = cfgGetGlobalCfg(tsCfg); + array = getGlobalCfg(tsCfg); snprintf(filename, sizeof(filename), "%s%sconfig%sglobal.json", path, TD_DIRSEP, TD_DIRSEP); } else { - array = cfgGetLocalCfg(tsCfg); + array = getLocalCfg(tsCfg); snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP); } @@ -2801,7 +2802,7 @@ int32_t persistLocalConfig(const char *path) { TAOS_RETURN(code); } char *serialized = NULL; - code = localConfigSerialize(cfgGetLocalCfg(tsCfg), &serialized); + code = localConfigSerialize(getLocalCfg(tsCfg), &serialized); if (code != TSDB_CODE_SUCCESS) { uError("failed to serialize local config since %s", tstrerror(code)); TAOS_RETURN(code); @@ -2852,16 +2853,15 @@ _exit: } int32_t tDeserializeSConfigArray(SDecoder *pDecoder, SArray *array) { - int32_t code = 0; - int32_t lino = 0; - int32_t sz = 0; - ECfgDataType dtype = CFG_DTYPE_NONE; + int32_t code = 0; + int32_t lino = 0; + int32_t sz = 0; tDecodeI32(pDecoder, &sz); for (int i = 0; i < sz; i++) { SConfigItem item = {0}; TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &item.name)); - TAOS_CHECK_EXIT(tDecodeI32(pDecoder, (int32_t *)&dtype)); - switch (dtype) { + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, (int32_t *)&item.dtype)); + switch (item.dtype) { { case CFG_DTYPE_NONE: break; @@ -2887,6 +2887,7 @@ int32_t tDeserializeSConfigArray(SDecoder *pDecoder, SArray *array) { break; } } + taosArrayPush(array, &item); } _exit: return code; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c73101c850..83577403aa 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1635,6 +1635,7 @@ int32_t tDeserializeSConfigReq(void *buf, int32_t bufLen, SConfigReq *pReq) { TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->cver)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->forceReadConfig)); if (pReq->forceReadConfig) { + pReq->array = taosArrayInit(128, sizeof(SConfigItem)); TAOS_CHECK_EXIT(tDeserializeSConfigArray(&decoder, pReq->array)); } tEndDecode(&decoder); @@ -1677,7 +1678,9 @@ int32_t tDeserializeSConfigRsp(void *buf, int32_t bufLen, SConfigRsp *pRsp) { TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pRsp->forceReadConfig)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pRsp->isConifgVerified)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pRsp->isVersionVerified)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pRsp->cver)); if ((!pRsp->isConifgVerified) || (!pRsp->isVersionVerified)) { + pRsp->array = taosArrayInit(128, sizeof(SConfigItem)); TAOS_CHECK_EXIT(tDeserializeSConfigArray(&decoder, pRsp->array)); } _exit: diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 8f72758cd9..15176f58a4 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -304,7 +304,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { tDeserializeSConfigRsp(pRsp->pCont, pRsp->contLen, &configRsp) == 0) { if (configRsp.forceReadConfig) { if (configRsp.isConifgVerified) { - persistGlobalConfig(cfgGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver); + persistGlobalConfig(getGlobalCfg(tsCfg), pMgmt->path, configRsp.cver); } else { // log the difference configurations printConfigNotMatch(configRsp.array); @@ -312,13 +312,12 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { } } if (!configRsp.isVersionVerified) { - cfgLoadFromArray(tsCfg, configRsp.array); - persistGlobalConfig(cfgGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver); + persistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver); } } setAllConfigs(tsCfg); persistLocalConfig(pMgmt->path); - setAllConfigs(tsCfg); + tsConfigInited = 1; } _exit: tFreeSConfigRsp(&configRsp); @@ -329,9 +328,9 @@ void dmSendConfigReq(SDnodeMgmt *pMgmt) { int32_t code = 0; SConfigReq req = {0}; - req.cver = tsConfigVersion; + req.cver = tsdmConfigVersion; req.forceReadConfig = tsForceReadConfig; - req.array = cfgGetGlobalCfg(tsCfg); + req.array = getGlobalCfg(tsCfg); dDebug("send config req to mnode, configVersion:%d", req.cver); int32_t contLen = tSerializeSConfigReq(NULL, 0, &req); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 8737d4cf9b..b3b740f0fb 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -45,7 +45,9 @@ static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) { return code; } -static void mmBuildConfigForDeploy(SMnodeMgmt *pMgmt) { persistGlobalConfig(cfgGetGlobalCfg(tsCfg), pMgmt->path, 0); } +static void mmBuildConfigForDeploy(SMnodeMgmt *pMgmt) { + persistGlobalConfig(getGlobalCfg(tsCfg), pMgmt->path, tsmmConfigVersion); +} static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) { pOption->deploy = true; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 060acd228c..d981831c12 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -934,21 +934,21 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) { SArray *diffArray = taosArrayInit(16, sizeof(SConfigItem)); SConfigRsp configRsp = {0}; configRsp.forceReadConfig = configReq.forceReadConfig; - configRsp.cver = tsConfigVersion; + configRsp.cver = tsmmConfigVersion; if (configRsp.forceReadConfig) { // compare config array from configReq with current config array - if (compareSConfigItemArrays(cfgGetGlobalCfg(tsCfg), configReq.array, diffArray)) { + if (compareSConfigItemArrays(getGlobalCfg(tsCfg), configReq.array, diffArray)) { configRsp.array = diffArray; } else { configRsp.isConifgVerified = 1; taosArrayDestroy(diffArray); } } else { - configRsp.array = cfgGetGlobalCfg(tsCfg); - if (configReq.cver == tsConfigVersion) { - configRsp.isConifgVerified = 1; + configRsp.array = getGlobalCfg(tsCfg); + if (configReq.cver == tsmmConfigVersion) { + configRsp.isVersionVerified = 1; } else { - configRsp.array = cfgGetGlobalCfg(tsCfg); + configRsp.array = getGlobalCfg(tsCfg); } } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 3bac376242..3fed23e8a2 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -1537,5 +1537,7 @@ void cfgDestroyIter(SConfigIter *pIter) { taosMemoryFree(pIter); } -SArray *cfgGetLocalCfg(SConfig *pCfg) { return pCfg->localArray; } -SArray *cfgGetGlobalCfg(SConfig *pCfg) { return pCfg->globalArray; } \ No newline at end of file +SArray *getLocalCfg(SConfig *pCfg) { return pCfg->localArray; } +SArray *getGlobalCfg(SConfig *pCfg) { return pCfg->globalArray; } +void setLocalCfg(SConfig *pCfg, SArray *pArray) { pCfg->localArray = pArray; }; +void setGlobalCfg(SConfig *pCfg, SArray *pArray) { pCfg->globalArray = pArray; }; \ No newline at end of file