diff --git a/src/balance/src/bnMain.c b/src/balance/src/bnMain.c index f022fff6d83049dbf75ce73f161983f28322304b..9997d44ca55954b120ae4849d4f68be4d23419f7 100644 --- a/src/balance/src/bnMain.c +++ b/src/balance/src/bnMain.c @@ -637,6 +637,19 @@ int32_t bnDropDnode(SDnodeObj *pDnode) { return TSDB_CODE_SUCCESS; } +int32_t bnDnodeCanCreateMnode(struct SDnodeObj *pDnode) { + if (pDnode == NULL) + return 0; + + if (pDnode->isMgmt || pDnode->alternativeRole == TAOS_DN_ALTERNATIVE_ROLE_VNODE + || pDnode->status == TAOS_DN_STATUS_DROPPING + || pDnode->status == TAOS_DN_STATUS_OFFLINE) { + return 0; + } else { + return 1; + } +} + static void bnMonitorDnodeModule() { int32_t numOfMnodes = mnodeGetMnodesNum(); if (numOfMnodes >= tsNumOfMnodes) return; @@ -645,13 +658,7 @@ static void bnMonitorDnodeModule() { SDnodeObj *pDnode = tsBnDnodes.list[i]; if (pDnode == NULL) break; - if (pDnode->isMgmt || pDnode->status == TAOS_DN_STATUS_DROPPING || pDnode->status == TAOS_DN_STATUS_OFFLINE) { - continue; - } - - if (pDnode->alternativeRole == TAOS_DN_ALTERNATIVE_ROLE_VNODE) { - continue; - } + if (!bnDnodeCanCreateMnode(pDnode)) continue; mLInfo("dnode:%d, numOfMnodes:%d expect:%d, create mnode in this dnode", pDnode->dnodeId, numOfMnodes, tsNumOfMnodes); mnodeCreateMnode(pDnode->dnodeId, pDnode->dnodeEp, true); diff --git a/src/inc/tbn.h b/src/inc/tbn.h index b9f4e3c608a1ae3df3a4ea0dca32c7bf9d5820a9..b35f90eb153d02b4bb09f6f96a8dd09835626c97 100644 --- a/src/inc/tbn.h +++ b/src/inc/tbn.h @@ -31,6 +31,7 @@ void bnReset(); int32_t bnAllocVnodes(struct SVgObj *pVgroup); int32_t bnAlterDnode(struct SDnodeObj *pDnode, int32_t vnodeId, int32_t dnodeId); int32_t bnDropDnode(struct SDnodeObj *pDnode); +int32_t bnDnodeCanCreateMnode(struct SDnodeObj *pDnode); #ifdef __cplusplus } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index ce21af49c2fcea873577d56db01cd2d4363471b1..2325122830251d7a7267ecbaaa35acd0511816e7 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "tgrant.h" -#include "tbn.h" #include "tglobal.h" #include "tconfig.h" #include "tutil.h" @@ -632,7 +631,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { } int32_t numOfMnodes = mnodeGetMnodesNum(); - if (numOfMnodes < tsNumOfMnodes && numOfMnodes < mnodeGetOnlineDnodesNum() && !pDnode->isMgmt) { + if (numOfMnodes < tsNumOfMnodes && numOfMnodes < mnodeGetOnlineDnodesNum() + && bnDnodeCanCreateMnode(pDnode)) { bnNotify(); }