From 23415cc6d7eb8a828d4128b0bd748261938666a5 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Mon, 9 Dec 2024 19:07:27 +0800 Subject: [PATCH] Fix some review errors. --- include/common/tmsg.h | 2 +- source/common/src/msg/tmsg.c | 2 ++ source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 6 +++- source/dnode/mnode/impl/src/mndConfig.c | 33 ++++----------------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 8d17dd48ab..cec63192d0 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1835,7 +1835,7 @@ typedef struct { int32_t tSerializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq); int32_t tDeserializeSConfigReq(void* buf, int32_t bufLen, SConfigReq* pReq); -void tFreeSStatusReq(SStatusReq* pReq); +void tFreeSConfigReq(SConfigReq* pReq); typedef struct { int32_t dnodeId; diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index 232845f0c7..aa53b4a022 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -1644,6 +1644,8 @@ _exit: return code; } +void tFreeSConfigReq(SConfigReq *pReq) { taosArrayDestroy(pReq->array); } + int32_t tSerializeSConfigRsp(void *buf, int32_t bufLen, SConfigRsp *pRsp) { SEncoder encoder = {0}; int32_t code = 0; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index a856a723c6..3831dd2a2d 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -287,6 +287,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { const STraceId *trace = &pRsp->info.traceId; int32_t code = 0; SConfigRsp configRsp = {0}; + bool needStop = false; if (pRsp->code != 0) { if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) { @@ -315,7 +316,7 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { } else { // log the difference configurations printConfigNotMatch(configRsp.array); - dmStop(); + needStop = true; goto _exit; } } @@ -347,6 +348,9 @@ static void dmProcessConfigRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { _exit: tFreeSConfigRsp(&configRsp); rpcFreeCont(pRsp->pCont); + if (needStop) { + dmStop(); + } } void dmSendConfigReq(SDnodeMgmt *pMgmt) { diff --git a/source/dnode/mnode/impl/src/mndConfig.c b/source/dnode/mnode/impl/src/mndConfig.c index b283c0f221..0a9c51511f 100644 --- a/source/dnode/mnode/impl/src/mndConfig.c +++ b/source/dnode/mnode/impl/src/mndConfig.c @@ -38,7 +38,7 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq); static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp); static int32_t mndProcessConfigReq(SRpcMsg *pReq); static int32_t mndInitWriteCfg(SMnode *pMnode); -static int32_t mndInitReadCfg(SMnode *pMnode); +static int32_t mndMaybeReBuildCfg(SMnode *pMnode); static int32_t initConfigArrayFromSdb(SMnode *pMnode, SArray *array); static void cfgArrayCleanUp(SArray *array); @@ -219,7 +219,7 @@ static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); } -static int32_t mndCfgActionPrepare(SMnode *pMnode) { return mndInitReadCfg(pMnode); } +static int32_t mndCfgActionPrepare(SMnode *pMnode) { return mndMaybeReBuildCfg(pMnode); } static int32_t mndProcessConfigReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; @@ -322,14 +322,9 @@ _OVER: return TSDB_CODE_SUCCESS; } -int32_t mndInitReadCfg(SMnode *pMnode) { - int32_t code = 0; - int32_t sz = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "init-read-config"); - if (pTrans == NULL) { - mError("failed to init read cfg in create trans, since %s", terrstr()); - goto _OVER; - } +int32_t mndMaybeReBuildCfg(SMnode *pMnode) { + int32_t code = 0; + int32_t sz = -1; SConfigObj *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion"); if (obj == NULL) { code = mndInitWriteCfg(pMnode); @@ -339,24 +334,8 @@ int32_t mndInitReadCfg(SMnode *pMnode) { mInfo("failed to acquire mnd config version, try to rebuild it , since %s", terrstr()); goto _OVER; } - - sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg)); - for (int i = 0; i < sz; ++i) { - SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i); - SConfigObj *newObj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name); - if (newObj == NULL) { - mInfo("failed to acquire mnd config:%s, since %s", item->name, terrstr()); - continue; - } - code = cfgUpdateItem(item, newObj); - if (code != 0) { - mError("failed to update mnd config:%s, since %s", item->name, terrstr()); - } - sdbRelease(pMnode->pSdb, newObj); - } _OVER: - mndTransDrop(pTrans); - return TSDB_CODE_SUCCESS; + return code; } int32_t mndSetCreateConfigCommitLogs(STrans *pTrans, SConfigObj *item) {