From cf0d3ddde3f3ea052d84f1b78a4cfa11ac0b5f85 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 17 May 2023 20:27:12 +0800 Subject: [PATCH] feat: support update active code by SQL --- source/common/src/tglobal.c | 12 ++++ source/dnode/mnode/impl/src/mndDnode.c | 88 +++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 237a52efe5..ac90d4773c 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1444,6 +1444,18 @@ void taosCfgDynamicOptions(const char *option, const char *value) { return; } + if (strcasecmp(option, "activeCode") == 0) { + // TODO + printf("%s:%d set activeCode: %s\n", __func__, __LINE__, value); + return; + } + + if (strcasecmp(option, "cActiveCode") == 0) { + // TODO + printf("%s:%d set cActiveCode: %s\n", __func__, __LINE__, value); + 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 d4cbcaaacd..3034b3b30a 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -635,6 +635,70 @@ _OVER: return code; } +static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq) { + int32_t code = -1; + int32_t action = -1; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + + if (strncasecmp(pCfgReq->config, "activeCode", 10) == 0) { + action = 0; + } else if (strncasecmp(pCfgReq->config, "cActiveCode", 11) == 0) { + action = 1; + } + + if (action == -1) { + code = TSDB_CODE_INVALID_CFG; + mWarn("dnode:%d, config dnode, app:%p config:%s value:%s, failed since %s", pCfgReq->dnodeId, pReq->info.ahandle, + pCfgReq->config, pCfgReq->value, tstrerror(code)); + + return code; + } + + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + while (1) { + SDnodeObj *pDnode = NULL; + pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); + if (pIter == NULL) break; + + if (pDnode->id != pCfgReq->dnodeId && pCfgReq->dnodeId != -1) { + continue; + } + + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "cfg-dnode"); + if (pTrans == NULL) goto _OVER; + if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER; + + SDnodeObj tmpDnode = *pDnode; + if (action == 0) { + strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); + } else if (action == 1) { + strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); + } else { + ASSERT(0); + } + + pRaw = mndDnodeActionEncode(&tmpDnode); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; + + mInfo("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, + pCfgReq->config, pCfgReq->value); + + sdbRelease(pSdb, pDnode); + } + + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = 0; + +_OVER: + mndTransDrop(pTrans); + sdbFreeRaw(pRaw); + return code; +} + static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -970,6 +1034,28 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { strcpy(dcfgReq.config, "monitor"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); +#ifdef TD_ENTERPRISE + } else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0 || strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { + int32_t idx = (strncasecmp(cfgReq.config, "a", 1) == 0) ? 10 : 11; + if (' ' != cfgReq.config[idx] && 0 != cfgReq.config[idx]) { + mError("dnode:%d, failed to config activeCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + + if ((idx == 10 && strlen(cfgReq.value) > TSDB_ACTIVE_KEY_LEN) || + (idx == 11 && strlen(cfgReq.value) > TSDB_CONN_ACTIVE_KEY_LEN)) { + mError("dnode:%d, failed to config activeCode since value out of range. conf:%s, val:%s", cfgReq.dnodeId, + cfgReq.config, cfgReq.value); + terrno = TSDB_CODE_INVALID_OPTION; + return -1; + } + + strcpy(dcfgReq.config, idx == 10 ? "activeCode" : "cActiveCode"); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); + + mndConfigDnode(pMnode, pReq, &cfgReq); +#endif } else { bool findOpt = false; for (int32_t d = 0; d < optionSize; ++d) { @@ -1023,7 +1109,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { tSerializeSDCfgDnodeReq(pBuf, bufLen, &dcfgReq); 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, .info = pReq->info}; + SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen}; tmsgSendReq(&epSet, &rpcMsg); code = 0; } -- GitLab