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.
This commit is contained in:
Matt Jaffee 2018-08-08 19:42:30 -05:00
parent 6e99a8757d
commit 1901ffada6
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 5 additions and 11 deletions

View file

@ -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

View file

@ -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()