From a7507d26b00f97b0ac6fa057bd294041fd99eaa6 Mon Sep 17 00:00:00 2001 From: Shungang Li Date: Sat, 7 Oct 2023 18:20:19 +0800 Subject: [PATCH] feat: alter local/dnode asynclog --- source/common/src/tglobal.c | 7 +++++++ source/dnode/mnode/impl/src/mndDnode.c | 15 +++++++++++++++ source/libs/command/inc/commandInt.h | 3 ++- source/libs/command/src/command.c | 12 +++++++++++- tools/shell/src/shellAuto.c | 12 +++++++++++- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index ef35400cc0..9922b8b82a 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1670,6 +1670,13 @@ void taosCfgDynamicOptions(const char *option, const char *value) { return; } + if (strcasecmp(option, "asynclog") == 0) { + int32_t newAsynclog = atoi(value); + uInfo("asynclog set from %d to %d", tsAsyncLog, newAsynclog); + tsAsyncLog = newAsynclog; + return; + } + const char *options[] = { "dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag", "tsdbDebugFlag", "tqDebugFlag", "fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag", "tdbDebugFlag", "tmrDebugFlag", "uDebugFlag", diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 4871d88a57..96d5a6a964 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1174,6 +1174,21 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { strcpy(dcfgReq.config, "ttlbatchdropnum"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); + } else if (strncasecmp(cfgReq.config, "asynclog", 8) == 0) { + int32_t optLen = strlen("asynclog"); + int32_t flag = -1; + int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag); + if (code < 0) return code; + + if (flag < 0 || flag > 1) { + mError("dnode:%d, failed to config asynclog since value:%d. Valid range: [0, 1]", cfgReq.dnodeId, flag); + terrno = TSDB_CODE_INVALID_CFG; + tFreeSMCfgDnodeReq(&cfgReq); + return -1; + } + + strcpy(dcfgReq.config, "asynclog"); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); #ifdef TD_ENTERPRISE } else if (strncasecmp(cfgReq.config, "supportvnodes", 13) == 0) { int32_t optLen = strlen("supportvnodes"); diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 996891c77a..7d3e25b3a9 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -111,6 +111,7 @@ extern "C" { #define COMMAND_CATALOG_DEBUG "catalogDebug" #define COMMAND_ENABLE_MEM_DEBUG "enableMemDebug" #define COMMAND_DISABLE_MEM_DEBUG "disableMemDebug" +#define COMMAND_ASYNCLOG "asynclog" typedef struct SExplainGroup { int32_t nodeNum; @@ -167,7 +168,7 @@ typedef struct SExplainCtx { } \ tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__); \ } while (0) - + #define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__) #define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 8b868ffde4..691f29501c 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -747,6 +747,16 @@ static int32_t execAlterCmd(char* cmd, char* value, bool* processed) { return code; } qInfo("memory dbg disabled"); + } else if (0 == strcasecmp(cmd, COMMAND_ASYNCLOG)) { + int newAsyncLogValue = (strlen(value) == 0) ? 1 : atoi(value); + if (newAsyncLogValue != 0 && newAsyncLogValue != 1) { + code = TSDB_CODE_INVALID_CFG_VALUE; + qError("failed to alter asynclog, error:%s", tstrerror(code)); + goto _return; + } + + code = TSDB_CODE_SUCCESS; + tsAsyncLog = newAsyncLogValue; } else { goto _return; } @@ -946,7 +956,7 @@ int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieve return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp); case QUERY_NODE_SHOW_DB_ALIVE_STMT: case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT: - return execShowAliveStatus(pConnId, (SShowAliveStmt*)pStmt, pRsp); + return execShowAliveStatus(pConnId, (SShowAliveStmt*)pStmt, pRsp); default: break; } diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 41cdb0f928..60d6388faa 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -66,6 +66,8 @@ SWords shellCommands[] = { {"alter dnode \"debugFlag\" \"141\";", 0, 0, NULL}, {"alter dnode \"monitor\" \"0\";", 0, 0, NULL}, {"alter dnode \"monitor\" \"1\";", 0, 0, NULL}, + {"alter dnode \"asynclog\" \"0\";", 0, 0, NULL}, + {"alter dnode \"asynclog\" \"1\";", 0, 0, NULL}, {"alter all dnodes \"resetlog\";", 0, 0, NULL}, {"alter all dnodes \"debugFlag\" \"141\";", 0, 0, NULL}, {"alter all dnodes \"monitor\" \"0\";", 0, 0, NULL}, @@ -77,6 +79,8 @@ SWords shellCommands[] = { {"alter local \"uDebugFlag\" \"143\";", 0, 0, NULL}, {"alter local \"rpcDebugFlag\" \"143\";", 0, 0, NULL}, {"alter local \"tmrDebugFlag\" \"143\";", 0, 0, NULL}, + {"alter local \"asynclog\" \"0\";", 0, 0, NULL}, + {"alter local \"asynclog\" \"1\";", 0, 0, NULL}, {"alter topic", 0, 0, NULL}, {"alter user ;", 0, 0, NULL}, // 20 @@ -184,7 +188,7 @@ SWords shellCommands[] = { {"show grants;", 0, 0, NULL}, #ifdef TD_ENTERPRISE {"split vgroup ", 0, 0, NULL}, -#endif +#endif {"insert into values(", 0, 0, NULL}, {"insert into using tags(", 0, 0, NULL}, {"insert into using values(", 0, 0, NULL}, @@ -391,13 +395,19 @@ void showHelp() { alter dnode 'monitor' '0';\n\ alter dnode 'monitor' \"1\";\n\ alter dnode \"debugflag\" \"143\";\n\ + alter dnode 'asynclog' '0';\n\ + alter dnode 'asynclog' \"1\";\n\ alter all dnodes \"monitor\" \"0\";\n\ alter all dnodes \"monitor\" \"1\";\n\ alter all dnodes \"resetlog\";\n\ alter all dnodes \"debugFlag\" \n\ + alter all dnodes \"asynclog\" \"0\";\n\ + alter all dnodes \"asynclog\" \"1\";\n\ alter table ;\n\ alter local \"resetlog\";\n\ alter local \"DebugFlag\" \"143\";\n\ + alter local \"asynclog\" \"0\";\n\ + alter local \"asynclog\" \"1\";\n\ alter topic\n\ alter user ...\n\ ----- C ----- \n\