Add more log info.
This commit is contained in:
parent
9ebff57e09
commit
5d2bc35569
|
@ -41,12 +41,6 @@ typedef struct {
|
||||||
int64_t lastIndex;
|
int64_t lastIndex;
|
||||||
} SMnodeOpt;
|
} SMnodeOpt;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t version;
|
|
||||||
SArray *pArray;
|
|
||||||
TdThreadMutex mutex;
|
|
||||||
} SMnodeConfig;
|
|
||||||
|
|
||||||
/* ------------------------ SMnode ------------------------ */
|
/* ------------------------ SMnode ------------------------ */
|
||||||
/**
|
/**
|
||||||
* @brief Open a mnode.
|
* @brief Open a mnode.
|
||||||
|
|
|
@ -53,11 +53,6 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum { CFG_SCOPE_SERVER, CFG_SCOPE_CLIENT, CFG_SCOPE_BOTH } ECfgScopeType;
|
typedef enum { CFG_SCOPE_SERVER, CFG_SCOPE_CLIENT, CFG_SCOPE_BOTH } ECfgScopeType;
|
||||||
typedef enum { CFG_CATEGORY_GLOBAL, CFG_CATEGORY_LOCAL } ECfgCategoryType;
|
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 {
|
typedef enum {
|
||||||
CFG_DYN_NONE = 0,
|
CFG_DYN_NONE = 0,
|
||||||
|
@ -70,12 +65,10 @@ typedef enum {
|
||||||
#ifdef TD_ENTERPRISE
|
#ifdef TD_ENTERPRISE
|
||||||
CFG_DYN_ENT_SERVER = CFG_DYN_SERVER,
|
CFG_DYN_ENT_SERVER = CFG_DYN_SERVER,
|
||||||
CFG_DYN_ENT_CLIENT = CFG_DYN_CLIENT,
|
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_SERVER_LAZY = CFG_DYN_SERVER_LAZY,
|
||||||
CFG_DYN_ENT_CLIENT_LAZY = CFG_DYN_CLIENT_LAZY,
|
CFG_DYN_ENT_CLIENT_LAZY = CFG_DYN_CLIENT_LAZY,
|
||||||
CFG_DYN_ENT_BOTH_LAZY = CFG_DYN_BOTH_LAZY,
|
CFG_DYN_ENT_BOTH_LAZY = CFG_DYN_BOTH_LAZY,
|
||||||
CFG_DYN_ENT_BOTH = CFG_DYN_BOTH,
|
CFG_DYN_ENT_BOTH = CFG_DYN_BOTH,
|
||||||
|
|
||||||
#else
|
#else
|
||||||
CFG_DYN_ENT_SERVER = CFG_DYN_NONE,
|
CFG_DYN_ENT_SERVER = CFG_DYN_NONE,
|
||||||
CFG_DYN_ENT_CLIENT = CFG_DYN_NONE,
|
CFG_DYN_ENT_CLIENT = CFG_DYN_NONE,
|
||||||
|
|
|
@ -1927,6 +1927,7 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) {
|
||||||
int32_t sz = taosArrayGetSize(array);
|
int32_t sz = taosArrayGetSize(array);
|
||||||
cJSON *configs = cJSON_GetObjectItem(pRoot, "configs");
|
cJSON *configs = cJSON_GetObjectItem(pRoot, "configs");
|
||||||
if (configs == NULL) {
|
if (configs == NULL) {
|
||||||
|
uError("failed to get configs from json, since %s", cJSON_GetErrorPtr());
|
||||||
cJSON_Delete(pRoot);
|
cJSON_Delete(pRoot);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
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;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1978,6 +1978,7 @@ int32_t readCfgFile(const char *path, bool isGlobal) {
|
||||||
array = taosGetLocalCfg(tsCfg);
|
array = taosGetLocalCfg(tsCfg);
|
||||||
snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP);
|
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;
|
int64_t fileSize = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
@ -1985,27 +1986,33 @@ int32_t readCfgFile(const char *path, bool isGlobal) {
|
||||||
if (terrno != ENOENT) {
|
if (terrno != ENOENT) {
|
||||||
uError("failed to stat file:%s , since %s", filename, tstrerror(code));
|
uError("failed to stat file:%s , since %s", filename, tstrerror(code));
|
||||||
code = terrno;
|
code = terrno;
|
||||||
|
goto _exit;
|
||||||
}
|
}
|
||||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
|
||||||
}
|
}
|
||||||
TdFilePtr pFile = taosOpenFile(filename, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(filename, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
|
uError("failed to open file:%s , since %s", filename, tstrerror(code));
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
goto _exit;
|
||||||
}
|
}
|
||||||
buf = (char *)taosMemoryMalloc(fileSize + 1);
|
buf = (char *)taosMemoryMalloc(fileSize + 1);
|
||||||
if (taosReadFile(pFile, buf, fileSize) != fileSize) {
|
if (taosReadFile(pFile, buf, fileSize) != fileSize) {
|
||||||
uError("failed to read file:%s , config since %s", filename, tstrerror(code));
|
uError("failed to read file:%s , config since %s", filename, tstrerror(code));
|
||||||
(void)taosCloseFile(&pFile);
|
code = terrno;
|
||||||
taosMemoryFree(buf);
|
goto _exit;
|
||||||
TAOS_RETURN(terrno);
|
|
||||||
}
|
}
|
||||||
char *serialized = NULL;
|
|
||||||
code = cfgDeserialize(array, buf, isGlobal);
|
code = cfgDeserialize(array, buf, isGlobal);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
uError("failed to deserialize config from %s since %s", filename, tstrerror(code));
|
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);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2015,6 +2022,7 @@ int32_t tryLoadCfgFromDataDir(SConfig *pCfg) {
|
||||||
TAOS_CHECK_GET_CFG_ITEM(tsCfg, pItem, "forceReadConfig");
|
TAOS_CHECK_GET_CFG_ITEM(tsCfg, pItem, "forceReadConfig");
|
||||||
tsForceReadConfig = pItem->i32;
|
tsForceReadConfig = pItem->i32;
|
||||||
if (!tsForceReadConfig) {
|
if (!tsForceReadConfig) {
|
||||||
|
uInfo("load config from tsDataDir:%s", tsDataDir);
|
||||||
code = readCfgFile(tsDataDir, false);
|
code = readCfgFile(tsDataDir, false);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
uError("failed to read local config from %s since %s", tsDataDir, tstrerror(code));
|
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) {
|
int32_t globalConfigSerialize(int32_t version, SArray *array, char **serialized) {
|
||||||
char buf[30];
|
char buf[30];
|
||||||
cJSON *json = cJSON_CreateObject();
|
cJSON *json = cJSON_CreateObject();
|
||||||
if (json == NULL) {
|
if (json == NULL) goto _exit;
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
json = cJSON_AddNumberToObject(json, "version", version);
|
||||||
}
|
if (json == NULL) goto _exit;
|
||||||
cJSON_AddNumberToObject(json, "version", version);
|
|
||||||
int sz = taosArrayGetSize(array);
|
int sz = taosArrayGetSize(array);
|
||||||
|
|
||||||
cJSON *cField = cJSON_CreateObject();
|
cJSON *cField = cJSON_CreateObject();
|
||||||
if (cField == NULL) {
|
if (cField == NULL) goto _exit;
|
||||||
cJSON_Delete(json);
|
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// cjson only support int32_t or double
|
// cjson only support int32_t or double
|
||||||
// string are used to prohibit the loss of precision
|
// 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:
|
case CFG_DTYPE_NONE:
|
||||||
break;
|
break;
|
||||||
case CFG_DTYPE_BOOL:
|
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;
|
break;
|
||||||
case CFG_DTYPE_INT32:
|
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;
|
break;
|
||||||
case CFG_DTYPE_INT64:
|
case CFG_DTYPE_INT64:
|
||||||
(void)sprintf(buf, "%" PRId64, item->i64);
|
(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;
|
break;
|
||||||
case CFG_DTYPE_FLOAT:
|
case CFG_DTYPE_FLOAT:
|
||||||
case CFG_DTYPE_DOUBLE:
|
case CFG_DTYPE_DOUBLE:
|
||||||
(void)sprintf(buf, "%f", item->fval);
|
(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;
|
break;
|
||||||
case CFG_DTYPE_STRING:
|
case CFG_DTYPE_STRING:
|
||||||
case CFG_DTYPE_DIR:
|
case CFG_DTYPE_DIR:
|
||||||
case CFG_DTYPE_LOCALE:
|
case CFG_DTYPE_LOCALE:
|
||||||
case CFG_DTYPE_CHARSET:
|
case CFG_DTYPE_CHARSET:
|
||||||
case CFG_DTYPE_TIMEZONE:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(json, "configs", cField);
|
if (!cJSON_AddItemToObject(json, "configs", cField)) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
*serialized = cJSON_Print(json);
|
*serialized = cJSON_Print(json);
|
||||||
|
_exit:
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("failed to serialize global config since %s", tstrerror(terrno));
|
||||||
|
}
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
return TSDB_CODE_SUCCESS;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t localConfigSerialize(SArray *array, char **serialized) {
|
int32_t localConfigSerialize(SArray *array, char **serialized) {
|
||||||
char buf[30];
|
char buf[30];
|
||||||
cJSON *json = cJSON_CreateObject();
|
cJSON *json = cJSON_CreateObject();
|
||||||
if (json == NULL) {
|
if (json == NULL) goto _exit;
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sz = taosArrayGetSize(array);
|
int sz = taosArrayGetSize(array);
|
||||||
|
|
||||||
cJSON *cField = cJSON_CreateObject();
|
cJSON *cField = cJSON_CreateObject();
|
||||||
if (array == NULL) {
|
if (cField == NULL) goto _exit;
|
||||||
cJSON_Delete(json);
|
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
|
||||||
}
|
|
||||||
// cjson only support int32_t or double
|
// cjson only support int32_t or double
|
||||||
// string are used to prohibit the loss of precision
|
// string are used to prohibit the loss of precision
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < sz; i++) {
|
||||||
|
@ -2769,40 +2779,48 @@ int32_t localConfigSerialize(SArray *array, char **serialized) {
|
||||||
case CFG_DTYPE_NONE:
|
case CFG_DTYPE_NONE:
|
||||||
break;
|
break;
|
||||||
case CFG_DTYPE_BOOL:
|
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;
|
break;
|
||||||
case CFG_DTYPE_INT32:
|
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;
|
break;
|
||||||
case CFG_DTYPE_INT64:
|
case CFG_DTYPE_INT64:
|
||||||
(void)sprintf(buf, "%" PRId64, item->i64);
|
(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;
|
break;
|
||||||
case CFG_DTYPE_FLOAT:
|
case CFG_DTYPE_FLOAT:
|
||||||
case CFG_DTYPE_DOUBLE:
|
case CFG_DTYPE_DOUBLE:
|
||||||
(void)sprintf(buf, "%f", item->fval);
|
(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;
|
break;
|
||||||
case CFG_DTYPE_STRING:
|
case CFG_DTYPE_STRING:
|
||||||
case CFG_DTYPE_DIR:
|
case CFG_DTYPE_DIR:
|
||||||
case CFG_DTYPE_LOCALE:
|
case CFG_DTYPE_LOCALE:
|
||||||
case CFG_DTYPE_CHARSET:
|
case CFG_DTYPE_CHARSET:
|
||||||
case CFG_DTYPE_TIMEZONE:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(json, "configs", cField);
|
cJSON_AddItemToObject(json, "configs", cField);
|
||||||
*serialized = cJSON_Print(json);
|
*serialized = cJSON_Print(json);
|
||||||
|
_exit:
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("failed to serialize local config since %s", tstrerror(terrno));
|
||||||
|
}
|
||||||
cJSON_Delete(json);
|
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) {
|
int32_t taosPersistGlobalConfig(SArray *array, const char *path, int32_t version) {
|
||||||
// TODO: just tmp ,refactor later
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char filepath[CONFIG_FILE_LEN] = {0};
|
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(filepath, sizeof(filepath), "%s%sconfig", path, TD_DIRSEP);
|
||||||
snprintf(filename, sizeof(filename), "%s%sconfig%sglobal.json", path, TD_DIRSEP, 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
|
TAOS_CHECK_GOTO(taosMkDir(filepath), &lino, _exit);
|
||||||
if (taosMkDir(filepath) != 0) {
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
uError("failed to create dir:%s since %s", filepath, tstrerror(code));
|
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
TdFilePtr pConfigFile =
|
TdFilePtr pConfigFile =
|
||||||
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);
|
||||||
|
@ -2826,19 +2839,21 @@ int32_t taosPersistGlobalConfig(SArray *array, const char *path, int32_t version
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
char *serialized = NULL;
|
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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
uError("failed to serialize local config since %s", tstrerror(code));
|
uError("failed to persist global config at line:%d, since %s", lino, tstrerror(code));
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
taosWriteFile(pConfigFile, serialized, strlen(serialized));
|
|
||||||
(void)taosCloseFile(&pConfigFile);
|
(void)taosCloseFile(&pConfigFile);
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosPersistLocalConfig(const char *path) {
|
int32_t taosPersistLocalConfig(const char *path) {
|
||||||
// TODO: just tmp ,refactor later
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char filepath[CONFIG_FILE_LEN] = {0};
|
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);
|
snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
// TODO(beryl) need to check if the file is existed
|
// TODO(beryl) need to check if the file is existed
|
||||||
if (taosMkDir(filepath) != 0) {
|
TAOS_CHECK_GOTO(taosMkDir(filepath), &lino, _exit);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
uError("failed to create dir:%s since %s", filepath, tstrerror(code));
|
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
TdFilePtr pConfigFile =
|
TdFilePtr pConfigFile =
|
||||||
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);
|
||||||
|
@ -2861,15 +2872,18 @@ int32_t taosPersistLocalConfig(const char *path) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *serialized = NULL;
|
char *serialized = NULL;
|
||||||
code = localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized);
|
TAOS_CHECK_GOTO(localConfigSerialize(taosGetLocalCfg(tsCfg), &serialized), &lino, _exit);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
TAOS_CHECK_GOTO(taosWriteFile(pConfigFile, serialized, strlen(serialized)), &lino, _exit);
|
||||||
uError("failed to serialize local config since %s", tstrerror(code));
|
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
|
||||||
taosWriteFile(pConfigFile, serialized, strlen(serialized));
|
|
||||||
(void)taosCloseFile(&pConfigFile);
|
(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) {
|
int32_t tSerializeSConfigArray(SEncoder *pEncoder, SArray *array) {
|
||||||
|
|
|
@ -290,8 +290,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
|
||||||
|
|
||||||
if (pRsp->code != 0) {
|
if (pRsp->code != 0) {
|
||||||
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 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,
|
dGInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId);
|
||||||
pMgmt->statusSeq);
|
|
||||||
pMgmt->pData->dropped = 1;
|
pMgmt->pData->dropped = 1;
|
||||||
if (dmWriteEps(pMgmt->pData) != 0) {
|
if (dmWriteEps(pMgmt->pData) != 0) {
|
||||||
dError("failed to write dnode file");
|
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.
|
// Try to use cfg file in current dnode.
|
||||||
if (configRsp.forceReadConfig) {
|
if (configRsp.forceReadConfig) {
|
||||||
if (configRsp.isConifgVerified) {
|
if (configRsp.isConifgVerified) {
|
||||||
|
uInfo("force read config and check config verified");
|
||||||
code = taosPersistGlobalConfig(taosGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver);
|
code = taosPersistGlobalConfig(taosGetGlobalCfg(tsCfg), pMgmt->path, configRsp.cver);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
dError("failed to persist global config since %s", tstrerror(code));
|
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.
|
// Try to use cfg from mnode sdb.
|
||||||
if (!configRsp.isVersionVerified) {
|
if (!configRsp.isVersionVerified) {
|
||||||
|
uInfo("config version not verified, update config");
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
|
code = taosPersistGlobalConfig(configRsp.array, pMgmt->path, configRsp.cver);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
|
||||||
obj = sdbGetRowObj(pRow);
|
obj = sdbGetRowObj(pRow);
|
||||||
if (obj == NULL) goto _OVER;
|
if (obj == NULL) goto _OVER;
|
||||||
int32_t dataPos = 0;
|
int32_t dataPos = 0;
|
||||||
// TODO(beryl):free it.
|
|
||||||
SDB_GET_BINARY(pRaw, dataPos, obj->name, CFG_NAME_MAX_LEN, _OVER)
|
SDB_GET_BINARY(pRaw, dataPos, obj->name, CFG_NAME_MAX_LEN, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, (int32_t *)&obj->dtype, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, (int32_t *)&obj->dtype, _OVER)
|
||||||
switch (obj->dtype) {
|
switch (obj->dtype) {
|
||||||
|
@ -161,6 +161,8 @@ SSdbRow *mndCfgActionDecode(SSdbRaw *pRaw) {
|
||||||
SDB_GET_INT32(pRaw, dataPos, &len, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &len, _OVER)
|
||||||
char *buf = taosMemoryMalloc(len + 1);
|
char *buf = taosMemoryMalloc(len + 1);
|
||||||
SDB_GET_BINARY(pRaw, dataPos, buf, len, _OVER)
|
SDB_GET_BINARY(pRaw, dataPos, buf, len, _OVER)
|
||||||
|
obj->fval = atof(buf);
|
||||||
|
taosMemoryFree(buf);
|
||||||
break;
|
break;
|
||||||
case CFG_DTYPE_STRING:
|
case CFG_DTYPE_STRING:
|
||||||
case CFG_DTYPE_DIR:
|
case CFG_DTYPE_DIR:
|
||||||
|
@ -180,6 +182,7 @@ _OVER:
|
||||||
if (terrno != 0) {
|
if (terrno != 0) {
|
||||||
mError("cfg failed to decode from raw:%p since %s", pRaw, terrstr());
|
mError("cfg failed to decode from raw:%p since %s", pRaw, terrstr());
|
||||||
taosMemoryFreeClear(pRow);
|
taosMemoryFreeClear(pRow);
|
||||||
|
taosMemoryFreeClear(obj->str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +226,6 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
|
||||||
configRsp.array = diffArray;
|
configRsp.array = diffArray;
|
||||||
} else {
|
} else {
|
||||||
configRsp.isConifgVerified = 1;
|
configRsp.isConifgVerified = 1;
|
||||||
taosArrayDestroy(diffArray);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configRsp.array = taosGetGlobalCfg(tsCfg);
|
configRsp.array = taosGetGlobalCfg(tsCfg);
|
||||||
|
@ -235,17 +237,21 @@ static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t contLen = tSerializeSConfigRsp(NULL, 0, &configRsp);
|
int32_t contLen = tSerializeSConfigRsp(NULL, 0, &configRsp);
|
||||||
|
if (contLen < 0) {
|
||||||
|
code = contLen;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
void *pHead = rpcMallocCont(contLen);
|
void *pHead = rpcMallocCont(contLen);
|
||||||
contLen = tSerializeSConfigRsp(pHead, contLen, &configRsp);
|
contLen = tSerializeSConfigRsp(pHead, contLen, &configRsp);
|
||||||
taosArrayDestroy(diffArray);
|
|
||||||
if (contLen < 0) {
|
if (contLen < 0) {
|
||||||
code = contLen;
|
code = contLen;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
pReq->info.rspLen = contLen;
|
pReq->info.rspLen = contLen;
|
||||||
pReq->info.rsp = pHead;
|
pReq->info.rsp = pHead;
|
||||||
_OVER:
|
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
taosArrayDestroy(diffArray);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -254,6 +260,7 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
|
||||||
int code = -1;
|
int code = -1;
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
|
|
||||||
|
mInfo("init write cfg to sdb");
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-write-config");
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-write-config");
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
mError("failed to init write cfg in create trans, since %s", terrstr());
|
mError("failed to init write cfg in create trans, since %s", terrstr());
|
||||||
|
@ -264,6 +271,7 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
|
||||||
SConfigObj *obj = mndInitConfigVersion();
|
SConfigObj *obj = mndInitConfigVersion();
|
||||||
if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) {
|
if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) {
|
||||||
mError("failed to init mnd config version, since %s", terrstr());
|
mError("failed to init mnd config version, since %s", terrstr());
|
||||||
|
goto _OVER;
|
||||||
}
|
}
|
||||||
sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
|
sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
|
||||||
|
|
||||||
|
@ -275,7 +283,6 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
taosMemoryFree(obj);
|
taosMemoryFree(obj);
|
||||||
}
|
}
|
||||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) goto _OVER;
|
|
||||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -540,20 +547,19 @@ _err:
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(beryl):add more log.
|
|
||||||
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue) {
|
static int32_t mndConfigUpdateTrans(SMnode *pMnode, const char *name, char *pValue) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
int32_t lino = -1;
|
int32_t lino = -1;
|
||||||
SConfigObj *pVersion = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
|
SConfigObj *pVersion = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
|
||||||
if (pVersion == NULL) {
|
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;
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
pVersion->i32 = ++tsmmConfigVersion;
|
pVersion->i32 = ++tsmmConfigVersion;
|
||||||
SConfigObj *pObj = sdbAcquire(pMnode->pSdb, SDB_CFG, name);
|
SConfigObj *pObj = sdbAcquire(pMnode->pSdb, SDB_CFG, name);
|
||||||
if (pObj == NULL) {
|
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;
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue