From 1901ffada651b92e4a4859a5899c86130c0020f7 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Wed, 8 Aug 2018 19:42:30 -0500 Subject: [PATCH] make sure cluster gets into DEGRADED state when adding nodes previously, losing a node could cause the cluster to go from NORMAL->DEGRADED, but adding a node would not cause it to go from STARTING->DEGRADED. Cody brought this up in code review. --- cluster.go | 12 +----------- server/server_test.go | 4 ++++ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cluster.go b/cluster.go index 309846e0b..715176b1c 100644 --- a/cluster.go +++ b/cluster.go @@ -456,12 +456,7 @@ func (c *cluster) receiveNodeState(nodeID string, state string) error { c.Topology.mu.Unlock() c.logger.Printf("received state %s (%s)", state, nodeID) - // Set cluster state to NORMAL. - if c.haveTopologyAgreement() && c.allNodesReady() { - return c.unprotectedSetStateAndBroadcast(ClusterStateNormal) - } - - return nil + return c.unprotectedSetStateAndBroadcast(c.determineClusterState()) } // determineClusterState is unprotected. @@ -1573,11 +1568,6 @@ func (c *cluster) considerTopology() error { return fmt.Errorf("coordinator %s is not in topology: %v", c.Node.ID, c.Topology.nodeIDs) } - // If local node is the only thing in .topology, continue. - //if len(c.Topology.NodeIDs) == 1 { - // return nil - //} - // Keep the cluster in state "STARTING" until hearing from all nodes. // Topology contains 2+ hosts. return nil diff --git a/server/server_test.go b/server/server_test.go index 1f00ebeb5..ab860dc1b 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -489,6 +489,10 @@ func TestClusteringNodesReplica2(t *testing.T) { t.Fatalf("restarting node 2: %v", err) } + if cluster[0].API.State() != pilosa.ClusterStateDegraded { + t.Fatalf("expected state to be DEGRADED, but got %s", cluster[0].API.State()) + } + // Create new main with the same config. config = cluster[1].Command.Config // config.Bind = cluster[1].API.Node().URI.HostPort()