From 42e7be57a4cc03ad71a3351f410d5b87cb1e6041 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 8 Oct 2020 14:52:02 +0800 Subject: [PATCH] TD-1652 --- src/dnode/src/dnodeMgmt.c | 20 ++++++++++++++++++-- src/dnode/src/dnodeModule.c | 23 ++++++++++------------- src/inc/dnode.h | 2 +- src/mnode/src/mnodeSdb.c | 7 +------ tests/script/unique/mnode/mgmt23.sim | 2 +- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 8f87a45fb7..8f2b687dc4 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -468,8 +468,24 @@ void dnodeUpdateMnodeEpSetForPeer(SRpcEpSet *pEpSet) { if (!mnodeIsRunning()) { if (strcmp(pEpSet->fqdn[i], tsLocalFqdn) == 0 && pEpSet->port[i] == tsServerPort) { - dInfo("mnode index:%d %s:%u should work as master", i, pEpSet->fqdn[i], pEpSet->port[i]); - sdbUpdateSync(); + dInfo("mnode index:%d %s:%u should work as mnode", i, pEpSet->fqdn[i], pEpSet->port[i]); + bool find = false; + for (int i = 0; i < tsDMnodeInfos.nodeNum; ++i) { + if (tsDMnodeInfos.nodeInfos[i].nodeId == dnodeGetDnodeId()) { + dInfo("localEp found in mnode infos"); + find = true; + break; + } + } + + if (!find) { + dInfo("localEp not found in mnode infos, will set into mnode infos"); + tstrncpy(tsDMnodeInfos.nodeInfos[tsDMnodeInfos.nodeNum].nodeEp, tsLocalEp, TSDB_EP_LEN); + tsDMnodeInfos.nodeInfos[tsDMnodeInfos.nodeNum].nodeId = dnodeGetDnodeId(); + tsDMnodeInfos.nodeNum++; + } + + dnodeStartMnode(); } } } diff --git a/src/dnode/src/dnodeModule.c b/src/dnode/src/dnodeModule.c index 18a293d415..ba7cdf2664 100644 --- a/src/dnode/src/dnodeModule.c +++ b/src/dnode/src/dnodeModule.c @@ -146,19 +146,16 @@ void dnodeProcessModuleStatus(uint32_t moduleStatus) { } } -bool dnodeCheckMnodeStarting() { - if (tsModuleStatus & (1 << TSDB_MOD_MNODE)) return false; - - SDMMnodeInfos *mnodes = dnodeGetMnodeInfos(); - for (int32_t i = 0; i < mnodes->nodeNum; ++i) { - SDMMnodeInfo *node = &mnodes->nodeInfos[i]; - if (node->nodeId == dnodeGetDnodeId()) { - uint32_t moduleStatus = tsModuleStatus | (1 << TSDB_MOD_MNODE); - dInfo("start mnode module, module status:%d, new status:%d", tsModuleStatus, moduleStatus); - dnodeProcessModuleStatus(moduleStatus); - return true; - } +bool dnodeStartMnode() { + if (tsModuleStatus & (1 << TSDB_MOD_MNODE)) { + dDebug("mnode module is already started, module status:%d", tsModuleStatus); + return false; } - return false; + uint32_t moduleStatus = tsModuleStatus | (1 << TSDB_MOD_MNODE); + dInfo("start mnode module, module status:%d, new status:%d", tsModuleStatus, moduleStatus); + dnodeProcessModuleStatus(moduleStatus); + + sdbUpdateSync(); + return true; } diff --git a/src/inc/dnode.h b/src/inc/dnode.h index fda9c1c1dd..017241c4f8 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -43,7 +43,7 @@ void dnodeGetMnodeEpSetForPeer(void *epSet); void dnodeGetMnodeEpSetForShell(void *epSet); void * dnodeGetMnodeInfos(); int32_t dnodeGetDnodeId(); -bool dnodeCheckMnodeStarting(); +bool dnodeStartMnode(); void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)); void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 4c672eb557..7654536122 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -91,7 +91,6 @@ typedef struct { } SSdbWriteWorkerPool; extern void * tsMnodeTmr; -static void * tsUpdateSyncTmr; static SSdbObject tsSdbObj = {0}; static taos_qset tsSdbWriteQset; static taos_qall tsSdbWriteQall; @@ -298,16 +297,12 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { taosFreeQitem(pOper); } -static void sdbUpdateSyncTmrFp(void *param, void *tmrId) { sdbUpdateSync(); } - void sdbUpdateSync() { if (!mnodeIsRunning()) { mDebug("mnode not start yet, update sync info later"); - if (dnodeCheckMnodeStarting()) { - taosTmrReset(sdbUpdateSyncTmrFp, 1000, NULL, tsMnodeTmr, &tsUpdateSyncTmr); - } return; } + mDebug("update sync info in sdb"); SSyncCfg syncCfg = {0}; diff --git a/tests/script/unique/mnode/mgmt23.sim b/tests/script/unique/mnode/mgmt23.sim index 4851872860..d1820ef8c6 100644 --- a/tests/script/unique/mnode/mgmt23.sim +++ b/tests/script/unique/mnode/mgmt23.sim @@ -65,7 +65,7 @@ endi print ============== step4 sql drop dnode $hostname2 -sleep 16000 +sleep 10000 sql show mnodes $dnode1Role = $data2_1 -- GitLab