diff --git a/src/balance/src/balance.c b/src/balance/src/balance.c index 53ed860aa16e7733e656c965feb75f88d0d26311..1c25c04717191bb3d3832935fe316a59913275b7 100644 --- a/src/balance/src/balance.c +++ b/src/balance/src/balance.c @@ -214,8 +214,8 @@ static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) { * desc: remove one vnode from vgroup * all vnodes in vgroup should in ready state, except the balancing one **/ -static void balanceRemoveVnode(SVgObj *pVgroup) { - if (pVgroup->numOfVnodes <= 1) return; +static int32_t balanceRemoveVnode(SVgObj *pVgroup) { + if (pVgroup->numOfVnodes <= 1) return -1; SVnodeGid *pRmVnode = NULL; SVnodeGid *pSelVnode = NULL; @@ -258,9 +258,11 @@ static void balanceRemoveVnode(SVgObj *pVgroup) { if (!balanceCheckVgroupReady(pVgroup, pSelVnode)) { mDebug("vgId:%d, is not ready", pVgroup->vgId); + return -1; } else { mDebug("vgId:%d, is ready, discard dnode:%d", pVgroup->vgId, pSelVnode->dnodeId); balanceDiscardVnode(pVgroup, pSelVnode); + return TSDB_CODE_SUCCESS; } } @@ -407,22 +409,22 @@ static int32_t balanceMonitorVgroups() { int32_t dbReplica = pVgroup->pDb->cfg.replications; int32_t vgReplica = pVgroup->numOfVnodes; + int32_t code; if (vgReplica > dbReplica) { mInfo("vgId:%d, replica:%d numOfVnodes:%d, try remove one vnode", pVgroup->vgId, dbReplica, vgReplica); hasUpdatingVgroup = true; - balanceRemoveVnode(pVgroup); + code = balanceRemoveVnode(pVgroup); } else if (vgReplica < dbReplica) { mInfo("vgId:%d, replica:%d numOfVnodes:%d, try add one vnode", pVgroup->vgId, dbReplica, vgReplica); hasUpdatingVgroup = true; - int32_t code = balanceAddVnode(pVgroup, NULL, NULL); - if (code == TSDB_CODE_SUCCESS) { - mnodeDecVgroupRef(pVgroup); - break; - } + code = balanceAddVnode(pVgroup, NULL, NULL); } mnodeDecVgroupRef(pVgroup); + if (code == TSDB_CODE_SUCCESS) { + break; + } } sdbFreeIter(pIter);