提交 c74b0282 编写于 作者: wmmhello's avatar wmmhello

[TD-5992] add error msg

上级 bc530df2
...@@ -439,16 +439,26 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { ...@@ -439,16 +439,26 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
} }
#include "cJSON.h" #include "cJSON.h"
static int taos_set_config_imp(const char *config){ typedef struct retMsg{
int ret;
char *msg;
} retMsg;
static retMsg taos_set_config_imp(const char *config){
retMsg ret = {0, "success"};
static bool setConfFlag = false; static bool setConfFlag = false;
if (setConfFlag) { if (setConfFlag) {
tscError("already set config"); tscError("already set config");
return -1; ret.msg = "already set config";
return ret;
} }
cJSON *root = cJSON_Parse(config); cJSON *root = cJSON_Parse(config);
if (root == NULL) { if (root == NULL) {
tscError("failed to set config, invalid json format: %s", config); tscError("failed to set config, invalid json format: %s", config);
return -1; ret.ret = -1;
ret.msg = "invalid json format";
return ret;
} }
int size = cJSON_GetArraySize(root); int size = cJSON_GetArraySize(root);
...@@ -456,13 +466,18 @@ static int taos_set_config_imp(const char *config){ ...@@ -456,13 +466,18 @@ static int taos_set_config_imp(const char *config){
cJSON *item = cJSON_GetArrayItem(root, i); cJSON *item = cJSON_GetArrayItem(root, i);
if (!item) { if (!item) {
tscError("failed to read index:%d", i); tscError("failed to read index:%d", i);
ret.ret = -2;
ret.msg = "part config failed, please see the log";
continue; continue;
} }
taosReadConfigOption(item->string, item->valuestring, NULL, NULL); if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL)){
ret.ret = -2;
ret.msg = "part config failed, please see the log";
}
} }
taosPrintGlobalCfg(); taosPrintGlobalCfg();
setConfFlag = true; setConfFlag = true;
return 0; return ret;
} }
int taos_set_config(const char *config){ int taos_set_config(const char *config){
......
...@@ -89,7 +89,7 @@ void taosDumpGlobalCfg(); ...@@ -89,7 +89,7 @@ void taosDumpGlobalCfg();
void taosInitConfigOption(SGlobalCfg cfg); void taosInitConfigOption(SGlobalCfg cfg);
SGlobalCfg * taosGetConfigOption(const char *option); SGlobalCfg * taosGetConfigOption(const char *option);
void taosReadConfigOption(const char *option, char *value, char *value2, char *value3); bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}}; SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};
int32_t tsGlobalConfigNum = 0; int32_t tsGlobalConfigNum = 0;
#define ATOI_JUDGE if ( !value && strcmp(input_value, "0") != 0) { \
uError("atoi error, input value:%s",input_value); \
return false; \
}
static char *tsGlobalUnit[] = { static char *tsGlobalUnit[] = {
" ", " ",
"(%)", "(%)",
...@@ -44,12 +49,14 @@ char *tsCfgStatusStr[] = { ...@@ -44,12 +49,14 @@ char *tsCfgStatusStr[] = {
"program argument list" "program argument list"
}; };
static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
float value = (float)atof(input_value); float value = (float)atof(input_value);
ATOI_JUDGE
float *option = (float *)cfg->ptr; float *option = (float *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -57,16 +64,20 @@ static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -57,16 +64,20 @@ static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
double value = atof(input_value); double value = atof(input_value);
ATOI_JUDGE
double *option = (double *)cfg->ptr; double *option = (double *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -74,17 +85,21 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -74,17 +85,21 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int32_t *option = (int32_t *)cfg->ptr; int32_t *option = (int32_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = value; *option = value;
...@@ -92,16 +107,20 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { ...@@ -92,16 +107,20 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int16_t *option = (int16_t *)cfg->ptr; int16_t *option = (int16_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (int16_t)value; *option = (int16_t)value;
...@@ -109,16 +128,20 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { ...@@ -109,16 +128,20 @@ static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
uint16_t *option = (uint16_t *)cfg->ptr; uint16_t *option = (uint16_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (uint16_t)value; *option = (uint16_t)value;
...@@ -126,16 +149,20 @@ static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) { ...@@ -126,16 +149,20 @@ static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { static bool taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value); int32_t value = atoi(input_value);
ATOI_JUDGE
int8_t *option = (int8_t *)cfg->ptr; int8_t *option = (int8_t *)cfg->ptr;
if (value < cfg->minValue || value > cfg->maxValue) { if (value < cfg->minValue || value > cfg->maxValue) {
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
*option = (int8_t)value; *option = (int8_t)value;
...@@ -143,8 +170,10 @@ static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) { ...@@ -143,8 +170,10 @@ static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option); tsCfgStatusStr[cfg->cfgStatus], *option);
return false;
} }
} }
return true;
} }
static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
...@@ -191,12 +220,13 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -191,12 +220,13 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
return true; return true;
} }
static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
uint32_t value = taosInetAddr(input_value); uint32_t value = taosInetAddr(input_value);
char * option = (char *)cfg->ptr; char * option = (char *)cfg->ptr;
if (value == INADDR_NONE) { if (value == INADDR_NONE) {
uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s",
cfg->option, input_value, option); cfg->option, input_value, option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
strncpy(option, input_value, cfg->ptrLength); strncpy(option, input_value, cfg->ptrLength);
...@@ -204,16 +234,19 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -204,16 +234,19 @@ static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], option); tsCfgStatusStr[cfg->cfgStatus], option);
return false;
} }
} }
return true;
} }
static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { static bool taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
int length = (int) strlen(input_value); int length = (int) strlen(input_value);
char *option = (char *)cfg->ptr; char *option = (char *)cfg->ptr;
if (length <= 0 || length > cfg->ptrLength) { if (length <= 0 || length > cfg->ptrLength) {
uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s",
cfg->option, input_value, cfg->ptrLength, option); cfg->option, input_value, cfg->ptrLength, option);
return false;
} else { } else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
strncpy(option, input_value, cfg->ptrLength); strncpy(option, input_value, cfg->ptrLength);
...@@ -221,8 +254,10 @@ static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { ...@@ -221,8 +254,10 @@ static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
} else { } else {
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], option); tsCfgStatusStr[cfg->cfgStatus], option);
return false;
} }
} }
return true;
} }
static void taosReadLogOption(char *option, char *value) { static void taosReadLogOption(char *option, char *value) {
...@@ -258,7 +293,7 @@ SGlobalCfg *taosGetConfigOption(const char *option) { ...@@ -258,7 +293,7 @@ SGlobalCfg *taosGetConfigOption(const char *option) {
return NULL; return NULL;
} }
void taosReadConfigOption(const char *option, char *value, char *value2, char *value3) { bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3) {
for (int i = 0; i < tsGlobalConfigNum; ++i) { for (int i = 0; i < tsGlobalConfigNum; ++i) {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue;
...@@ -266,43 +301,35 @@ void taosReadConfigOption(const char *option, char *value, char *value2, char *v ...@@ -266,43 +301,35 @@ void taosReadConfigOption(const char *option, char *value, char *value2, char *v
switch (cfg->valType) { switch (cfg->valType) {
case TAOS_CFG_VTYPE_INT8: case TAOS_CFG_VTYPE_INT8:
taosReadInt8Config(cfg, value); return taosReadInt8Config(cfg, value);
break;
case TAOS_CFG_VTYPE_INT16: case TAOS_CFG_VTYPE_INT16:
taosReadInt16Config(cfg, value); return taosReadInt16Config(cfg, value);
break;
case TAOS_CFG_VTYPE_INT32: case TAOS_CFG_VTYPE_INT32:
taosReadInt32Config(cfg, value); return taosReadInt32Config(cfg, value);
break;
case TAOS_CFG_VTYPE_UINT16: case TAOS_CFG_VTYPE_UINT16:
taosReadUInt16Config(cfg, value); return taosReadUInt16Config(cfg, value);
break;
case TAOS_CFG_VTYPE_FLOAT: case TAOS_CFG_VTYPE_FLOAT:
taosReadFloatConfig(cfg, value); return taosReadFloatConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_DOUBLE: case TAOS_CFG_VTYPE_DOUBLE:
taosReadDoubleConfig(cfg, value); return taosReadDoubleConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_STRING: case TAOS_CFG_VTYPE_STRING:
taosReadStringConfig(cfg, value); return taosReadStringConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_IPSTR: case TAOS_CFG_VTYPE_IPSTR:
taosReadIpStrConfig(cfg, value); return taosReadIpStrConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_DIRECTORY: case TAOS_CFG_VTYPE_DIRECTORY:
taosReadDirectoryConfig(cfg, value); return taosReadDirectoryConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_DATA_DIRCTORY: case TAOS_CFG_VTYPE_DATA_DIRCTORY:
if (taosReadDirectoryConfig(cfg, value)) { if (taosReadDirectoryConfig(cfg, value)) {
taosReadDataDirCfg(value, value2, value3); taosReadDataDirCfg(value, value2, value3);
return true;
} }
break; return false;
default: default:
uError("config option:%s, input value:%s, can't be recognized", option, value); uError("config option:%s, input value:%s, can't be recognized", option, value);
break; return false;
} }
break;
} }
return false;
} }
void taosInitConfigOption(SGlobalCfg cfg) { void taosInitConfigOption(SGlobalCfg cfg) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册