diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 2d36a4bef4b1c4e9d820ef5faa4862bcd4c2a3a9..f23ec1548c18ae68c5bbb6b8b6c249a1bf5e1406 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -454,7 +454,7 @@ static int taos_set_config_imp(const char *config){ int size = cJSON_GetArraySize(root); for(int i = 0; i < size; i++){ cJSON *item = cJSON_GetArrayItem(root, i); - if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION)){ + if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){ ret = -2; } } diff --git a/src/client/tests/setConfigTest.cpp b/src/client/tests/setConfigTest.cpp index 63cda16bb557d4584e137926467a644463d745a6..e7c34ed8f161467bf394531aff7fa426210aa21c 100644 --- a/src/client/tests/setConfigTest.cpp +++ b/src/client/tests/setConfigTest.cpp @@ -5,21 +5,35 @@ #include "tglobal.h" #include "tconfig.h" -/* test parse time function */ -TEST(testCase, set_config_test) { +/* test set config function */ +TEST(testCase, set_config_test1) { const char *config = "{\"debugFlag\":\"131\"}"; taos_set_config(config); const char *config2 = "{\"debugFlag\":\"199\"}"; - taos_set_config(config2); // not take effect + taos_set_config(config2); // not take effect - bool readResult = taosReadGlobalCfg(); - ASSERT_TRUE(readResult); // load file config, not take effect + bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect + ASSERT_TRUE(readResult); int32_t checkResult = taosCheckGlobalCfg(); ASSERT_EQ(checkResult, 0); SGlobalCfg *cfg = taosGetConfigOption("debugFlag"); ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION); - int32_t result = *(int32_t*)cfg->ptr; + int32_t result = *(int32_t *)cfg->ptr; ASSERT_EQ(result, 131); } + +TEST(testCase, set_config_test2) { + const char *config = "{\"numOfCommitThreads\":\"10\"}"; + taos_set_config(config); + + bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect + ASSERT_TRUE(readResult); + int32_t checkResult = taosCheckGlobalCfg(); + ASSERT_EQ(checkResult, 0); + + SGlobalCfg *cfg = taosGetConfigOption("numOfCommitThreads"); + int32_t result = *(int32_t*)cfg->ptr; + ASSERT_NE(result, 10); // numOfCommitThreads not type of TSDB_CFG_CTYPE_B_CLIENT +} diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index f73ba9a7aaa2ab2ae669ab17d1bff7e680d5a3b8..e892e7f5249509cf42bd3a1ffdff0ddb50001231 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -89,7 +89,7 @@ void taosDumpGlobalCfg(); void taosInitConfigOption(SGlobalCfg cfg); SGlobalCfg * taosGetConfigOption(const char *option); -bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus); +bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType); #ifdef __cplusplus } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index e7a8f0639b99e22805f69656160966e08e4da7b2..d70375721c629c7e5107fcfa4a60d056fd07aafd 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -294,11 +294,12 @@ SGlobalCfg *taosGetConfigOption(const char *option) { } bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, - int8_t cfgStatus) { + int8_t cfgStatus, int8_t sourceType) { bool ret = false; for (int i = 0; i < tsGlobalConfigNum; ++i) { SGlobalCfg *cfg = tsGlobalConfig + i; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; + if (sourceType != 0 && !(sourceType & TSDB_CFG_CTYPE_B_CLIENT)) continue; if (strcasecmp(cfg->option, option) != 0) continue; switch (cfg->valType) { @@ -479,7 +480,7 @@ bool taosReadGlobalCfg() { if (vlen3 != 0) value3[vlen3] = 0; } - taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE); + taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE, 0); } fclose(fp);