diff --git a/api.go b/api.go index 741d48894..0f7a39c8a 100644 --- a/api.go +++ b/api.go @@ -112,10 +112,10 @@ func NewAPI(opts ...apiOption) (*API, error) { // validAPIMethods specifies the api methods that are valid for each // cluster state. var validAPIMethods = map[string]map[apiMethod]struct{}{ - ClusterStateStarting: methodsCommon, - ClusterStateNormal: appendMap(methodsCommon, methodsNormal), - ClusterStateDegraded: appendMap(methodsCommon, methodsNormal), - ClusterStateResizing: appendMap(methodsCommon, methodsResizing), + string(ClusterStateStarting): methodsCommon, + string(ClusterStateNormal): appendMap(methodsCommon, methodsNormal), + string(ClusterStateDegraded): appendMap(methodsCommon, methodsNormal), + string(ClusterStateResizing): appendMap(methodsCommon, methodsResizing), } func appendMap(a, b map[apiMethod]struct{}) map[apiMethod]struct{} { diff --git a/cluster.go b/cluster.go index d02a70417..b0bc00548 100644 --- a/cluster.go +++ b/cluster.go @@ -75,8 +75,7 @@ type nodeAction struct { // cluster represents a collection of nodes. type cluster struct { // nolint: maligned - noder topology.Noder - unprotectedNoder topology.Noder + noder topology.Noder id string Node *topology.Node @@ -374,9 +373,9 @@ func (c *cluster) unprotectedSetState(state string) { var doCleanup bool switch state { - case ClusterStateNormal, ClusterStateDegraded: + case string(ClusterStateNormal), string(ClusterStateDegraded): // If state is RESIZING -> [NORMAL, DEGRADED] then run cleanup. - if c.state == ClusterStateResizing { + if c.state == string(ClusterStateResizing) { doCleanup = true } } @@ -384,7 +383,7 @@ func (c *cluster) unprotectedSetState(state string) { c.state = state switch state { - case ClusterStateNormal: + case string(ClusterStateNormal): // Because the cluster state is changing to NORMAL, // we [potentially] need to reset the translation sync. // If, for example, the cluster has changed size and is @@ -424,18 +423,6 @@ func (c *cluster) unprotectedSetState(state string) { } } -func (c *cluster) setMyNodeState(state string) { - c.mu.Lock() - defer c.mu.Unlock() - c.Node.State = state - nodes := c.noder.Nodes() - for i, n := range nodes { - if n.ID == c.Node.ID { - nodes[i].State = state - } - } -} - // receiveNodeState sets node state in Topology in order for the // Coordinator to keep track of, during startup, which nodes have // finished opening their Holder. @@ -471,11 +458,11 @@ func (c *cluster) receiveNodeState(nodeID string, state string) error { // determineClusterState is unprotected. func (c *cluster) determineClusterState() (clusterState string) { - if c.state == ClusterStateResizing { - return ClusterStateResizing + if c.state == string(ClusterStateResizing) { + return string(ClusterStateResizing) } if c.haveTopologyAgreement() && c.allNodesReady() { - return ClusterStateNormal + return string(ClusterStateNormal) } // TODO: // If the cluster is still STARTING, there's no need to put it into @@ -491,9 +478,9 @@ func (c *cluster) determineClusterState() (clusterState string) { // noting that it's a little confusing that a cluster starting up // could possibly go into state DEGRADED. if len(c.Topology.nodeIDs)-len(c.nodeIDs()) < c.ReplicaN && c.allNodesReady() { - return ClusterStateDegraded + return string(ClusterStateDegraded) } - return ClusterStateStarting + return string(ClusterStateStarting) } // unprotectedStatus returns the the cluster's status including what nodes it contains, its ID, and current state. @@ -1106,7 +1093,7 @@ func (c *cluster) containsShards(index string, availableShards *roaring.Bitmap, func (c *cluster) setup() error { // Cluster always comes up in state STARTING until cluster membership is determined. - c.state = ClusterStateStarting + c.state = string(ClusterStateStarting) // Load topology file if it exists. if err := c.loadTopology(); err != nil { @@ -1191,7 +1178,7 @@ func (c *cluster) handleNodeAction(nodeAction nodeAction) error { c.mu.Unlock() if err != nil { c.logger.Printf("generateResizeJob error: err=%s", err) - if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { + if err := c.setStateAndBroadcast(string(ClusterStateNormal)); err != nil { c.logger.Printf("setStateAndBroadcast error: err=%s", err) } return errors.Wrap(err, "setting state") @@ -1295,7 +1282,7 @@ func (c *cluster) listenForJoins() { // Only change state to NORMAL if we have successfully added at least one host. if setNormal { // Put the cluster back to state NORMAL and broadcast. - if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { + if err := c.setStateAndBroadcast(string(ClusterStateNormal)); err != nil { c.logger.Printf("setStateAndBroadcast error: err=%s", err) } } @@ -2157,7 +2144,7 @@ func (c *cluster) nodeJoin(node *topology.Node) error { // If the result of the previous AddNode completed the joining of nodes // in the topology, then change the state to NORMAL. if c.haveTopologyAgreement() { - return c.unprotectedSetStateAndBroadcast(ClusterStateNormal) + return c.unprotectedSetStateAndBroadcast(string(ClusterStateNormal)) } // This lets the remote node to proceed with opening its holder, // instead of waiting in DOWN state because cluster is in STARTING state. @@ -2167,7 +2154,7 @@ func (c *cluster) nodeJoin(node *topology.Node) error { } if c.haveTopologyAgreement() && c.allNodesReady() { - return c.unprotectedSetStateAndBroadcast(ClusterStateNormal) + return c.unprotectedSetStateAndBroadcast(string(ClusterStateNormal)) } // Send the status to the remote node. This lets the remote node // know that it can proceed with opening its Holder. @@ -2193,14 +2180,14 @@ func (c *cluster) nodeJoin(node *topology.Node) error { if err := c.addNode(node); err != nil { return errors.Wrap(err, "adding node") } - return c.unprotectedSetStateAndBroadcast(ClusterStateNormal) + return c.unprotectedSetStateAndBroadcast(string(ClusterStateNormal)) } else if err != nil { return errors.Wrap(err, "checking if holder has data2") } // If the cluster has data, we need to change to RESIZING and // kick off the resizing process. - if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil { + if err := c.unprotectedSetStateAndBroadcast(string(ClusterStateResizing)); err != nil { return errors.Wrap(err, "broadcasting state") } c.joiningLeavingNodes <- nodeAction{node, resizeJobActionAdd} @@ -2229,7 +2216,7 @@ func (c *cluster) nodeLeave(nodeID string) error { c.unprotectedCoordinatorNode().ID) } - if c.state != ClusterStateNormal && c.state != ClusterStateDegraded { + if c.state != string(ClusterStateNormal) && c.state != string(ClusterStateDegraded) { return fmt.Errorf("cluster must be '%s' or '%s' to remove a node but is '%s'", ClusterStateNormal, ClusterStateDegraded, c.state) } @@ -2265,7 +2252,7 @@ func (c *cluster) nodeLeave(nodeID string) error { // If the cluster has data then change state to RESIZING and // kick off the resizing process. - if err := c.unprotectedSetStateAndBroadcast(ClusterStateResizing); err != nil { + if err := c.unprotectedSetStateAndBroadcast(string(ClusterStateResizing)); err != nil { return errors.Wrap(err, "broadcasting state") } c.joiningLeavingNodes <- nodeAction{node: &topology.Node{ID: nodeID}, action: resizeJobActionRemove} diff --git a/cluster_internal_test.go b/cluster_internal_test.go index 09119b864..0b4c95fb9 100644 --- a/cluster_internal_test.go +++ b/cluster_internal_test.go @@ -720,7 +720,7 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that node comes up in state NORMAL. - if state != ClusterStateNormal { + if state != string(ClusterStateNormal) { t.Errorf("expected state: %v, but got: %v", ClusterStateNormal, state) } @@ -766,7 +766,7 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that node comes up in state NORMAL. - if state != ClusterStateNormal { + if state != string(ClusterStateNormal) { t.Errorf("expected state: %v, but got: %v", ClusterStateNormal, state) } @@ -833,9 +833,9 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that nodes comes up in state NORMAL. - if state0 != ClusterStateNormal { + if state0 != string(ClusterStateNormal) { t.Errorf("expected node0 state: %v, but got: %v", ClusterStateNormal, state0) - } else if state1 != ClusterStateNormal { + } else if state1 != string(ClusterStateNormal) { t.Errorf("expected node1 state: %v, but got: %v", ClusterStateNormal, state1) } @@ -882,7 +882,7 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that node is in state STARTING before the other node joins. - if state0 != ClusterStateStarting { + if state0 != string(ClusterStateStarting) { t.Errorf("expected node0 state: %v, but got: %v", ClusterStateStarting, state0) } @@ -896,9 +896,9 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that node comes up in state NORMAL. - if state0 != ClusterStateNormal { + if state0 != string(ClusterStateNormal) { t.Errorf("expected node0 state: %v, but got: %v", ClusterStateNormal, state0) - } else if state1 != ClusterStateNormal { + } else if state1 != string(ClusterStateNormal) { t.Errorf("expected node2 state: %v, but got: %v", ClusterStateNormal, state1) } @@ -972,9 +972,9 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensure that nodes come up in state NORMAL. - if state0 != ClusterStateNormal { + if state0 != string(ClusterStateNormal) { t.Errorf("expected node0 state: %v, but got: %v", ClusterStateNormal, state0) - } else if state1 != ClusterStateNormal { + } else if state1 != string(ClusterStateNormal) { t.Errorf("expected node1 state: %v, but got: %v", ClusterStateNormal, state1) } // INVAR: after node1.State() is normal, the rebalancing should have been done. diff --git a/server.go b/server.go index 7ed582643..cf974bbb7 100644 --- a/server.go +++ b/server.go @@ -777,7 +777,7 @@ func (s *Server) monitorAntiEntropy() { continue } - if state == ClusterStateResizing { + if state == string(ClusterStateResizing) { continue // don't launch anti-entropy during resize. // the cluster sets its state to resizing and *then* sends to // abortAntiEntropyCh before starting to resize @@ -1017,7 +1017,7 @@ func (s *Server) handleRemoteStatus(pb Message) { } // Ignore NodeStatus messages until the cluster is in a Normal state. - if state != ClusterStateNormal { + if state != string(ClusterStateNormal) { return } diff --git a/server/cluster_test.go b/server/cluster_test.go index f4d22b08d..fa3a46961 100644 --- a/server/cluster_test.go +++ b/server/cluster_test.go @@ -122,7 +122,7 @@ func TestClusterResize_EmptyNode(t *testing.T) { defer m0.Close() state0, err := m0.API.State() - if err != nil || state0 != pilosa.ClusterStateNormal { + if err != nil || state0 != string(pilosa.ClusterStateNormal) { t.Fatalf("unexpected cluster state: %s, error: %v", state0, err) } } @@ -134,9 +134,9 @@ func TestClusterResize_EmptyNodes(t *testing.T) { state0, err0 := clus.GetNode(0).API.State() state1, err1 := clus.GetNode(1).API.State() - if err0 != nil || state0 != pilosa.ClusterStateNormal { + if err0 != nil || state0 != string(pilosa.ClusterStateNormal) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || state1 != pilosa.ClusterStateNormal { + } else if err1 != nil || state1 != string(pilosa.ClusterStateNormal) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } } @@ -162,9 +162,9 @@ func TestClusterResize_AddNode(t *testing.T) { state0, err0 := clus.GetNode(0).API.State() state1, err1 := clus.GetNode(1).API.State() - if err0 != nil || !test.CheckClusterState(clus.GetNode(0), pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(clus.GetNode(0), string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(clus.GetNode(1), pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(clus.GetNode(1), string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } }) @@ -207,9 +207,9 @@ func TestClusterResize_AddNode(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error; %v", state1, err1) } }) @@ -268,9 +268,9 @@ func TestClusterResize_AddNode(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -328,9 +328,9 @@ func TestClusterResize_AddNode(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -395,9 +395,9 @@ func TestClusterResize_AddNode(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -453,9 +453,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -520,9 +520,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -589,9 +589,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } @@ -654,9 +654,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) } m0.QueryExpect(t, "i", "", `Row(f=1)`, exp) @@ -717,11 +717,11 @@ func TestCluster_GossipMembership(t *testing.T) { state0, err0 := m0.API.State() state1, err1 := m1.API.State() state2, err2 := m2.API.State() - if err0 != nil || !test.CheckClusterState(m0, pilosa.ClusterStateNormal, 1000) { + if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0) - } else if err1 != nil || !test.CheckClusterState(m1, pilosa.ClusterStateNormal, 1000) { + } else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1) - } else if err2 != nil || !test.CheckClusterState(m2, pilosa.ClusterStateNormal, 1000) { + } else if err2 != nil || !test.CheckClusterState(m2, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected node2 cluster state: %s, error: %v", state2, err2) } diff --git a/server/server.go b/server/server.go index 476641dbc..df6356363 100644 --- a/server/server.go +++ b/server/server.go @@ -563,7 +563,7 @@ func (m *Command) GossipTransport() *gossip.Transport { // Close shuts down the server. func (m *Command) Close() error { select { - case _, _ = <-m.done: + case <-m.done: return nil default: eg := errgroup.Group{} diff --git a/server/server_test.go b/server/server_test.go index 4952f479e..298be37eb 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -359,7 +359,7 @@ func TestConcurrentFieldCreation(t *testing.T) { cluster := test.MustRunCluster(t, 3) defer cluster.Close() - err := cluster.AwaitState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err := cluster.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -686,7 +686,7 @@ func TestClusteringNodesReplica2(t *testing.T) { t.Fatalf("closing 2nd node: %v", err) } - err = cluster.AwaitCoordinatorState(pilosa.ClusterStateStarting, 30*time.Second) + err = cluster.AwaitCoordinatorState(string(pilosa.ClusterStateStarting), 30*time.Second) if err != nil { t.Fatalf("after closing second server: %v", err) } @@ -713,7 +713,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) { cluster.Close() }() - err = cluster.AwaitState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err = cluster.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -725,7 +725,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) { t.Fatalf("closing third node: %v", err) } - err = cluster.AwaitCoordinatorState(pilosa.ClusterStateDegraded, 30*time.Second) + err = cluster.AwaitCoordinatorState(string(pilosa.ClusterStateDegraded), 30*time.Second) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -734,7 +734,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) { t.Fatalf("removing failed node: %v", err) } - err = cluster.AwaitCoordinatorState(pilosa.ClusterStateNormal, 30*time.Second) + err = cluster.AwaitCoordinatorState(string(pilosa.ClusterStateNormal), 30*time.Second) if err != nil { t.Fatalf("removing disabled node: %v", err) } @@ -757,7 +757,7 @@ func TestRemoveConcurrentIndexCreation(t *testing.T) { } defer cluster.Close() - err = cluster.AwaitState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err = cluster.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -772,7 +772,7 @@ func TestRemoveConcurrentIndexCreation(t *testing.T) { t.Fatalf("removing node: %v", err) } - err = cluster.AwaitCoordinatorState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err = cluster.AwaitCoordinatorState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -904,7 +904,7 @@ func TestClusterQueriesAfterRestart(t *testing.T) { defer cluster.Close() cmd1 := cluster.GetNode(1) - err := cluster.AwaitState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err := cluster.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } @@ -972,7 +972,7 @@ func TestClusterQueriesAfterRestart(t *testing.T) { if err1 != nil { t.Fatalf("getting state foor node 1: %v", err) } - for state1 != pilosa.ClusterStateNormal { + for state1 != string(pilosa.ClusterStateNormal) { time.Sleep(time.Millisecond) } @@ -1201,7 +1201,7 @@ func TestClusterCreatedAtRace(t *testing.T) { cluster := test.MustRunCluster(t, 4) defer cluster.Close() - err := cluster.AwaitState(pilosa.ClusterStateNormal, 100*time.Millisecond) + err := cluster.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond) if err != nil { t.Fatalf("starting cluster: %v", err) } diff --git a/test/cluster.go b/test/cluster.go index d4e95a967..b581f3eff 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -438,7 +438,7 @@ func (c *Cluster) Start() error { return err } - return c.AwaitState(pilosa.ClusterStateNormal, 30*time.Second) + return c.AwaitState(string(pilosa.ClusterStateNormal), 30*time.Second) } // Close stops a Cluster diff --git a/test/pilosa_test.go b/test/pilosa_test.go index 686c071e2..b2ef10758 100644 --- a/test/pilosa_test.go +++ b/test/pilosa_test.go @@ -77,7 +77,7 @@ func TestNewCluster(t *testing.T) { t.Fatalf("wrong number of nodes in status: %s", bytes) } - if body.State != pilosa.ClusterStateNormal { + if body.State != string(pilosa.ClusterStateNormal) { t.Fatalf("cluster state should be %s but is %s", pilosa.ClusterStateNormal, body.State) } } diff --git a/translator_test.go b/translator_test.go index 1e2448656..a12b4ca25 100644 --- a/translator_test.go +++ b/translator_test.go @@ -515,12 +515,12 @@ func TestTranslation_Replication(t *testing.T) { exp := `{"results":[{"attrs":{},"columns":[],"keys":["x1","x2"]}]}` coordState, err := coord.API.State() - if err != nil || !test.CheckClusterState(coord, pilosa.ClusterStateNormal, 1000) { + if err != nil || !test.CheckClusterState(coord, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected coord cluster state: %s, got: %s, err: %v", pilosa.ClusterStateNormal, coordState, err) } otherState, err := other.API.State() - if err != nil || !test.CheckClusterState(other, pilosa.ClusterStateNormal, 1000) { + if err != nil || !test.CheckClusterState(other, string(pilosa.ClusterStateNormal), 1000) { t.Fatalf("unexpected other cluster state: %s, got: %s, err: %v", pilosa.ClusterStateNormal, otherState, err) } @@ -533,7 +533,7 @@ func TestTranslation_Replication(t *testing.T) { } coordState, err = coord.API.State() - if err != nil || !test.CheckClusterState(coord, pilosa.ClusterStateDegraded, 1000) { + if err != nil || !test.CheckClusterState(coord, string(pilosa.ClusterStateDegraded), 1000) { t.Fatalf("unexpected coord cluster state: %s, got: %s", pilosa.ClusterStateDegraded, coordState) } diff --git a/utils_internal_test.go b/utils_internal_test.go index 534cbbc79..e0c366eaa 100644 --- a/utils_internal_test.go +++ b/utils_internal_test.go @@ -85,7 +85,7 @@ func NewTestCluster(tb testing.TB, n int) *cluster { c.Node = cNodes[0] c.Coordinator = cNodes[0].ID - c.SetState(ClusterStateNormal) + c.SetState(string(ClusterStateNormal)) return c } @@ -239,7 +239,7 @@ func (t *ClusterCluster) addNode() error { } // Wait for the AddNode job to finish. - if state != ClusterStateNormal { + if state != string(ClusterStateNormal) { t.resizeDone = make(chan struct{}) t.mu.Lock() t.resizing = true @@ -391,7 +391,7 @@ func (b bcast) SendSync(m Message) error { } } b.t.mu.RLock() - if obj.State == ClusterStateNormal && b.t.resizing { + if obj.State == string(ClusterStateNormal) && b.t.resizing { close(b.t.resizeDone) } b.t.mu.RUnlock() @@ -435,7 +435,7 @@ func (b bcast) SendTo(to *topology.Node, m Message) error { } } b.t.mu.RLock() - if obj.State == ClusterStateNormal && b.t.resizing { + if obj.State == string(ClusterStateNormal) && b.t.resizing { close(b.t.resizeDone) } b.t.mu.RUnlock() @@ -568,7 +568,7 @@ func NewTestClusterWithReplication(tb testing.TB, nNodes, nReplicas, partitionN c.Node = cNodes[0] c.Coordinator = cNodes[0].ID - c.SetState(ClusterStateNormal) + c.SetState(string(ClusterStateNormal)) if err := c.holder.Open(); err != nil { panic(err)