diff --git a/src/mnode/inc/mnodeDnode.h b/src/mnode/inc/mnodeDnode.h index 10f79582d4a492622e1cc425d69aaa95966846d7..941bfca9e61cd2a5dec5942847277c5a9a78913c 100644 --- a/src/mnode/inc/mnodeDnode.h +++ b/src/mnode/inc/mnodeDnode.h @@ -66,6 +66,7 @@ void mnodeCleanupDnodes(); int32_t mnodeGetDnodesNum(); int32_t mnodeGetOnlinDnodesCpuCoreNum(); +int32_t mnodeGetVnodeDnodesNum(); int32_t mnodeGetOnlineDnodesNum(); void mnodeGetOnlineAndTotalDnodesNum(int32_t *onlineNum, int32_t *totalNum); void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 13afd1c29894fea07e5c269eee53b36a386ee442..cc0b18c9b7047a718f6244cbe20ce76789a21a4c 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -339,8 +339,8 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) { return TSDB_CODE_MND_INVALID_DB_OPTION; } - if (pCfg->replications > mnodeGetDnodesNum()) { - mError("no enough dnode to config replica: %d, #dnodes: %d", pCfg->replications, mnodeGetDnodesNum()); + if (pCfg->replications > mnodeGetVnodeDnodesNum()) { + mError("no enough dnode to config replica: %d, #dnodes: %d", pCfg->replications, mnodeGetVnodeDnodesNum()); return TSDB_CODE_MND_INVALID_DB_OPTION; } @@ -1057,7 +1057,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } - if (replications > mnodeGetDnodesNum()) { + if (replications > mnodeGetVnodeDnodesNum()) { mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 58e9f8b749b3df1f58fbd3e67f29dacb379ca0bc..c9ea2f1af4be64d5301e77e44f30d2f7f7833dd3 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -271,6 +271,21 @@ int32_t mnodeGetOnlineDnodesNum() { return onlineDnodes; } +int32_t mnodeGetVnodeDnodesNum() { + SDnodeObj *pDnode = NULL; + void * pIter = NULL; + int32_t numOfDnodes = 0; + + while (1) { + pIter = mnodeGetNextDnode(pIter, &pDnode); + if (pDnode == NULL) break; + if (pDnode->alternativeRole != TAOS_DN_ALTERNATIVE_ROLE_MNODE) numOfDnodes++; + mnodeDecDnodeRef(pDnode); + } + + return numOfDnodes; +} + void mnodeGetOnlineAndTotalDnodesNum(int32_t *onlineNum, int32_t *totalNum) { SDnodeObj *pDnode = NULL; void * pIter = NULL;