From cf0d3ddde3f3ea052d84f1b78a4cfa11ac0b5f85 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 17 May 2023 20:27:12 +0800 Subject: [PATCH 01/15] 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; } From 5098d440687fea2a96dcb286e6841e0ec40821e4 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 12:59:44 +0800 Subject: [PATCH 02/15] feat: support update active code in sdb --- source/dnode/mnode/impl/src/mndDnode.c | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 3034b3b30a..0042206bc5 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -227,6 +227,14 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) { static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew) { mTrace("dnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew); pOld->updateTime = pNew->updateTime; +#ifdef TD_ENTERPRISE + if (strncmp(pOld->active, pNew->active, TSDB_ACTIVE_KEY_LEN) != 0) { + strncpy(pOld->active, pNew->active, TSDB_ACTIVE_KEY_LEN); + } + if (strncmp(pOld->connActive, pNew->connActive, TSDB_CONN_ACTIVE_KEY_LEN) != 0) { + strncpy(pOld->connActive, pNew->connActive, TSDB_CONN_ACTIVE_KEY_LEN); + } +#endif return 0; } @@ -636,7 +644,6 @@ _OVER: } static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq) { - int32_t code = -1; int32_t action = -1; SSdbRaw *pRaw = NULL; STrans *pTrans = NULL; @@ -648,11 +655,11 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg } if (action == -1) { - code = TSDB_CODE_INVALID_CFG; + terrno = 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)); + pCfgReq->config, pCfgReq->value, terrstr()); - return code; + return -1; } SSdb *pSdb = pMnode->pSdb; @@ -666,9 +673,11 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg 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; + if (!pTrans) { + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "cfg-dnode"); + if (!pTrans) goto _OVER; + if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER; + } SDnodeObj tmpDnode = *pDnode; if (action == 0) { @@ -690,13 +699,14 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg sdbRelease(pSdb, pDnode); } - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; - code = 0; + if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + + terrno = 0; _OVER: mndTransDrop(pTrans); sdbFreeRaw(pRaw); - return code; + return terrno; } static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { @@ -1042,11 +1052,11 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { 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); + int32_t vlen = strlen(cfgReq.value); + if ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || + (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN -1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))) { + mError("dnode:%d, failed to config activeCode since invalid vlen. conf:%s, val:%s", cfgReq.dnodeId, cfgReq.config, + cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; return -1; } @@ -1054,7 +1064,10 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { strcpy(dcfgReq.config, idx == 10 ? "activeCode" : "cActiveCode"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); - mndConfigDnode(pMnode, pReq, &cfgReq); + if (mndConfigDnode(pMnode, pReq, &cfgReq) != 0) { + mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr()); + return -1; + } #endif } else { bool findOpt = false; From ab06dd04f4da10b45eb34d8f116d337d88b9d161 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 13:01:28 +0800 Subject: [PATCH 03/15] feat: support update active code in sdb --- source/dnode/mnode/impl/src/mndDnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 0042206bc5..bafcd0bdee 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1054,7 +1054,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { } int32_t vlen = strlen(cfgReq.value); if ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || - (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN -1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))) { + (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN -1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1)))) { mError("dnode:%d, failed to config activeCode since invalid vlen. conf:%s, val:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; From 0e891c5c1457cb46e07177149002a0eb3d40b8ab Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 13:30:45 +0800 Subject: [PATCH 04/15] chore: more code --- source/dnode/mnode/impl/src/mndDnode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index bafcd0bdee..cd7cefc2e4 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1053,8 +1053,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { return -1; } int32_t vlen = strlen(cfgReq.value); - if ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || - (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN -1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1)))) { + if (vlen > 0 && ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || + (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))))) { mError("dnode:%d, failed to config activeCode since invalid vlen. conf:%s, val:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; From 1de90208f7418debcd0e708205bd9478b111dfaf Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 18:02:48 +0800 Subject: [PATCH 05/15] test: test case for alter dnode active code --- include/util/tdef.h | 4 +- source/dnode/mnode/impl/src/mndDnode.c | 4 +- .../0-others/information_schema.py | 44 ++++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index 427a49fd4e..925b2ed520 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -267,8 +267,8 @@ typedef enum ELogicConditionType { #define TSDB_DNODE_CONFIG_LEN 128 #define TSDB_DNODE_VALUE_LEN 256 -#define TSDB_ACTIVE_KEY_LEN 109 // history 109:? -#define TSDB_CONN_ACTIVE_KEY_LEN 257 // history 257:? +#define TSDB_ACTIVE_KEY_LEN 109 +#define TSDB_CONN_ACTIVE_KEY_LEN 255 #define TSDB_DEFAULT_PKT_SIZE 65480 // same as RPC_MAX_UDP_SIZE diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index cd7cefc2e4..fa9552e08f 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1055,8 +1055,8 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { int32_t vlen = strlen(cfgReq.value); if (vlen > 0 && ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))))) { - mError("dnode:%d, failed to config activeCode since invalid vlen. conf:%s, val:%s", cfgReq.dnodeId, cfgReq.config, - cfgReq.value); + mError("dnode:%d, failed to config activeCode since invalid vlen:%d. conf:%s, val:%s", cfgReq.dnodeId, vlen, + cfgReq.config, cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; return -1; } diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 3c4a71c3e4..ef631ee8d9 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -162,7 +162,48 @@ class TDTestCase: for t in range (2): tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') tdSql.checkEqual(20470,len(tdSql.queryResult)) - + + def ins_dnodes_check(self): + tdSql.execute('drop database if exists db2') + tdSql.execute('create database if not exists db2 vgroups 1 replica 1') + tdSql.query(f'select * from information_schema.ins_dnodes') + result = tdSql.queryResult + tdSql.checkEqual(result[0][0],1) + tdSql.checkEqual(result[0][8],"") + tdSql.checkEqual(result[0][9],"") + self.str107 = 'Hc7VCc+' + for t in range (10): + self.str107 += 'tP+2soIXpP' + self.str108 = self.str107 + '=' + self.str109 = self.str108 + '+' + self.str254 = self.str108 + self.str108 + '0123456789001234567890012345678901234567' + self.str255 = self.str254 + '=' + self.str510 = self.str255 + self.str255 + tdSql.error('alter dnode 1 "activeCode" "a"') + tdSql.error('alter dnode 1 "activeCode" "' + self.str107 + '"') + tdSql.execute('alter all dnodes "activeCode" "' + self.str108 + '"') + tdSql.error('alter dnode 1 "activeCode" "' + self.str109 + '"') + tdSql.error('alter all dnodes "activeCode" "' + self.str510 + '"') + tdSql.query(f'select * from information_schema.ins_dnodes') + tdSql.checkEqual(tdSql.queryResult[0][8],self.str108) + tdSql.execute('alter dnode 1 "activeCode" ""') + tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') + tdSql.checkEqual(tdSql.queryResult[0][0],"") + tdSql.checkEqual(tdSql.queryResult[0][1],'') + tdSql.error('alter dnode 1 "cActiveCode" "a"') + tdSql.error('alter dnode 1 "cActiveCode" "' + self.str107 + '"') + tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str254 + '"') + tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') + tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') + tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') + tdSql.checkEqual(tdSql.queryResult[0][0],"") + tdSql.checkEqual(tdSql.queryResult[0][1],self.str254) + tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str109 + '"') + tdSql.query(f'show dnodes') + tdSql.checkEqual(tdSql.queryResult[0][0],self.str109) + tdSql.execute('alter all dnodes "activeCode" ""') + tdSql.query(f'select c_active_code from information_schema.ins_dnodes') + tdSql.checkEqual(tdSql.queryResult[0][0],'') def run(self): self.prepare_data() @@ -170,6 +211,7 @@ class TDTestCase: self.ins_columns_check() # self.ins_col_check_4096() self.ins_stable_check() + self.ins_dnodes_check() def stop(self): From e3f194ed9bb3e64d6dbd557bf4258ba302056502 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 19:13:04 +0800 Subject: [PATCH 06/15] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 66 +++++++++++++++----------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index fa9552e08f..23580c17e1 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -44,6 +44,11 @@ static const char *offlineReason[] = { "unknown", }; +enum { + DND_ACTIVE_CODE, + DND_CONN_ACTIVE_CODE, +}; + static int32_t mndCreateDefaultDnode(SMnode *pMnode); static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode); static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw); @@ -643,25 +648,10 @@ _OVER: return code; } -static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq) { - int32_t action = -1; +static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq, int8_t action) { 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) { - terrno = 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, terrstr()); - - return -1; - } - SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; while (1) { @@ -674,18 +664,19 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg } if (!pTrans) { - pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "cfg-dnode"); + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "config-dnode"); if (!pTrans) goto _OVER; if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER; } SDnodeObj tmpDnode = *pDnode; - if (action == 0) { + if (action == DND_ACTIVE_CODE) { strncpy(tmpDnode.active, pCfgReq->value, TSDB_ACTIVE_KEY_LEN); - } else if (action == 1) { + } else if (action == DND_CONN_ACTIVE_CODE) { strncpy(tmpDnode.connActive, pCfgReq->value, TSDB_CONN_ACTIVE_KEY_LEN); } else { - ASSERT(0); + terrno = TSDB_CODE_INVALID_CFG; + goto _OVER; } pRaw = mndDnodeActionEncode(&tmpDnode); @@ -1045,27 +1036,46 @@ 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]) { + } else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0) { + if (' ' != cfgReq.config[10] && 0 != cfgReq.config[10]) { mError("dnode:%d, failed to config activeCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); terrno = TSDB_CODE_INVALID_CFG; return -1; } int32_t vlen = strlen(cfgReq.value); - if (vlen > 0 && ((idx == 10 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || - (idx == 11 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))))) { + if (vlen > 0 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) { mError("dnode:%d, failed to config activeCode since invalid vlen:%d. conf:%s, val:%s", cfgReq.dnodeId, vlen, cfgReq.config, cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; return -1; } - strcpy(dcfgReq.config, idx == 10 ? "activeCode" : "cActiveCode"); + strcpy(dcfgReq.config, "activeCode"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); - if (mndConfigDnode(pMnode, pReq, &cfgReq) != 0) { - mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr()); + if (mndConfigDnode(pMnode, pReq, &cfgReq, DND_ACTIVE_CODE) != 0) { + mError("dnode:%d, failed to config activeCode since %s", cfgReq.dnodeId, terrstr()); + return -1; + } + } else if (strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { + if (' ' != cfgReq.config[11] && 0 != cfgReq.config[11]) { + mError("dnode:%d, failed to config cActiveCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + int32_t vlen = strlen(cfgReq.value); + if (vlen > 0 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))) { + mError("dnode:%d, failed to config cActiveCode since invalid vlen:%d. conf:%s, val:%s", cfgReq.dnodeId, vlen, + cfgReq.config, cfgReq.value); + terrno = TSDB_CODE_INVALID_OPTION; + return -1; + } + + strcpy(dcfgReq.config, "cActiveCode"); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); + + if (mndConfigDnode(pMnode, pReq, &cfgReq, DND_CONN_ACTIVE_CODE) != 0) { + mError("dnode:%d, failed to config cActiveCode since %s", cfgReq.dnodeId, terrstr()); return -1; } #endif From 24f368c71a33c1700ab0a348257983e8790e05f0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 20:22:12 +0800 Subject: [PATCH 07/15] enh: read active code from cfg --- include/common/tglobal.h | 4 ++++ source/common/src/tglobal.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 8509d39793..c16d82d801 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -77,6 +77,10 @@ extern int32_t tsElectInterval; extern int32_t tsHeartbeatInterval; extern int32_t tsHeartbeatTimeout; +// dnode +extern char tsActive[]; +extern char tsConnActive[]; + // vnode extern int64_t tsVndCommitMaxIntervalMs; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index ac90d4773c..57a29d2db9 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -66,6 +66,10 @@ int32_t tsElectInterval = 25 * 1000; int32_t tsHeartbeatInterval = 1000; int32_t tsHeartbeatTimeout = 20 * 1000; +// dnode +char tsActive[TSDB_ACTIVE_KEY_LEN] = {0}; +char tsConnActive[TSDB_CONN_ACTIVE_KEY_LEN] = {0}; + // vnode int64_t tsVndCommitMaxIntervalMs = 600 * 1000; @@ -490,6 +494,9 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt64(pCfg, "mndSdbWriteDelta", tsMndSdbWriteDelta, 20, 10000, 0) != 0) return -1; if (cfgAddInt64(pCfg, "mndLogRetention", tsMndLogRetention, 500, 10000, 0) != 0) return -1; + if (cfgAddString(pCfg, "activeCode", tsActive, 0) != 0) return -1; + if (cfgAddString(pCfg, "cActiveCode", tsConnActive, 0) != 0) return -1; + if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1; if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1; @@ -885,6 +892,9 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64; tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64; + tstrncpy(tsActive, cfgGetItem(pCfg, "activeCode")->str, sizeof(tsActive)); + tstrncpy(tsConnActive, cfgGetItem(pCfg, "cActiveCode")->str, sizeof(tsConnActive)); + tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs)); tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath)); @@ -927,6 +937,10 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; } else if (strcasecmp("assert", name) == 0) { tsAssert = cfgGetItem(pCfg, "assert")->bval; + } else if (strcasecmp("activeCode", name) == 0) { + SConfigItem *pActiveItem = cfgGetItem(pCfg, "activeCode"); + snprintf(tsActive, sizeof(tsActive), "%s", pActiveItem->str); + cfgSetItem(pCfg, "activeCode", tsActive, pActiveItem->stype); } break; } @@ -946,7 +960,12 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; } else if (strcasecmp("crashReporting", name) == 0) { tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval; + } else if (strcasecmp("cActiveCode", name) == 0) { + SConfigItem *pActiveItem = cfgGetItem(pCfg, "cActiveCode"); + snprintf(tsConnActive, sizeof(tsConnActive), "%s", pActiveItem->str); + cfgSetItem(pCfg, "cActiveCode", tsActive, pActiveItem->stype); } + break; } case 'd': { From 5fc17e874d3cef07369408d87d3875e3d700e611 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 18 May 2023 20:24:46 +0800 Subject: [PATCH 08/15] chore: remove unused code --- source/common/src/tglobal.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 57a29d2db9..699b6f6428 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1463,18 +1463,6 @@ 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", From 8eb4367d460b95c237b97476e6d1292c7f9a6ab1 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 06:50:12 +0800 Subject: [PATCH 09/15] fix: range check and test case adjust --- source/libs/parser/src/parUtil.c | 1 + tests/system-test/0-others/information_schema.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 14da6f8aab..5597bd3df8 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -305,6 +305,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { dst[j] = src[k]; j++; } + if (j >= dlen) j = dlen - 1; dst[j] = '\0'; return j; } diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index ef631ee8d9..e502b22773 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -176,8 +176,10 @@ class TDTestCase: self.str107 += 'tP+2soIXpP' self.str108 = self.str107 + '=' self.str109 = self.str108 + '+' - self.str254 = self.str108 + self.str108 + '0123456789001234567890012345678901234567' + self.str254 = self.str108 + self.str108 + '01234567890123456789012345678901234567' self.str255 = self.str254 + '=' + self.str256 = self.str254 + '=(' + self.str257 = self.str254 + '=()' self.str510 = self.str255 + self.str255 tdSql.error('alter dnode 1 "activeCode" "a"') tdSql.error('alter dnode 1 "activeCode" "' + self.str107 + '"') @@ -192,16 +194,17 @@ class TDTestCase: tdSql.checkEqual(tdSql.queryResult[0][1],'') tdSql.error('alter dnode 1 "cActiveCode" "a"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str107 + '"') - tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str254 + '"') + tdSql.error('alter dnode 1 "cActiveCode" "' + self.str256 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') + tdSql.execute('alter all dnodes "cActiveCode" "' + self.str254 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],"") tdSql.checkEqual(tdSql.queryResult[0][1],self.str254) tdSql.execute('alter dnode 1 "cActiveCode" "' + self.str109 + '"') tdSql.query(f'show dnodes') - tdSql.checkEqual(tdSql.queryResult[0][0],self.str109) - tdSql.execute('alter all dnodes "activeCode" ""') + tdSql.checkEqual(tdSql.queryResult[0][9],self.str109) + tdSql.execute('alter all dnodes "cActiveCode" ""') tdSql.query(f'select c_active_code from information_schema.ins_dnodes') tdSql.checkEqual(tdSql.queryResult[0][0],'') From 0fc1eadeedeb236f4bd82efa90323bb7ce82ba2d Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 06:52:07 +0800 Subject: [PATCH 10/15] chore: revert --- include/common/tglobal.h | 4 ---- source/common/src/tglobal.c | 19 ------------------- 2 files changed, 23 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index c16d82d801..8509d39793 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -77,10 +77,6 @@ extern int32_t tsElectInterval; extern int32_t tsHeartbeatInterval; extern int32_t tsHeartbeatTimeout; -// dnode -extern char tsActive[]; -extern char tsConnActive[]; - // vnode extern int64_t tsVndCommitMaxIntervalMs; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 699b6f6428..237a52efe5 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -66,10 +66,6 @@ int32_t tsElectInterval = 25 * 1000; int32_t tsHeartbeatInterval = 1000; int32_t tsHeartbeatTimeout = 20 * 1000; -// dnode -char tsActive[TSDB_ACTIVE_KEY_LEN] = {0}; -char tsConnActive[TSDB_CONN_ACTIVE_KEY_LEN] = {0}; - // vnode int64_t tsVndCommitMaxIntervalMs = 600 * 1000; @@ -494,9 +490,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt64(pCfg, "mndSdbWriteDelta", tsMndSdbWriteDelta, 20, 10000, 0) != 0) return -1; if (cfgAddInt64(pCfg, "mndLogRetention", tsMndLogRetention, 500, 10000, 0) != 0) return -1; - if (cfgAddString(pCfg, "activeCode", tsActive, 0) != 0) return -1; - if (cfgAddString(pCfg, "cActiveCode", tsConnActive, 0) != 0) return -1; - if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1; if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1; @@ -892,9 +885,6 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64; tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64; - tstrncpy(tsActive, cfgGetItem(pCfg, "activeCode")->str, sizeof(tsActive)); - tstrncpy(tsConnActive, cfgGetItem(pCfg, "cActiveCode")->str, sizeof(tsConnActive)); - tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs)); tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath)); @@ -937,10 +927,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; } else if (strcasecmp("assert", name) == 0) { tsAssert = cfgGetItem(pCfg, "assert")->bval; - } else if (strcasecmp("activeCode", name) == 0) { - SConfigItem *pActiveItem = cfgGetItem(pCfg, "activeCode"); - snprintf(tsActive, sizeof(tsActive), "%s", pActiveItem->str); - cfgSetItem(pCfg, "activeCode", tsActive, pActiveItem->stype); } break; } @@ -960,12 +946,7 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; } else if (strcasecmp("crashReporting", name) == 0) { tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval; - } else if (strcasecmp("cActiveCode", name) == 0) { - SConfigItem *pActiveItem = cfgGetItem(pCfg, "cActiveCode"); - snprintf(tsConnActive, sizeof(tsConnActive), "%s", pActiveItem->str); - cfgSetItem(pCfg, "cActiveCode", tsActive, pActiveItem->stype); } - break; } case 'd': { From 573e16a2a7c5e128598c3eb0e4824e6e9a7cdcf6 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 06:54:09 +0800 Subject: [PATCH 11/15] chore: test case --- tests/system-test/0-others/information_schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index e502b22773..8245407ade 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -196,6 +196,8 @@ class TDTestCase: tdSql.error('alter dnode 1 "cActiveCode" "' + self.str107 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str256 + '"') tdSql.error('alter all dnodes "cActiveCode" "' + self.str255 + '"') + tdSql.error('alter all dnodes "cActiveCode" "' + self.str256 + '"') + tdSql.error('alter all dnodes "cActiveCode" "' + self.str257 + '"') tdSql.execute('alter all dnodes "cActiveCode" "' + self.str254 + '"') tdSql.error('alter dnode 1 "cActiveCode" "' + self.str510 + '"') tdSql.query(f'select active_code,c_active_code from information_schema.ins_dnodes') From c770a5c30691f504cf971657802edca008aa3715 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 06:59:28 +0800 Subject: [PATCH 12/15] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 23580c17e1..d9c1247a93 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1057,6 +1057,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { mError("dnode:%d, failed to config activeCode since %s", cfgReq.dnodeId, terrstr()); return -1; } + return 0; } else if (strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { if (' ' != cfgReq.config[11] && 0 != cfgReq.config[11]) { mError("dnode:%d, failed to config cActiveCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); @@ -1078,6 +1079,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { mError("dnode:%d, failed to config cActiveCode since %s", cfgReq.dnodeId, terrstr()); return -1; } + return 0; #endif } else { bool findOpt = false; From de9389585995bb8828011b2e642d3d461e9a3f56 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 09:25:26 +0800 Subject: [PATCH 13/15] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 36 +++++++------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d9c1247a93..587f78f300 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1036,50 +1036,32 @@ 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) { - if (' ' != cfgReq.config[10] && 0 != cfgReq.config[10]) { + } else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0 || strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { + int8_t opt = strncasecmp(cfgReq.config, "a", 1) == 0 ? DND_ACTIVE_CODE : DND_CONN_ACTIVE_CODE; + int8_t index = opt == DND_ACTIVE_CODE ? 10 : 11; + if (' ' != cfgReq.config[index] && 0 != cfgReq.config[index]) { mError("dnode:%d, failed to config activeCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); terrno = TSDB_CODE_INVALID_CFG; return -1; } int32_t vlen = strlen(cfgReq.value); - if (vlen > 0 && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) { + if (vlen > 0 && ((opt == DND_ACTIVE_CODE && vlen != (TSDB_ACTIVE_KEY_LEN - 1)) || + (opt == DND_CONN_ACTIVE_CODE && + (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))))) { mError("dnode:%d, failed to config activeCode since invalid vlen:%d. conf:%s, val:%s", cfgReq.dnodeId, vlen, cfgReq.config, cfgReq.value); terrno = TSDB_CODE_INVALID_OPTION; return -1; } - strcpy(dcfgReq.config, "activeCode"); + strcpy(dcfgReq.config, opt == DND_ACTIVE_CODE ? "activeCode" : "cActiveCode"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); - if (mndConfigDnode(pMnode, pReq, &cfgReq, DND_ACTIVE_CODE) != 0) { + if (mndConfigDnode(pMnode, pReq, &cfgReq, opt) != 0) { mError("dnode:%d, failed to config activeCode since %s", cfgReq.dnodeId, terrstr()); return -1; } return 0; - } else if (strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { - if (' ' != cfgReq.config[11] && 0 != cfgReq.config[11]) { - mError("dnode:%d, failed to config cActiveCode since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); - terrno = TSDB_CODE_INVALID_CFG; - return -1; - } - int32_t vlen = strlen(cfgReq.value); - if (vlen > 0 && (vlen > (TSDB_CONN_ACTIVE_KEY_LEN - 1) || vlen < (TSDB_ACTIVE_KEY_LEN - 1))) { - mError("dnode:%d, failed to config cActiveCode since invalid vlen:%d. conf:%s, val:%s", cfgReq.dnodeId, vlen, - cfgReq.config, cfgReq.value); - terrno = TSDB_CODE_INVALID_OPTION; - return -1; - } - - strcpy(dcfgReq.config, "cActiveCode"); - snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%s", cfgReq.value); - - if (mndConfigDnode(pMnode, pReq, &cfgReq, DND_CONN_ACTIVE_CODE) != 0) { - mError("dnode:%d, failed to config cActiveCode since %s", cfgReq.dnodeId, terrstr()); - return -1; - } - return 0; #endif } else { bool findOpt = false; From 8571e6f6c5bd010e61628767b351e0dd30c2bb24 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 16:06:20 +0800 Subject: [PATCH 14/15] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 29 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index d9c1247a93..e344dca0a0 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -649,18 +649,19 @@ _OVER: } static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq, int8_t action) { - SSdbRaw *pRaw = NULL; - STrans *pTrans = NULL; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + SDnodeObj *pDnode = NULL; + bool cfgAll = pCfgReq->dnodeId == -1; 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; + if (cfgAll) { + pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); + if (pIter == NULL) break; + } else if(!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId)) { + goto _OVER; } if (!pTrans) { @@ -687,7 +688,12 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg 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 (cfgAll) { + sdbRelease(pSdb, pDnode); + pDnode = NULL; + } else { + break; + } } if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; @@ -695,6 +701,11 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg terrno = 0; _OVER: + if (cfgAll) { + sdbRelease(pSdb, pDnode); + } else { + mndReleaseDnode(pMnode, pDnode); + } mndTransDrop(pTrans); sdbFreeRaw(pRaw); return terrno; From 8fd4b27c436186736cf8a9abab786e6b013328e6 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 19 May 2023 16:10:44 +0800 Subject: [PATCH 15/15] chore: code optimization --- source/dnode/mnode/impl/src/mndDnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 029d63cb9d..99ec7970ad 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -660,7 +660,7 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg if (cfgAll) { pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); if (pIter == NULL) break; - } else if(!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId)) { + } else if(!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId))) { goto _OVER; }