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(); struct SConfig *taosGetCfg();
void taosSetGlobalDebugFlag(int32_t flag); int32_t taosSetGlobalDebugFlag(int32_t flag);
void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal); int32_t taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden); void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
int8_t taosGranted(int8_t type); int8_t taosGranted(int8_t type);
int32_t taosSetSlowLogScope(char *pScope); int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope);
#ifdef __cplusplus #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_OTHERS 0x4
#define SLOW_LOG_TYPE_ALL 0x7 #define SLOW_LOG_TYPE_ALL 0x7
static int32_t taosSetSlowLogScope(char *pScope) { static int32_t taosSetSlowLogScope(char* pScopeStr, int32_t* pScope) {
if (NULL == pScope || 0 == strlen(pScope)) { if (NULL == pScopeStr || 0 == strlen(pScopeStr)) {
return SLOW_LOG_TYPE_QUERY; *pScope = SLOW_LOG_TYPE_QUERY;
TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
int32_t slowScope = 0; int32_t slowScope = 0;
char* scope = NULL; char* scope = NULL;
char *tmp = NULL; char *tmp = NULL;
while((scope = strsep(&pScope, "|")) != NULL){ while((scope = strsep(&pScopeStr, "|")) != NULL){
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
tmp = taosStrdup(scope); tmp = taosStrdup(scope);
strtrim(tmp); strtrim(tmp);
@ -772,73 +773,94 @@ static int32_t taosSetSlowLogScope(char *pScope) {
} }
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
uError("Invalid slowLog scope value:%s", pScope); uError("Invalid slowLog scope value:%s", pScopeStr);
terrno = TSDB_CODE_INVALID_CFG_VALUE; TAOS_RETURN(TSDB_CODE_INVALID_CFG_VALUE);
return -1;
} }
*pScope = slowScope;
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
return slowScope; TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
TEST(TaosSetSlowLogScopeTest, NullPointerInput) { TEST(TaosSetSlowLogScopeTest, NullPointerInput) {
char *pScope = NULL; char* pScopeStr = NULL;
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
} }
TEST(TaosSetSlowLogScopeTest, EmptyStringInput) { TEST(TaosSetSlowLogScopeTest, EmptyStringInput) {
char pScope[1] = ""; char pScopeStr[1] = "";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
} }
TEST(TaosSetSlowLogScopeTest, AllScopeInput) { TEST(TaosSetSlowLogScopeTest, AllScopeInput) {
char pScope[] = "all"; char pScopeStr[] = "all";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_ALL); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_ALL);
} }
TEST(TaosSetSlowLogScopeTest, QueryScopeInput) { TEST(TaosSetSlowLogScopeTest, QueryScopeInput) {
char pScope[] = " query"; char pScopeStr[] = " query";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
} }
TEST(TaosSetSlowLogScopeTest, InsertScopeInput) { TEST(TaosSetSlowLogScopeTest, InsertScopeInput) {
char pScope[] = "insert"; char pScopeStr[] = "insert";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_INSERT); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_INSERT);
} }
TEST(TaosSetSlowLogScopeTest, OthersScopeInput) { TEST(TaosSetSlowLogScopeTest, OthersScopeInput) {
char pScope[] = "others"; char pScopeStr[] = "others";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_OTHERS); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_OTHERS);
} }
TEST(TaosSetSlowLogScopeTest, NoneScopeInput) { TEST(TaosSetSlowLogScopeTest, NoneScopeInput) {
char pScope[] = "none"; char pScopeStr[] = "none";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, SLOW_LOG_TYPE_NULL); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_NULL);
} }
TEST(TaosSetSlowLogScopeTest, InvalidScopeInput) { TEST(TaosSetSlowLogScopeTest, InvalidScopeInput) {
char pScope[] = "invalid"; char pScopeStr[] = "invalid";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, -1); int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, -1);
} }
TEST(TaosSetSlowLogScopeTest, MixedScopesInput) { TEST(TaosSetSlowLogScopeTest, MixedScopesInput) {
char pScope[] = "query|insert|others|none"; char pScopeStr[] = "query|insert|others|none";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS)); 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) { TEST(TaosSetSlowLogScopeTest, MixedScopesInputWithSpaces) {
char pScope[] = "query | insert | others "; char pScopeStr[] = "query | insert | others ";
int32_t result = taosSetSlowLogScope(pScope); int32_t scope = 0;
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS)); 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 #pragma GCC diagnostic pop

View File

@ -74,7 +74,7 @@ static struct {
char encryptKey[ENCRYPT_KEY_LEN + 1]; char encryptKey[ENCRYPT_KEY_LEN + 1];
} global = {0}; } 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 dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert = 1; }
static void dmStopDnode(int signum, void *sigInfo, void *context) { static void dmStopDnode(int signum, void *sigInfo, void *context) {

View File

@ -827,9 +827,7 @@ static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
return terrno; return terrno;
} }
if (taosCfgDynamicOptions(tsCfg, pStmt->config, false)) { TAOS_CHECK_RETURN(taosCfgDynamicOptions(tsCfg, pStmt->config, false));
return terrno;
}
_return: _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) { 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 = TSDB_CODE_SUCCESS;
if (lock) { if (lock) {
taosThreadMutexLock(&pCfg->lock); taosThreadMutexLock(&pCfg->lock);
@ -421,10 +421,12 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
case CFG_DTYPE_STRING: { case CFG_DTYPE_STRING: {
if (strcasecmp(name, "slowLogScope") == 0) { if (strcasecmp(name, "slowLogScope") == 0) {
char *tmp = taosStrdup(pVal); 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); cfgUnLock(pCfg);
taosMemoryFree(tmp); taosMemoryFree(tmp);
TAOS_RETURN(TSDB_CODE_INVALID_CFG); TAOS_RETURN(code);
} }
taosMemoryFree(tmp); taosMemoryFree(tmp);
} }