Add more log info.

This commit is contained in:
xiao-77 2024-11-25 16:23:34 +08:00
parent 9ebff57e09
commit 5d2bc35569
5 changed files with 94 additions and 86 deletions

View File

@ -41,12 +41,6 @@ typedef struct {
int64_t lastIndex;
} SMnodeOpt;
typedef struct {
int32_t version;
SArray *pArray;
TdThreadMutex mutex;
} SMnodeConfig;
/* ------------------------ SMnode ------------------------ */
/**
* @brief Open a mnode.

View File

@ -53,11 +53,6 @@ typedef enum {
typedef enum { CFG_SCOPE_SERVER, CFG_SCOPE_CLIENT, CFG_SCOPE_BOTH } ECfgScopeType;
typedef enum { CFG_CATEGORY_GLOBAL, CFG_CATEGORY_LOCAL } ECfgCategoryType;
typedef enum {
CFG_DYNAMIC_MODIFICATION_SUPPORT,
CFG_DYNAMIC_MODIFICATION_NOT_SUPPORT,
CFG_MODIFICATION_READONLY
} ECfgModificationType;
typedef enum {
CFG_DYN_NONE = 0,
@ -70,12 +65,10 @@ typedef enum {
#ifdef TD_ENTERPRISE
CFG_DYN_ENT_SERVER = CFG_DYN_SERVER,
CFG_DYN_ENT_CLIENT = CFG_DYN_CLIENT,
CFG_DYN_ENT_READONLY = CFG_MODIFICATION_READONLY,
CFG_DYN_ENT_SERVER_LAZY = CFG_DYN_SERVER_LAZY,
CFG_DYN_ENT_CLIENT_LAZY = CFG_DYN_CLIENT_LAZY,
CFG_DYN_ENT_BOTH_LAZY = CFG_DYN_BOTH_LAZY,
CFG_DYN_ENT_BOTH = CFG_DYN_BOTH,
#else
CFG_DYN_ENT_SERVER = CFG_DYN_NONE,
CFG_DYN_ENT_CLIENT = CFG_DYN_NONE,

View File

@ -1927,6 +1927,7 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) {
int32_t sz = taosArrayGetSize(array);
cJSON *configs = cJSON_GetObjectItem(pRoot, "configs");
if (configs == NULL) {
uError("failed to get configs from json, since %s", cJSON_GetErrorPtr());
cJSON_Delete(pRoot);
return TSDB_CODE_OUT_OF_MEMORY;
}
@ -1963,7 +1964,6 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) {
}
}
}
cJSON_Delete(pRoot);
return TSDB_CODE_SUCCESS;
}
@ -1978,6 +1978,7 @@ int32_t readCfgFile(const char *path, bool isGlobal) {
array = taosGetLocalCfg(tsCfg);
snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP);
}
uInfo("start to read config file:%s", filename);
int64_t fileSize = 0;
char *buf = NULL;
@ -1985,27 +1986,33 @@ int32_t readCfgFile(const char *path, bool isGlobal) {
if (terrno != ENOENT) {
uError("failed to stat file:%s , since %s", filename, tstrerror(code));
code = terrno;
goto _exit;
}
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
TdFilePtr pFile = taosOpenFile(filename, TD_FILE_READ);
if (pFile == NULL) {
uError("failed to open file:%s , since %s", filename, tstrerror(code));
code = terrno;
TAOS_RETURN(code);
goto _exit;
}
buf = (char *)taosMemoryMalloc(fileSize + 1);
if (taosReadFile(pFile, buf, fileSize) != fileSize) {
uError("failed to read file:%s , config since %s", filename, tstrerror(code));
(void)taosCloseFile(&pFile);
taosMemoryFree(buf);
TAOS_RETURN(terrno);
code = terrno;
goto _exit;
}
char *serialized = NULL;
code = cfgDeserialize(array, buf, isGlobal);
if (code != TSDB_CODE_SUCCESS) {
uError("failed to deserialize config from %s since %s", filename, tstrerror(code));
TAOS_RETURN(code);
goto _exit;
}
_exit:
if (code != TSDB_CODE_SUCCESS) {
uError("failed to read config from %s since %s", filename, tstrerror(code));
}
taosMemoryFree(buf);
(void)taosCloseFile(&pFile);
TAOS_RETURN(code);
}
@ -2015,6 +2022,7 @@ int32_t tryLoadCfgFromDataDir(SConfig *pCfg) {
TAOS_CHECK_GET_CFG_ITEM(tsCfg, pItem, "forceReadConfig");
tsForceReadConfig = pItem->i32;
if (!tsForceReadConfig) {
uInfo("load config from tsDataDir:%s", tsDataDir);
code = readCfgFile(tsDataDir, false);
if (code != TSDB_CODE_SUCCESS) {
uError("failed to read local config from %s since %s", tsDataDir, tstrerror(code));
@ -2695,17 +2703,13 @@ int8_t taosGranted(int8_t type) {
int32_t globalConfigSerialize(int32_t version, SArray *array, char **serialized) {
char buf[30];
cJSON *json = cJSON_CreateObject();
if (json == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
cJSON_AddNumberToObject(json, "version", version);
if (json == NULL) goto _exit;
json = cJSON_AddNumberToObject(json, "version", version);
if (json == NULL) goto _exit;
int sz = taosArrayGetSize(array);
cJSON *cField = cJSON_CreateObject();
if (cField == NULL) {
cJSON_Delete(json);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
if (cField == NULL) goto _exit;
// cjson only support int32_t or double
// string are used to prohibit the loss of precision
@ -2716,50 +2720,56 @@ int32_t globalConfigSerialize(int32_t version, SArray *array, char **serialized)
case CFG_DTYPE_NONE:
break;
case CFG_DTYPE_BOOL:
cJSON_AddBoolToObject(cField, item->name, item->bval);
cField = cJSON_AddBoolToObject(cField, item->name, item->bval);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_INT32:
cJSON_AddNumberToObject(cField, item->name, item->i32);
cField = cJSON_AddNumberToObject(cField, item->name, item->i32);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_INT64:
(void)sprintf(buf, "%" PRId64, item->i64);
cJSON_AddStringToObject(cField, item->name, buf);
cField = cJSON_AddStringToObject(cField, item->name, buf);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE:
(void)sprintf(buf, "%f", item->fval);
cJSON_AddStringToObject(cField, item->name, buf);
cField = cJSON_AddStringToObject(cField, item->name, buf);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
cJSON_AddStringToObject(cField, item->name, item->str);
cField = cJSON_AddStringToObject(cField, item->name, item->str);
if (cField == NULL) goto _exit;
break;
}
}
}
cJSON_AddItemToObject(json, "configs", cField);
if (!cJSON_AddItemToObject(json, "configs", cField)) {
goto _exit;
}
*serialized = cJSON_Print(json);
_exit:
if (terrno != TSDB_CODE_SUCCESS) {
uError("failed to serialize global config since %s", tstrerror(terrno));
}
cJSON_Delete(json);
return TSDB_CODE_SUCCESS;
return terrno;
}
int32_t localConfigSerialize(SArray *array, char **serialized) {
char buf[30];
cJSON *json = cJSON_CreateObject();
if (json == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
if (json == NULL) goto _exit;
int sz = taosArrayGetSize(array);
cJSON *cField = cJSON_CreateObject();
if (array == NULL) {
cJSON_Delete(json);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
if (cField == NULL) goto _exit;
// cjson only support int32_t or double
// string are used to prohibit the loss of precision
for (int i = 0; i < sz; i++) {
@ -2769,40 +2779,48 @@ int32_t localConfigSerialize(SArray *array, char **serialized) {
case CFG_DTYPE_NONE:
break;
case CFG_DTYPE_BOOL:
cJSON_AddBoolToObject(cField, item->name, item->bval);
cField = cJSON_AddBoolToObject(cField, item->name, item->bval);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_INT32:
cJSON_AddNumberToObject(cField, item->name, item->i32);
cField = cJSON_AddNumberToObject(cField, item->name, item->i32);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_INT64:
(void)sprintf(buf, "%" PRId64, item->i64);
cJSON_AddStringToObject(cField, item->name, buf);
cField = cJSON_AddStringToObject(cField, item->name, buf);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE:
(void)sprintf(buf, "%f", item->fval);
cJSON_AddStringToObject(cField, item->name, buf);
cField = cJSON_AddStringToObject(cField, item->name, buf);
if (cField == NULL) goto _exit;
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
cJSON_AddStringToObject(cField, item->name, item->str);
cField = cJSON_AddStringToObject(cField, item->name, item->str);
if (cField == NULL) goto _exit;
break;
}
}
}
cJSON_AddItemToObject(json, "configs", cField);
*serialized = cJSON_Print(json);
_exit:
if (terrno != TSDB_CODE_SUCCESS) {
uError("failed to serialize local config since %s", tstrerror(terrno));
}
cJSON_Delete(json);
return TSDB_CODE_SUCCESS;
return terrno;
}
// TODO:close file when error
int32_t taosPersistGlobalConfig(SArray *array, const char *path, int32_t version) {
// TODO: just tmp ,refactor later
int32_t code = 0;
int32_t lino = 0;
char *buffer = NULL;
TdFilePtr pFile = NULL;
char filepath[CONFIG_FILE_LEN] = {0};
@ -2810,12 +2828,7 @@ int32_t taosPersistGlobalConfig(SArray *array, const char *path, int32_t version
snprintf(filepath, sizeof(filepath), "%s%sconfig", path, TD_DIRSEP);
snprintf(filename, sizeof(filename), "%s%sconfig%sglobal.json", path, TD_DIRSEP, TD_DIRSEP);
// TODO(beryl) need to check if the file is existed
if (taosMkDir(filepath) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
uError("failed to create dir:%s since %s", filepath, tstrerror(code));
TAOS_RETURN(code);
}
TAOS_CHECK_GOTO(taosMkDir(filepath), &lino, _exit);
TdFilePtr pConfigFile =
taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
@ -2826,19 +2839,21 @@ int32_t taosPersistGlobalConfig(SArray *array, const char *path, int32_t version
TAOS_RETURN(code);
}
char *serialized = NULL;
code = globalConfigSerialize(version, array, &serialized);
TAOS_CHECK_GOTO(globalConfigSerialize(version, array, &serialized), &lino, _exit);
TAOS_CHECK_GOTO(taosWriteFile(pConfigFile, serialized, strlen(serialized)), &lino, _exit);
_exit:
if (code != TSDB_CODE_SUCCESS) {
uError("failed to serialize local config since %s", tstrerror(code));
TAOS_RETURN(code);
uError("failed to persist global config at line:%d, since %s", lino, tstrerror(code));
}
taosWriteFile(pConfigFile, serialized, strlen(serialized));
(void)taosCloseFile(&pConfigFile);
return TSDB_CODE_SUCCESS;
return code;
}
int32_t taosPersistLocalConfig(const char *path) {
// TODO: just tmp ,refactor later
int32_t code = 0;
int32_t lino = 0;
char *buffer = NULL;
TdFilePtr pFile = NULL;
char filepath[CONFIG_FILE_LEN] = {0};
@ -2847,11 +2862,7 @@ int32_t taosPersistLocalConfig(const char *path) {
snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP);
// TODO(beryl) need to check if the file is existed
if (taosMkDir(filepath) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
uError("failed to create dir:%s since %s", filepath, tstrerror(code));
TAOS_RETURN(code);
}
TAOS_CHECK_GOTO(taosMkDir(filepath), &lino, _exit);
TdFilePtr pConfigFile =
taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
@ -2861,15 +2872,18 @@ int32_t taosPersistLocalConfig(const char *path) {
uError("failed to open file:%s since %s", filename, tstrerror(code));
TAOS_RETURN(code);
}
char *serialized = NULL;
code = localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized);
if (code != TSDB_CODE_SUCCESS) {
uError("failed to serialize local config since %s", tstrerror(code));
TAOS_RETURN(code);
}
taosWriteFile(pConfigFile, serialized, strlen(serialized));
TAOS_CHECK_GOTO(localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized), &lino, _exit);
TAOS_CHECK_GOTO(taosWriteFile(pConfigFile, serialized, strlen(serialized)), &lino, _exit);
(void)taosCloseFile(&pConfigFile);
return TSDB_CODE_SUCCESS;
_exit:
if (code != TSDB_CODE_SUCCESS) {
uError("failed to persist global config at line:%d, since %s", lino, tstrerror(code));
}
(void)taosCloseFile(&pConfigFile);
return code;
}
int32_t tSerializeSConfigArray(SEncoder *pEncoder, SArray *array) {

View File

@ -290,8 +290,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
if (pRsp->code != 0) {
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) {
dGInfo("dnode:%d, set to dropped since not exist in mnode, statusSeq:%d", pMgmt->pData->dnodeId,
pMgmt->statusSeq);
dGInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId);
pMgmt->pData->dropped = 1;
if (dmWriteEps(pMgmt->pData) != 0) {
dError("failed to write dnode file");
@ -306,6 +305,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
// Try to use cfg file in current dnode.
if (configRsp.forceReadConfig) {
if (configRsp.isConifgVerified) {
uInfo("force read config and check config verified");
code = taosPersistGlobalConfig(taosGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver);
if (code != TSDB_CODE_SUCCESS) {
dError("failed to persist global config since %s", tstrerror(code));
@ -320,6 +320,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
}
// Try to use cfg from mnode sdb.
if (!configRsp.isVersionVerified) {
uInfo("config version not verified, update config");
needUpdate = true;
code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
if (code != TSDB_CODE_SUCCESS) {

View File

@ -141,7 +141,7 @@ SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
obj = sdbGetRowObj(pRow);
if (obj == NULL) goto _OVER;
int32_t dataPos = 0;
// TODO(beryl):free it.
SDB_GET_BINARY(pRaw, dataPos, obj->name, CFG_NAME_MAX_LEN, _OVER)
SDB_GET_INT32(pRaw, dataPos, (int32_t *)&obj->dtype, _OVER)
switch (obj->dtype) {
@ -161,6 +161,8 @@ SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32(pRaw, dataPos, &len, _OVER)
char *buf = taosMemoryMalloc(len + 1);
SDB_GET_BINARY(pRaw, dataPos, buf, len, _OVER)
obj->fval = atof(buf);
taosMemoryFree(buf);
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
@ -180,6 +182,7 @@ _OVER:
if (terrno != 0) {
mError("cfg failed to decode from raw:%p since %s", pRaw, terrstr());
taosMemoryFreeClear(pRow);
taosMemoryFreeClear(obj->str);
return NULL;
}
@ -223,7 +226,6 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
configRsp.array = diffArray;
} else {
configRsp.isConifgVerified = 1;
taosArrayDestroy(diffArray);
}
} else {
configRsp.array = taosGetGlobalCfg(tsCfg);
@ -235,17 +237,21 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
}
int32_t contLen = tSerializeSConfigRsp(NULL, 0, &configRsp);
void *pHead = rpcMallocCont(contLen);
if (contLen < 0) {
code = contLen;
goto _OVER;
}
void *pHead = rpcMallocCont(contLen);
contLen = tSerializeSConfigRsp(pHead, contLen, &configRsp);
taosArrayDestroy(diffArray);
if (contLen < 0) {
code = contLen;
goto _OVER;
}
pReq->info.rspLen = contLen;
pReq->info.rsp = pHead;
_OVER:
_OVER:
taosArrayDestroy(diffArray);
mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_SUCCESS;
}
@ -254,6 +260,7 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
int code = -1;
size_t sz = 0;
mInfo("init write cfg to sdb");
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-write-config");
if (pTrans == NULL) {
mError("failed to init write cfg in create trans, since %s", terrstr());
@ -264,6 +271,7 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
SConfigObj *obj = mndInitConfigVersion();
if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) {
mError("failed to init mnd config version, since %s", terrstr());
goto _OVER;
}
sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
@ -275,7 +283,6 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
}
taosMemoryFree(obj);
}
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) goto _OVER;
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
_OVER:
@ -540,20 +547,19 @@ _err:
TAOS_RETURN(code);
}
// TODO(beryl):add more log.
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue) {
int32_t code = -1;
int32_t lino = -1;
SConfigObj *pVersion = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
if (pVersion == NULL) {
mWarn("failed to acquire tsmmConfigVersion while update config, since %s", terrstr());
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) {
mWarn("failed to acquire mnd config:%s while update config, since %s", name, terrstr());
mError("failed to acquire mnd config:%s while update config, since %s", name, terrstr());
code = terrno;
goto _OVER;
}