feat: (errcode) tglobal.c

This commit is contained in:
Shungang Li 2024-07-24 16:36:57 +08:00
parent df3e2b78cd
commit 5b8a67e59e
6 changed files with 575 additions and 531 deletions

View File

@ -272,11 +272,11 @@ int32_t taosCfgDynamicOptions(SConfig *pCfg, const char *name, bool forServer);
struct SConfig *taosGetCfg();
void taosSetGlobalDebugFlag(int32_t flag);
void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
int32_t taosSetGlobalDebugFlag(int32_t flag);
int32_t taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
int8_t taosGranted(int8_t type);
int32_t taosSetSlowLogScope(char *pScope);
int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope);
#ifdef __cplusplus
}

File diff suppressed because it is too large Load Diff

View File

@ -733,16 +733,17 @@ TEST(AlreadyAddGroupIdTest, GroupIdAddedWithDifferentLength) {
#define SLOW_LOG_TYPE_OTHERS 0x4
#define SLOW_LOG_TYPE_ALL 0x7
static int32_t taosSetSlowLogScope(char *pScope) {
if (NULL == pScope || 0 == strlen(pScope)) {
return SLOW_LOG_TYPE_QUERY;
static int32_t taosSetSlowLogScope(char* pScopeStr, int32_t* pScope) {
if (NULL == pScopeStr || 0 == strlen(pScopeStr)) {
*pScope = SLOW_LOG_TYPE_QUERY;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
int32_t slowScope = 0;
char* scope = NULL;
char *tmp = NULL;
while((scope = strsep(&pScope, "|")) != NULL){
while((scope = strsep(&pScopeStr, "|")) != NULL){
taosMemoryFreeClear(tmp);
tmp = taosStrdup(scope);
strtrim(tmp);
@ -772,73 +773,94 @@ static int32_t taosSetSlowLogScope(char *pScope) {
}
taosMemoryFreeClear(tmp);
uError("Invalid slowLog scope value:%s", pScope);
terrno = TSDB_CODE_INVALID_CFG_VALUE;
return -1;
uError("Invalid slowLog scope value:%s", pScopeStr);
TAOS_RETURN(TSDB_CODE_INVALID_CFG_VALUE);
}
*pScope = slowScope;
taosMemoryFreeClear(tmp);
return slowScope;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
TEST(TaosSetSlowLogScopeTest, NullPointerInput) {
char *pScope = NULL;
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char* pScopeStr = NULL;
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, EmptyStringInput) {
char pScope[1] = "";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char pScopeStr[1] = "";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, AllScopeInput) {
char pScope[] = "all";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_ALL);
char pScopeStr[] = "all";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_ALL);
}
TEST(TaosSetSlowLogScopeTest, QueryScopeInput) {
char pScope[] = " query";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char pScopeStr[] = " query";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, InsertScopeInput) {
char pScope[] = "insert";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_INSERT);
char pScopeStr[] = "insert";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_INSERT);
}
TEST(TaosSetSlowLogScopeTest, OthersScopeInput) {
char pScope[] = "others";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_OTHERS);
char pScopeStr[] = "others";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_OTHERS);
}
TEST(TaosSetSlowLogScopeTest, NoneScopeInput) {
char pScope[] = "none";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_NULL);
char pScopeStr[] = "none";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_NULL);
}
TEST(TaosSetSlowLogScopeTest, InvalidScopeInput) {
char pScope[] = "invalid";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, -1);
char pScopeStr[] = "invalid";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, -1);
}
TEST(TaosSetSlowLogScopeTest, MixedScopesInput) {
char pScope[] = "query|insert|others|none";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
char pScopeStr[] = "query|insert|others|none";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
}
TEST(TaosSetSlowLogScopeTest, MixedScopesInputWithSpaces) {
char pScope[] = "query | insert | others ";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
char pScopeStr[] = "query | insert | others ";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
}
#pragma GCC diagnostic pop

View File

@ -74,7 +74,7 @@ static struct {
char encryptKey[ENCRYPT_KEY_LEN + 1];
} global = {0};
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { taosSetGlobalDebugFlag(143); }
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { (void)taosSetGlobalDebugFlag(143); }
static void dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert = 1; }
static void dmStopDnode(int signum, void *sigInfo, void *context) {

View File

@ -827,9 +827,7 @@ static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
return terrno;
}
if (taosCfgDynamicOptions(tsCfg, pStmt->config, false)) {
return terrno;
}
TAOS_CHECK_RETURN(taosCfgDynamicOptions(tsCfg, pStmt->config, false));
_return:

View File

@ -317,7 +317,7 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock) {
// GRANT_CFG_SET;
int32_t code = 0;
int32_t code = TSDB_CODE_SUCCESS;
if (lock) {
taosThreadMutexLock(&pCfg->lock);
@ -421,10 +421,12 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
case CFG_DTYPE_STRING: {
if (strcasecmp(name, "slowLogScope") == 0) {
char *tmp = taosStrdup(pVal);
if (taosSetSlowLogScope(tmp) < 0) {
int32_t scope = 0;
int32_t code = taosSetSlowLogScope(tmp, &scope);
if (TSDB_CODE_SUCCESS != code) {
cfgUnLock(pCfg);
taosMemoryFree(tmp);
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
TAOS_RETURN(code);
}
taosMemoryFree(tmp);
}