diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 98e0df9655..4ba9a9c93e 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -118,6 +118,8 @@ void cfgCleanup(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg); SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName); int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock); +int32_t cfgGetAndSetItem(SConfig *pCfg, SConfigItem *pItem, const char *name, const char *value, ECfgSrcType stype, + bool lock); int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer); int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter); @@ -148,11 +150,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 *getLocalCfg(SConfig *pCfg); -SArray *getGlobalCfg(SConfig *pCfg); +SArray *taosGetLocalCfg(SConfig *pCfg); +SArray *taosGetGlobalCfg(SConfig *pCfg); -void setLocalCfg(SConfig *pCfg, SArray *pArray); -void setGlobalCfg(SConfig *pCfg, SArray *pArray); +void taosSetLocalCfg(SConfig *pCfg, SArray *pArray); +void taosSetGlobalCfg(SConfig *pCfg, SArray *pArray); #ifdef __cplusplus } #endif diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index c8b214ecfa..50fab2d3f4 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1969,10 +1969,10 @@ int32_t readCfgFile(const char *path, bool isGlobal) { char filename[CONFIG_FILE_LEN] = {0}; SArray *array = NULL; if (isGlobal) { - array = getGlobalCfg(tsCfg); + array = taosGetGlobalCfg(tsCfg); snprintf(filename, sizeof(filename), "%s%sconfig%sglobal.json", path, TD_DIRSEP, TD_DIRSEP); } else { - array = getLocalCfg(tsCfg); + array = taosGetLocalCfg(tsCfg); snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP); } @@ -2802,7 +2802,7 @@ int32_t persistLocalConfig(const char *path) { TAOS_RETURN(code); } char *serialized = NULL; - code = localConfigSerialize(getLocalCfg(tsCfg), &serialized); + code = localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized); if (code != TSDB_CODE_SUCCESS) { uError("failed to serialize local config since %s", tstrerror(code)); TAOS_RETURN(code); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 83577403aa..989078d20d 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -3243,6 +3243,7 @@ int32_t tSerializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq) tEncoderInit(&encoder, buf, bufLen); TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->version)); TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->config)); TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->value)); tEndEncode(&encoder); @@ -3264,6 +3265,7 @@ int32_t tDeserializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq tDecoderInit(&decoder, buf, bufLen); TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->version)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->config)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->value)); tEndDecode(&decoder); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 15176f58a4..7301923873 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(getGlobalCfg(tsCfg), pMgmt->path, configRsp.cver); + persistGlobalConfig(taosGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver); } else { // log the difference configurations printConfigNotMatch(configRsp.array); @@ -330,7 +330,7 @@ void dmSendConfigReq(SDnodeMgmt *pMgmt) { req.cver = tsdmConfigVersion; req.forceReadConfig = tsForceReadConfig; - req.array = getGlobalCfg(tsCfg); + req.array = taosGetGlobalCfg(tsCfg); dDebug("send config req to mnode, configVersion:%d", req.cver); int32_t contLen = tSerializeSConfigReq(NULL, 0, &req); @@ -446,9 +446,9 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value); - SConfig *pCfg = taosGetCfg(); - - code = cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true); + SConfig *pCfg = taosGetCfg(); + SConfigItem *pItem = NULL; + code = cfgGetAndSetItem(pCfg, pItem, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true); if (code != 0) { if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) { code = 0; @@ -456,8 +456,17 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { return code; } } + TAOS_CHECK_RETURN(taosCfgDynamicOptions(pCfg, cfgReq.config, true)); + if (cfgReq.version > 0) { + tsdmConfigVersion = cfgReq.version; + } + if (pItem->category == CFG_CATEGORY_GLOBAL) { + persistGlobalConfig(taosGetGlobalCfg(pCfg), pMgmt->path, tsdmConfigVersion); + } else { + persistLocalConfig(pMgmt->path); + } - return taosCfgDynamicOptions(pCfg, cfgReq.config, true); + return TSDB_CODE_SUCCESS; } int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index 9e68747878..a044f6e8c4 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -214,18 +214,18 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) { configRsp.cver = tsmmConfigVersion; if (configRsp.forceReadConfig) { // compare config array from configReq with current config array - if (compareSConfigItemArrays(getGlobalCfg(tsCfg), configReq.array, diffArray)) { + if (compareSConfigItemArrays(taosGetGlobalCfg(tsCfg), configReq.array, diffArray)) { configRsp.array = diffArray; } else { configRsp.isConifgVerified = 1; taosArrayDestroy(diffArray); } } else { - configRsp.array = getGlobalCfg(tsCfg); + configRsp.array = taosGetGlobalCfg(tsCfg); if (configReq.cver == tsmmConfigVersion) { configRsp.isVersionVerified = 1; } else { - configRsp.array = getGlobalCfg(tsCfg); + configRsp.array = taosGetGlobalCfg(tsCfg); } } @@ -261,10 +261,10 @@ int32_t mndInitWriteCfg(SMnode *pMnode) { if ((code = mndSetCreateConfigCommitLogs(pTrans, &obj)) != 0) { mError("failed to init mnd config version, since %s", terrstr()); } - sz = taosArrayGetSize(getGlobalCfg(tsCfg)); + sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); for (int i = 0; i < sz; ++i) { - SConfigItem *item = taosArrayGet(getGlobalCfg(tsCfg), i); + SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); SConfigObj *obj = mndInitConfigObj(item); if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) { mError("failed to init mnd config:%s, since %s", item->name, terrstr()); @@ -296,9 +296,9 @@ int32_t mndInitReadCfg(SMnode *pMnode) { sdbRelease(pMnode->pSdb, obj); } - sz = taosArrayGetSize(getGlobalCfg(tsCfg)); + sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); for (int i = 0; i < sz; ++i) { - SConfigItem *item = taosArrayGet(getGlobalCfg(tsCfg), i); + SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); SConfigObj *newObj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name); if (newObj == NULL) { mInfo("failed to acquire mnd config:%s, since %s", item->name, terrstr()); @@ -481,7 +481,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { TAOS_CHECK_GOTO(cfgCheckRangeForDynUpdate(taosGetCfg(), dcfgReq.config, dcfgReq.value, true), &lino, _err_out); } - mndConfigUpdateTrans(pMnode, cfgReq.config, cfgReq.value); + // update config in sdb + TAOS_CHECK_GOTO(mndConfigUpdateTrans(pMnode, cfgReq.config, cfgReq.value), &lino, _err_out); { // audit char obj[50] = {0}; (void)sprintf(obj, "%d", cfgReq.dnodeId); @@ -491,6 +492,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { tFreeSMCfgDnodeReq(&cfgReq); + dcfgReq.version = tsmmConfigVersion; code = mndSendCfgDnodeReq(pMnode, cfgReq.dnodeId, &dcfgReq); // dont care suss or succ; diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index f4b158075d..f05c90f6a3 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -40,6 +40,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile); int32_t cfgLoadFromEnvVar(SConfig *pConfig); int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd); int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); +int32_t cfgSetItemVal(SConfigItem *item, ECfgDataType dtype); extern char **environ; @@ -353,49 +354,7 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); } - switch (pItem->dtype) { - case CFG_DTYPE_BOOL: { - code = cfgSetBool(pItem, value, stype); - break; - } - case CFG_DTYPE_INT32: { - code = cfgSetInt32(pItem, value, stype); - break; - } - case CFG_DTYPE_INT64: { - code = cfgSetInt64(pItem, value, stype); - break; - } - case CFG_DTYPE_FLOAT: - case CFG_DTYPE_DOUBLE: { - code = cfgSetFloat(pItem, value, stype); - break; - } - case CFG_DTYPE_STRING: { - code = cfgSetString(pItem, value, stype); - break; - } - case CFG_DTYPE_DIR: { - code = cfgSetDir(pItem, value, stype); - break; - } - case CFG_DTYPE_TIMEZONE: { - code = cfgSetTimezone(pItem, value, stype); - break; - } - case CFG_DTYPE_CHARSET: { - code = doSetConf(pItem, value, stype); - break; - } - case CFG_DTYPE_LOCALE: { - code = doSetConf(pItem, value, stype); - break; - } - case CFG_DTYPE_NONE: - default: - code = TSDB_CODE_INVALID_CFG; - break; - } + TAOS_CHECK_RETURN(cfgSetItemVal(pItem, pItem->dtype)); if (lock) { (void)taosThreadMutexUnlock(&pCfg->lock); @@ -404,6 +363,62 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy TAOS_RETURN(code); } +int32_t cfgGetAndSetItem(SConfig *pCfg, SConfigItem *pItem, const char *name, const char *value, ECfgSrcType stype, + bool lock) { + // GRANT_CFG_SET; + int32_t code = TSDB_CODE_SUCCESS; + + if (lock) { + (void)taosThreadMutexLock(&pCfg->lock); + } + + pItem = cfgGetItem(pCfg, name); + if (pItem == NULL) { + (void)taosThreadMutexUnlock(&pCfg->lock); + TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + } + + TAOS_CHECK_RETURN(cfgSetItemVal(pItem, pItem->dtype)); + + if (lock) { + (void)taosThreadMutexUnlock(&pCfg->lock); + } + + TAOS_RETURN(code); +} + +int32_t cfgSetItemVal(SConfigItem *item, ECfgDataType dtype) { + if (item == NULL) { + TAOS_RETURN(TSDB_CODE_INVALID_CFG); + } + item->dtype = dtype; + switch (dtype) { + case CFG_DTYPE_BOOL: + item->bval = false; + break; + case CFG_DTYPE_INT32: + item->i32 = 0; + break; + case CFG_DTYPE_INT64: + item->i64 = 0; + break; + case CFG_DTYPE_FLOAT: + case CFG_DTYPE_DOUBLE: + item->fval = 0; + break; + case CFG_DTYPE_STRING: + case CFG_DTYPE_DIR: + case CFG_DTYPE_LOCALE: + case CFG_DTYPE_CHARSET: + case CFG_DTYPE_TIMEZONE: + item->str = NULL; + break; + default: + TAOS_RETURN(TSDB_CODE_INVALID_CFG); + } + + TAOS_RETURN(TSDB_CODE_SUCCESS); +} SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName) { if (pCfg == NULL) return NULL; @@ -1538,7 +1553,7 @@ void cfgDestroyIter(SConfigIter *pIter) { taosMemoryFree(pIter); } -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 +SArray *taosGetLocalCfg(SConfig *pCfg) { return pCfg->localArray; } +SArray *taosGetGlobalCfg(SConfig *pCfg) { return pCfg->globalArray; } +void taosSetLocalCfg(SConfig *pCfg, SArray *pArray) { pCfg->localArray = pArray; }; +void taosSetGlobalCfg(SConfig *pCfg, SArray *pArray) { pCfg->globalArray = pArray; }; \ No newline at end of file