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

[TD-5992] make config take effect

上级 2cf005ca
...@@ -445,6 +445,7 @@ static int taos_set_config_imp(const char *config){ ...@@ -445,6 +445,7 @@ static int taos_set_config_imp(const char *config){
tscError("already set config"); tscError("already set config");
return 0; return 0;
} }
taosInitGlobalCfg();
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);
...@@ -460,21 +461,15 @@ static int taos_set_config_imp(const char *config){ ...@@ -460,21 +461,15 @@ static int taos_set_config_imp(const char *config){
ret = -2; ret = -2;
continue; continue;
} }
if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL)){ if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION)){
ret = -2; ret = -2;
} }
} }
taosPrintGlobalCfg();
setConfFlag = true; setConfFlag = true;
return ret; return ret;
} }
int taos_set_config(const char *config){ int taos_set_config(const char *config){
if(taos_init()){
tscError("failed to call taos_init");
return -1;
}
static int32_t lock = 0; static int32_t lock = 0;
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) { for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
......
...@@ -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);
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3); bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -293,7 +293,9 @@ SGlobalCfg *taosGetConfigOption(const char *option) { ...@@ -293,7 +293,9 @@ SGlobalCfg *taosGetConfigOption(const char *option) {
return NULL; return NULL;
} }
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3) { bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3,
int8_t cfgStatus) {
bool ret = false;
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;
...@@ -301,35 +303,48 @@ bool taosReadConfigOption(const char *option, char *value, char *value2, char *v ...@@ -301,35 +303,48 @@ bool 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:
return taosReadInt8Config(cfg, value); ret = taosReadInt8Config(cfg, value);
break;
case TAOS_CFG_VTYPE_INT16: case TAOS_CFG_VTYPE_INT16:
return taosReadInt16Config(cfg, value); ret = taosReadInt16Config(cfg, value);
break;
case TAOS_CFG_VTYPE_INT32: case TAOS_CFG_VTYPE_INT32:
return taosReadInt32Config(cfg, value); ret = taosReadInt32Config(cfg, value);
break;
case TAOS_CFG_VTYPE_UINT16: case TAOS_CFG_VTYPE_UINT16:
return taosReadUInt16Config(cfg, value); ret = taosReadUInt16Config(cfg, value);
break;
case TAOS_CFG_VTYPE_FLOAT: case TAOS_CFG_VTYPE_FLOAT:
return taosReadFloatConfig(cfg, value); ret = taosReadFloatConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_DOUBLE: case TAOS_CFG_VTYPE_DOUBLE:
return taosReadDoubleConfig(cfg, value); ret = taosReadDoubleConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_STRING: case TAOS_CFG_VTYPE_STRING:
return taosReadStringConfig(cfg, value); ret = taosReadStringConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_IPSTR: case TAOS_CFG_VTYPE_IPSTR:
return taosReadIpStrConfig(cfg, value); ret = taosReadIpStrConfig(cfg, value);
break;
case TAOS_CFG_VTYPE_DIRECTORY: case TAOS_CFG_VTYPE_DIRECTORY:
return taosReadDirectoryConfig(cfg, value); ret = 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; ret = true;
} }
return false; ret = false;
break;
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);
return false; ret = false;
} }
if(ret && cfgStatus == TAOS_CFG_CSTATUS_OPTION){
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
} }
return false; }
return ret;
} }
void taosInitConfigOption(SGlobalCfg cfg) { void taosInitConfigOption(SGlobalCfg cfg) {
...@@ -464,7 +479,7 @@ bool taosReadGlobalCfg() { ...@@ -464,7 +479,7 @@ bool taosReadGlobalCfg() {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
taosReadConfigOption(option, value, value2, value3); taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE);
} }
fclose(fp); fclose(fp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册