Fix review errors.

This commit is contained in:
xiao-77 2024-12-10 20:13:53 +08:00
parent b34dd6f347
commit 28ea9b9f60
5 changed files with 58 additions and 27 deletions

View File

@ -1425,9 +1425,6 @@ static int32_t taosSetSystemCfg(SConfig *pCfg) {
tsEnableCoreFile = pItem->bval; tsEnableCoreFile = pItem->bval;
taosSetCoreDump(tsEnableCoreFile); taosSetCoreDump(tsEnableCoreFile);
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "assert");
tsAssert = pItem->bval;
// todo // todo
tsVersion = 30000000; tsVersion = 30000000;
@ -1981,7 +1978,11 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) {
int64_t actDiskID = 0; int64_t actDiskID = 0;
int64_t expDiskID = taosStr2Int64(cJSON_GetStringValue(filed), NULL, 10); int64_t expDiskID = taosStr2Int64(cJSON_GetStringValue(filed), NULL, 10);
if (!taosCheckFileDiskID(dir, &actDiskID, expDiskID)) { if ((code = taosGetFileDiskID(dir, &actDiskID)) != 0) {
uError("failed to get disk id for dir:%s, since %s", dir, tstrerror(code));
goto _exit;
}
if (actDiskID != expDiskID) {
uError("failed to check disk id for dir:%s, actDiskID%" PRId64 ", expDiskID%" PRId64, dir, actDiskID, uError("failed to check disk id for dir:%s, actDiskID%" PRId64 ", expDiskID%" PRId64, dir, actDiskID,
expDiskID); expDiskID);
code = TSDB_CODE_INVALID_DISK_ID; code = TSDB_CODE_INVALID_DISK_ID;
@ -2006,7 +2007,7 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) {
break; break;
case CFG_DTYPE_FLOAT: case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE: case CFG_DTYPE_DOUBLE:
pItem->fval = atoll(cJSON_GetStringValue(pJson)); pItem->fval = taosStr2Float(cJSON_GetStringValue(pJson), NULL);
break; break;
case CFG_DTYPE_STRING: case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR: case CFG_DTYPE_DIR:
@ -2959,7 +2960,7 @@ int32_t taosPersistLocalConfig(const char *path) {
taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pConfigFile == NULL) { if (pConfigFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(terrno);
uError("failed to open file:%s since %s", filename, tstrerror(code)); uError("failed to open file:%s since %s", filename, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -2968,7 +2969,7 @@ int32_t taosPersistLocalConfig(const char *path) {
TAOS_CHECK_GOTO(localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized), &lino, _exit); TAOS_CHECK_GOTO(localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized), &lino, _exit);
if (taosWriteFile(pConfigFile, serialized, strlen(serialized)) < 0) { if (taosWriteFile(pConfigFile, serialized, strlen(serialized)) < 0) {
lino = __LINE__; lino = __LINE__;
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(terrno);
uError("failed to write file:%s since %s", filename, tstrerror(code)); uError("failed to write file:%s since %s", filename, tstrerror(code));
goto _exit; goto _exit;
} }

View File

@ -198,7 +198,8 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
req.clusterCfg.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold; req.clusterCfg.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
tstrncpy(req.clusterCfg.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN); tstrncpy(req.clusterCfg.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
char timestr[32] = "1970-01-01 00:00:00.00"; char timestr[32] = "1970-01-01 00:00:00.00";
if (taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, NULL) != 0) { if (taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, NULL) !=
0) {
dError("failed to parse time since %s", tstrerror(code)); dError("failed to parse time since %s", tstrerror(code));
} }
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
@ -333,6 +334,10 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
} }
if (needUpdate) { if (needUpdate) {
code = cfgUpdateFromArray(tsCfg, configRsp.array); code = cfgUpdateFromArray(tsCfg, configRsp.array);
if (code != TSDB_CODE_SUCCESS) {
dError("failed to update config since %s", tstrerror(code));
goto _exit;
}
code = setAllConfigs(tsCfg); code = setAllConfigs(tsCfg);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
dError("failed to set all configs since %s", tstrerror(code)); dError("failed to set all configs since %s", tstrerror(code));
@ -369,6 +374,10 @@ void dmSendConfigReq(SDnodeMgmt *pMgmt) {
} }
void *pHead = rpcMallocCont(contLen); void *pHead = rpcMallocCont(contLen);
if (pHead == NULL) {
dError("failed to malloc cont since %s", tstrerror(contLen));
return;
}
contLen = tSerializeSConfigReq(pHead, contLen, &req); contLen = tSerializeSConfigReq(pHead, contLen, &req);
if (contLen < 0) { if (contLen < 0) {
rpcFreeCont(pHead); rpcFreeCont(pHead);

View File

@ -51,7 +51,6 @@ static void *dmConfigThreadFp(void *param) {
SDnodeMgmt *pMgmt = param; SDnodeMgmt *pMgmt = param;
int64_t lastTime = taosGetTimestampMs(); int64_t lastTime = taosGetTimestampMs();
setThreadName("dnode-config"); setThreadName("dnode-config");
int32_t upTimeCount = 0;
while (1) { while (1) {
taosMsleep(200); taosMsleep(200);
if (pMgmt->pData->dropped || pMgmt->pData->stopped || tsConfigInited) break; if (pMgmt->pData->dropped || pMgmt->pData->stopped || tsConfigInited) break;

View File

@ -244,6 +244,10 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
} }
array = taosArrayInit(16, sizeof(SConfigItem)); array = taosArrayInit(16, sizeof(SConfigItem));
if (array == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER;
}
SConfigRsp configRsp = {0}; SConfigRsp configRsp = {0};
configRsp.forceReadConfig = configReq.forceReadConfig; configRsp.forceReadConfig = configReq.forceReadConfig;
@ -291,6 +295,7 @@ _OVER:
if (code != 0) { if (code != 0) {
mError("failed to process config req, since %s", tstrerror(code)); mError("failed to process config req, since %s", tstrerror(code));
} }
sdbRelease(pMnode->pSdb, vObj);
cfgArrayCleanUp(array); cfgArrayCleanUp(array);
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -310,7 +315,7 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
// encode mnd config version // encode mnd config version
SConfigObj *versionObj = mndInitConfigVersion(); SConfigObj *versionObj = mndInitConfigVersion();
if ((code = mndSetCreateConfigCommitLogs(pTrans, versionObj)) != 0) { if ((code = mndSetCreateConfigCommitLogs(pTrans, versionObj)) != 0) {
mError("failed to init mnd config version, since %s", terrstr()); mError("failed to init mnd config version, since %s", tstrerror(code));
taosMemoryFree(versionObj->str); taosMemoryFree(versionObj->str);
taosMemoryFree(versionObj); taosMemoryFree(versionObj);
goto _OVER; goto _OVER;
@ -327,6 +332,8 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
} }
if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) { if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) {
mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code)); mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
taosMemoryFree(obj);
goto _OVER;
} }
taosMemoryFree(obj); taosMemoryFree(obj);
} }
@ -347,7 +354,7 @@ int32_t mndInitReadCfg(SMnode *pMnode) {
if (obj == NULL) { if (obj == NULL) {
code = mndInitWriteCfg(pMnode); code = mndInitWriteCfg(pMnode);
if (code != 0) { if (code != 0) {
mError("failed to init write cfg, since %s", terrstr()); mError("failed to init write cfg, since %s", tstrerror(code));
} }
mInfo("failed to acquire mnd config version, try to rebuild it , since %s", terrstr()); mInfo("failed to acquire mnd config version, try to rebuild it , since %s", terrstr());
goto _OVER; goto _OVER;
@ -426,17 +433,17 @@ static int32_t mndMCfg2DCfg(SMCfgDnodeReq *pMCfgReq, SDCfgDnodeReq *pDCfgReq) {
} }
size_t optLen = p - pMCfgReq->config; size_t optLen = p - pMCfgReq->config;
tstrncpy(pDCfgReq->config, pMCfgReq->config, optLen + 1); strncpy(pDCfgReq->config, pMCfgReq->config, optLen);
pDCfgReq->config[optLen] = 0; pDCfgReq->config[optLen] = 0;
if (' ' == pMCfgReq->config[optLen]) { if (' ' == pMCfgReq->config[optLen]) {
// 'key value' // 'key value'
if (strlen(pMCfgReq->value) != 0) goto _err; if (strlen(pMCfgReq->value) != 0) goto _err;
tstrncpy(pDCfgReq->value, p + 1, strlen(p + 1)); (void)strcpy(pDCfgReq->value, p + 1);
} else { } else {
// 'key' 'value' // 'key' 'value'
if (strlen(pMCfgReq->value) == 0) goto _err; if (strlen(pMCfgReq->value) == 0) goto _err;
tstrncpy(pDCfgReq->value, pMCfgReq->value, strlen(pMCfgReq->value)); (void)strcpy(pDCfgReq->value, pMCfgReq->value);
} }
TAOS_RETURN(code); TAOS_RETURN(code);
@ -659,6 +666,7 @@ static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
if (item.name == NULL) { if (item.name == NULL) {
code = terrno; code = terrno;
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, obj);
goto _exit; goto _exit;
} }
switch (obj->dtype) { switch (obj->dtype) {
@ -685,6 +693,7 @@ static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
item.str = taosStrdup(obj->str); item.str = taosStrdup(obj->str);
if (item.str == NULL) { if (item.str == NULL) {
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, obj);
code = terrno; code = terrno;
goto _exit; goto _exit;
} }
@ -692,6 +701,7 @@ static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array) {
} }
if (taosArrayPush(array, &item) == NULL) { if (taosArrayPush(array, &item) == NULL) {
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, obj);
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
break; break;
@ -731,6 +741,10 @@ SArray *initVariablesFromItems(SArray *pItems) {
int32_t sz = taosArrayGetSize(pItems); int32_t sz = taosArrayGetSize(pItems);
SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo)); SArray *pInfos = taosArrayInit(sz, sizeof(SVariablesInfo));
if (pInfos == NULL) {
mError("failed to init array while init variables from items, since %s", tstrerror(terrno));
return NULL;
}
for (int32_t i = 0; i < sz; ++i) { for (int32_t i = 0; i < sz; ++i) {
SConfigItem *pItem = taosArrayGet(pItems, i); SConfigItem *pItem = taosArrayGet(pItems, i);
SVariablesInfo info = {0}; SVariablesInfo info = {0};

View File

@ -17,6 +17,7 @@
#include "cJSON.h" #include "cJSON.h"
#include "taoserror.h" #include "taoserror.h"
#include "tconfig.h" #include "tconfig.h"
#include "tconv.h"
#include "tenv.h" #include "tenv.h"
#include "tglobal.h" #include "tglobal.h"
#include "tgrant.h" #include "tgrant.h"
@ -24,7 +25,6 @@
#include "tlog.h" #include "tlog.h"
#include "tunit.h" #include "tunit.h"
#include "tutil.h" #include "tutil.h"
#include "tconv.h"
#define CFG_NAME_PRINT_LEN 32 #define CFG_NAME_PRINT_LEN 32
#define CFG_SRC_PRINT_LEN 12 #define CFG_SRC_PRINT_LEN 12
@ -129,6 +129,10 @@ int32_t cfgUpdateFromArray(SConfig *pCfg, SArray *pArgs) {
case CFG_DTYPE_TIMEZONE: case CFG_DTYPE_TIMEZONE:
taosMemoryFree(pItemOld->str); taosMemoryFree(pItemOld->str);
pItemOld->str = taosStrdup(pItemNew->str); pItemOld->str = taosStrdup(pItemNew->str);
if (pItemOld->str == NULL) {
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(terrno);
}
break; break;
default: default:
break; break;
@ -307,7 +311,7 @@ static int32_t doSetConf(SConfigItem *pItem, const char *value, ECfgSrcType styp
} }
static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) { static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
if (stype == CFG_STYPE_ALTER_SERVER_CMD || (pItem->dynScope & CFG_DYN_CLIENT) == 0){ if (stype == CFG_STYPE_ALTER_SERVER_CMD || (pItem->dynScope & CFG_DYN_CLIENT) == 0) {
uError("failed to config timezone, not support"); uError("failed to config timezone, not support");
TAOS_RETURN(TSDB_CODE_INVALID_CFG); TAOS_RETURN(TSDB_CODE_INVALID_CFG);
} }
@ -325,7 +329,7 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType
} }
static int32_t cfgSetCharset(SConfigItem *pItem, const char *value, ECfgSrcType stype) { static int32_t cfgSetCharset(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
if (stype == CFG_STYPE_ALTER_SERVER_CMD || stype == CFG_STYPE_ALTER_CLIENT_CMD){ if (stype == CFG_STYPE_ALTER_SERVER_CMD || stype == CFG_STYPE_ALTER_CLIENT_CMD) {
uError("failed to config charset, not support"); uError("failed to config charset, not support");
TAOS_RETURN(TSDB_CODE_INVALID_CFG); TAOS_RETURN(TSDB_CODE_INVALID_CFG);
} }
@ -351,7 +355,7 @@ static int32_t cfgSetCharset(SConfigItem *pItem, const char *value, ECfgSrcType
} }
static int32_t cfgSetLocale(SConfigItem *pItem, const char *value, ECfgSrcType stype) { static int32_t cfgSetLocale(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
if (stype == CFG_STYPE_ALTER_SERVER_CMD || (pItem->dynScope & CFG_DYN_CLIENT) == 0){ if (stype == CFG_STYPE_ALTER_SERVER_CMD || (pItem->dynScope & CFG_DYN_CLIENT) == 0) {
uError("failed to config locale, not support"); uError("failed to config locale, not support");
TAOS_RETURN(TSDB_CODE_INVALID_CFG); TAOS_RETURN(TSDB_CODE_INVALID_CFG);
} }
@ -589,7 +593,11 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
cfgUnLock(pCfg); cfgUnLock(pCfg);
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
} }
TAOS_CHECK_RETURN(checkItemDyn(pItem, isServer)); int32_t code = checkItemDyn(pItem, isServer);
if (code != TSDB_CODE_SUCCESS) {
cfgUnLock(pCfg);
TAOS_RETURN(code);
}
if ((!isUpdateAll) && (pItem->category == CFG_CATEGORY_GLOBAL)) { if ((!isUpdateAll) && (pItem->category == CFG_CATEGORY_GLOBAL)) {
uError("failed to config:%s, not support update global config on only one dnode", name); uError("failed to config:%s, not support update global config on only one dnode", name);
cfgUnLock(pCfg); cfgUnLock(pCfg);
@ -872,14 +880,14 @@ int32_t cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t
case CFG_DTYPE_DOUBLE: case CFG_DTYPE_DOUBLE:
len = tsnprintf(buf, bufSize, "%f", pItem->fval); len = tsnprintf(buf, bufSize, "%f", pItem->fval);
break; break;
case CFG_DTYPE_TIMEZONE:{ case CFG_DTYPE_TIMEZONE: {
// char str1[TD_TIMEZONE_LEN] = {0}; // char str1[TD_TIMEZONE_LEN] = {0};
// time_t tx1 = taosGetTimestampSec(); // time_t tx1 = taosGetTimestampSec();
// if (taosFormatTimezoneStr(tx1, buf, NULL, str1) != 0) { // if (taosFormatTimezoneStr(tx1, buf, NULL, str1) != 0) {
// tstrncpy(str1, "tz error", sizeof(str1)); // tstrncpy(str1, "tz error", sizeof(str1));
// } // }
// len = tsnprintf(buf, bufSize, "%s", str1); // len = tsnprintf(buf, bufSize, "%s", str1);
// break; // break;
} }
case CFG_DTYPE_STRING: case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR: case CFG_DTYPE_DIR: