From 462d78e5bb540c8c3f17dad4c4d4ef97edc37d9d Mon Sep 17 00:00:00 2001 From: releng Date: Tue, 19 Nov 2024 15:29:23 -0500 Subject: [PATCH] Sync from server repo (adcc1d5dfa9) --- vclusterops/cluster_op.go | 4 ++-- vclusterops/cluster_op_test.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) 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) }