diff --git a/vclusterops/cluster_op.go b/vclusterops/cluster_op.go index 8caf0f3..dd8eca9 100644 --- a/vclusterops/cluster_op.go +++ b/vclusterops/cluster_op.go @@ -444,11 +444,11 @@ func (op *opBase) isSkipExecute() bool { // hasQuorum checks if we have enough working primary nodes to maintain data integrity // quorumCount = (1/2 * number of primary nodes) + 1 func (op *opBase) hasQuorum(hostCount, primaryNodeCount uint) bool { - quorumCount := (primaryNodeCount + 1) / 2 + quorumCount := primaryNodeCount/2 + 1 if hostCount < quorumCount { op.logger.PrintError("[%s] Quorum check failed: "+ "number of hosts with latest catalog (%d) is not "+ - "greater than or equal to 1/2 of number of the primary nodes (%d)\n", + "greater than 1/2 of number of the primary nodes (%d)\n", op.name, hostCount, primaryNodeCount) return false } diff --git a/vclusterops/cluster_op_test.go b/vclusterops/cluster_op_test.go index 7a6272d..4caeeff 100644 --- a/vclusterops/cluster_op_test.go +++ b/vclusterops/cluster_op_test.go @@ -26,7 +26,7 @@ func TestHasQuorum(t *testing.T) { // positive case 1: hostCount := uint(2) - primaryNodeCount := uint(4) + primaryNodeCount := uint(3) succeed := op.hasQuorum(hostCount, primaryNodeCount) assert.Equal(t, succeed, true) @@ -53,4 +53,10 @@ func TestHasQuorum(t *testing.T) { primaryNodeCount = 5 succeed = op.hasQuorum(hostCount, primaryNodeCount) assert.Equal(t, succeed, false) + + // negative case 3: + hostCount = 2 + primaryNodeCount = 4 + succeed = op.hasQuorum(hostCount, primaryNodeCount) + assert.Equal(t, succeed, false) }