fix(util): fix dead lock.

This commit is contained in:
Haojun Liao 2024-04-27 10:08:15 +08:00
parent 12570d7390
commit 1f6b7bbcff
5 changed files with 32 additions and 21 deletions

View File

@ -107,7 +107,7 @@ int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg);
SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName); SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName);
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype); int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock);
int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer); int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer);
SConfigIter *cfgCreateIter(SConfig *pConf); SConfigIter *cfgCreateIter(SConfig *pConf);

View File

@ -838,7 +838,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
return -1; return -1;
} }
int code = cfgSetItem(pCfg, name, str, CFG_STYPE_TAOS_OPTIONS); int code = cfgSetItem(pCfg, name, str, CFG_STYPE_TAOS_OPTIONS, true);
if (code != 0) { if (code != 0) {
tscError("failed to set cfg:%s to %s since %s", name, str, terrstr()); tscError("failed to set cfg:%s to %s since %s", name, str, terrstr());
} else { } else {

View File

@ -1081,13 +1081,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
SEp firstEp = {0}; SEp firstEp = {0};
taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp);
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype); cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype, true);
SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp"); SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp");
SEp secondEp = {0}; SEp secondEp = {0};
taosGetFqdnPortFromEp(strlen(pSecondpItem->str) == 0 ? defaultFirstEp : pSecondpItem->str, &secondEp); taosGetFqdnPortFromEp(strlen(pSecondpItem->str) == 0 ? defaultFirstEp : pSecondpItem->str, &secondEp);
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port); snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype); cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype, true);
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
@ -1149,9 +1149,10 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
static void taosSetSystemCfg(SConfig *pCfg) { static void taosSetSystemCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
osSetTimezone(pItem->str); osSetTimezone(pItem->str);
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr); uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr);
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype); cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype, true);
const char *locale = cfgGetItem(pCfg, "locale")->str; const char *locale = cfgGetItem(pCfg, "locale")->str;
const char *charset = cfgGetItem(pCfg, "charset")->str; const char *charset = cfgGetItem(pCfg, "charset")->str;
@ -1639,7 +1640,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
SEp firstEp = {0}; SEp firstEp = {0};
taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp);
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype, false);
uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst); uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst);
matched = true; matched = true;
} else if (strcasecmp("firstEp", name) == 0) { } else if (strcasecmp("firstEp", name) == 0) {
@ -1654,7 +1656,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
SEp firstEp = {0}; SEp firstEp = {0};
taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp);
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype, false);
uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst); uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst);
matched = true; matched = true;
} }
@ -1701,7 +1704,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
SEp secondEp = {0}; SEp secondEp = {0};
taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? tsFirst : pItem->str, &secondEp); taosGetFqdnPortFromEp(strlen(pItem->str) == 0 ? tsFirst : pItem->str, &secondEp);
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port); snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
cfgSetItem(pCfg, "secondEp", tsSecond, pItem->stype); cfgSetItem(pCfg, "secondEp", tsSecond, pItem->stype, false);
uInfo("%s set to %s", name, tsSecond); uInfo("%s set to %s", name, tsSecond);
matched = true; matched = true;
} else if (strcasecmp("smlChildTableName", name) == 0) { } else if (strcasecmp("smlChildTableName", name) == 0) {
@ -1732,7 +1735,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
SEp firstEp = {0}; SEp firstEp = {0};
taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp);
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype, false);
uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst); uInfo("localEp set to '%s', tsFirst set to '%s'", tsLocalEp, tsFirst);
matched = true; matched = true;
} else if (strcasecmp("slowLogScope", name) == 0) { } else if (strcasecmp("slowLogScope", name) == 0) {
@ -1749,7 +1753,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
if (strcasecmp("timezone", name) == 0) { if (strcasecmp("timezone", name) == 0) {
osSetTimezone(pItem->str); osSetTimezone(pItem->str);
uInfo("%s set from %s to %s", name, tsTimezoneStr, pItem->str); uInfo("%s set from %s to %s", name, tsTimezoneStr, pItem->str);
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype);
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype, false);
matched = true; matched = true;
} else if (strcasecmp("tempDir", name) == 0) { } else if (strcasecmp("tempDir", name) == 0) {
uInfo("%s set from %s to %s", name, tsTempDir, pItem->str); uInfo("%s set from %s to %s", name, tsTempDir, pItem->str);

View File

@ -914,7 +914,7 @@ static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
return terrno; return terrno;
} }
if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CMD)) { if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CMD, true)) {
return terrno; return terrno;
} }

View File

@ -80,7 +80,7 @@ int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs) {
int32_t size = taosArrayGetSize(pArgs); int32_t size = taosArrayGetSize(pArgs);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SConfigPair *pPair = taosArrayGet(pArgs, i); SConfigPair *pPair = taosArrayGet(pArgs, i);
if (cfgSetItem(pCfg, pPair->name, pPair->value, CFG_STYPE_ARG_LIST) != 0) { if (cfgSetItem(pCfg, pPair->name, pPair->value, CFG_STYPE_ARG_LIST, true) != 0) {
return -1; return -1;
} }
} }
@ -325,10 +325,13 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese
return 0; return 0;
} }
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) { int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock) {
// GRANT_CFG_SET; // GRANT_CFG_SET;
int32_t code = 0; int32_t code = 0;
taosThreadMutexLock(&pCfg->lock);
if (lock) {
taosThreadMutexLock(&pCfg->lock);
}
SConfigItem *pItem = cfgGetItem(pCfg, name); SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) { if (pItem == NULL) {
@ -381,7 +384,10 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
break; break;
} }
taosThreadMutexUnlock(&pCfg->lock); if (lock) {
taosThreadMutexUnlock(&pCfg->lock);
}
return code; return code;
} }
@ -923,7 +929,7 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR); code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
if (strcasecmp(name, "dataDir") == 0) { if (strcasecmp(name, "dataDir") == 0) {
@ -966,7 +972,7 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD); code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
if (strcasecmp(name, "dataDir") == 0) { if (strcasecmp(name, "dataDir") == 0) {
@ -1031,7 +1037,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE); code = cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
if (strcasecmp(name, "dataDir") == 0) { if (strcasecmp(name, "dataDir") == 0) {
@ -1101,7 +1107,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
count++; count++;
} }
code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE); code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
} else { } else {
paGetToken(value + vlen + 1, &value2, &vlen2); paGetToken(value + vlen + 1, &value2, &vlen2);
@ -1111,7 +1117,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE); code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
} }
@ -1286,7 +1292,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL); code = cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL, true);
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break; if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
if (strcasecmp(name, "dataDir") == 0) { if (strcasecmp(name, "dataDir") == 0) {