From ffd5513e10d2ad05934e47e192d99429c6cff0a5 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 23 Feb 2022 13:46:17 +0800 Subject: [PATCH] [TS-1223](mnode): check vnode dnodes num when create db and alter db replica --- src/mnode/inc/mnodeDnode.h | 1 + src/mnode/src/mnodeDb.c | 6 +++--- src/mnode/src/mnodeDnode.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/mnode/inc/mnodeDnode.h b/src/mnode/inc/mnodeDnode.h index 10f79582d4..941bfca9e6 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 13afd1c298..cc0b18c9b7 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 58e9f8b749..c9ea2f1af4 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; -- GitLab