From 480de34a0ed41f002fa7efee95c94ab6a6f4c055 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Jul 2022 14:13:12 +0800 Subject: [PATCH] enh: support alter debugflag in dnode --- source/common/src/tglobal.c | 34 +++++++++++++++ source/dnode/mnode/impl/src/mndDnode.c | 58 ++++++++++++++++++++------ source/libs/sync/src/syncMain.c | 4 +- 3 files changed, 81 insertions(+), 15 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 24bf4e5c2d..974146302c 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1117,10 +1117,44 @@ void taosCfgDynamicOptions(const char *option, const char *value) { if (strncasecmp(option, "debugFlag", 9) == 0) { int32_t flag = atoi(value); taosSetAllDebugFlag(flag); + return; } if (strcasecmp(option, "resetlog") == 0) { taosResetLog(); cfgDumpCfg(tsCfg, 0, false); + return; } + + if (strcasecmp(option, "monitor") == 0) { + int32_t monitor = atoi(value); + uInfo("monitor set from %d to %d", tsEnableMonitor, monitor); + tsEnableMonitor = monitor; + return; + } + + const char *options[] = { + "dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag", "tsdbDebugFlag", + "tqDebugFlag", "fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag", "tmrDebugFlag", + "uDebugFlag", "smaDebugFlag", "rpcDebugFlag", "qDebugFlag", + }; + int32_t *optionVars[] = { + &dDebugFlag, &vDebugFlag, &mDebugFlag, &wDebugFlag, &sDebugFlag, &tsdbDebugFlag, + &tqDebugFlag, &fsDebugFlag, &udfDebugFlag, &smaDebugFlag, &idxDebugFlag, &tmrDebugFlag, + &uDebugFlag, &smaDebugFlag, &rpcDebugFlag, &qDebugFlag, + }; + + int32_t optionSize = tListLen(options); + for (int32_t d = 0; d < optionSize; ++d) { + const char *optName = options[d]; + int32_t optLen = strlen(optName); + if (strncasecmp(option, optName, optLen) != 0) continue; + + int32_t flag = atoi(value); + uInfo("%s set from %d to %d", optName, *optionVars[d], flag); + *optionVars[d] = flag; + return; + } + + uError("failed to cfg dynamic option:%s value:%s", option, value); } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 9ce108b789..3e5d378bb1 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -781,7 +781,13 @@ _OVER: } static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { - SMnode *pMnode = pReq->info.node; + SMnode *pMnode = pReq->info.node; + const char *options[] = { + "debugFlag", "dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag", + "tsdbDebugFlag", "tqDebugFlag", "fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag", + "tmrDebugFlag", "uDebugFlag", "smaDebugFlag", "rpcDebugFlag", "qDebugFlag", + }; + int32_t optionSize = tListLen(options); SMCfgDnodeReq cfgReq = {0}; if (tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) { @@ -802,27 +808,52 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { SEpSet epSet = mndGetDnodeEpset(pDnode); mndReleaseDnode(pMnode, pDnode); + SDCfgDnodeReq dcfgReq = {0}; - if (strncasecmp(cfgReq.config, "debugFlag", 9) == 0) { + if (strcasecmp(cfgReq.config, "resetlog") == 0) { + strcpy(dcfgReq.config, "resetlog"); + } else if (strncasecmp(cfgReq.config, "monitor", 7) == 0) { const char *value = cfgReq.value; int32_t flag = atoi(value); if (flag <= 0) { - flag = atoi(cfgReq.config + 10); + flag = atoi(cfgReq.config + 8); } - if (flag <= 0 || flag > 255) { - mError("dnode:%d, failed to config debugFlag since value:%d", cfgReq.dnodeId, flag); + if (flag < 0 || flag > 2) { + mError("dnode:%d, failed to config monitor since value:%d", cfgReq.dnodeId, flag); terrno = TSDB_CODE_INVALID_CFG; return -1; } - strcpy(dcfgReq.config, "debugFlag"); + strcpy(dcfgReq.config, "monitor"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); - } else if (strcasecmp(cfgReq.config, "resetlog") == 0) { - strcpy(dcfgReq.config, "resetlog"); } else { - terrno = TSDB_CODE_INVALID_CFG; - mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr()); - return -1; + bool findOpt = false; + for (int32_t d = 0; d < optionSize; ++d) { + const char *optName = options[d]; + int32_t optLen = strlen(optName); + if (strncasecmp(cfgReq.config, optName, optLen) != 0) continue; + + const char *value = cfgReq.value; + int32_t flag = atoi(value); + if (flag <= 0) { + flag = atoi(cfgReq.config + optLen + 1); + } + if (flag <= 0 || flag > 255) { + mError("dnode:%d, failed to config %s since value:%d", cfgReq.dnodeId, optName, flag); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + + tstrncpy(dcfgReq.config, optName, optLen + 1); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); + findOpt = true; + } + + if (!findOpt) { + terrno = TSDB_CODE_INVALID_CFG; + mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr()); + return -1; + } } int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, &dcfgReq); @@ -831,13 +862,14 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { if (pBuf == NULL) return -1; tSerializeSDCfgDnodeReq(pBuf, bufLen, &dcfgReq); - mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, pReq->info.ahandle); + mInfo("dnode:%d, send config req to dnode, app:%p config:%s value:%s", cfgReq.dnodeId, pReq->info.ahandle, + dcfgReq.config, dcfgReq.value); SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen}; return tmsgSendReq(&epSet, &rpcMsg); } static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) { - mDebug("config rsp from dnode, app:%p", pRsp->info.ahandle); + mInfo("config rsp from dnode, app:%p", pRsp->info.ahandle); return 0; } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index abc0f53611..bab64b6f11 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -293,7 +293,7 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) { int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { if (pSyncNode->peersNum == 0) { - sError("only one replica, cannot leader transfer"); + sDebug("only one replica, cannot leader transfer"); terrno = TSDB_CODE_SYN_ONE_REPLICA; return -1; } @@ -307,7 +307,7 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { int32_t ret = 0; if (pSyncNode->replicaNum == 1) { - sError("only one replica, cannot leader transfer"); + sDebug("only one replica, cannot leader transfer"); terrno = TSDB_CODE_SYN_ONE_REPLICA; return -1; } -- GitLab