mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Merge pull request #1397 from travisturner/disco-unify-state
Unify state
This commit is contained in:
commit
ecd8e3fa10
11 changed files with 71 additions and 78 deletions
15
api.go
15
api.go
|
|
@ -31,6 +31,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/pql"
|
||||
"github.com/pilosa/pilosa/v2/roaring"
|
||||
"github.com/pilosa/pilosa/v2/stats"
|
||||
|
|
@ -111,11 +112,11 @@ 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{}{
|
||||
string(ClusterStateStarting): methodsCommon,
|
||||
string(ClusterStateNormal): appendMap(methodsCommon, methodsNormal),
|
||||
string(ClusterStateDegraded): appendMap(methodsCommon, methodsDegraded),
|
||||
string(ClusterStateResizing): appendMap(methodsCommon, methodsResizing),
|
||||
var validAPIMethods = map[disco.ClusterState]map[apiMethod]struct{}{
|
||||
disco.ClusterStateStarting: methodsCommon,
|
||||
disco.ClusterStateNormal: appendMap(methodsCommon, methodsNormal),
|
||||
disco.ClusterStateDegraded: appendMap(methodsCommon, methodsDegraded),
|
||||
disco.ClusterStateResizing: appendMap(methodsCommon, methodsResizing),
|
||||
}
|
||||
|
||||
func appendMap(a, b map[apiMethod]struct{}) map[apiMethod]struct{} {
|
||||
|
|
@ -1814,9 +1815,9 @@ func (api *API) ResizeAbort() error {
|
|||
}
|
||||
|
||||
// State returns the cluster state which is usually "NORMAL", but could be
|
||||
// "STARTING", "RESIZING", or potentially others. See cluster.go for more
|
||||
// "STARTING", "RESIZING", or potentially others. See disco.go for more
|
||||
// details.
|
||||
func (api *API) State() (string, error) {
|
||||
func (api *API) State() (disco.ClusterState, error) {
|
||||
if err := api.validate(apiState); err != nil {
|
||||
return "", errors.Wrap(err, "validating api method")
|
||||
}
|
||||
|
|
|
|||
21
cluster.go
21
cluster.go
|
|
@ -33,16 +33,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// ClusterState represents the state returned in the /status endpoint.
|
||||
ClusterStateStarting = disco.ClusterStateStarting
|
||||
ClusterStateDegraded = disco.ClusterStateDegraded // cluster is running but we've lost some # of hosts >0 but < replicaN
|
||||
ClusterStateNormal = disco.ClusterStateNormal
|
||||
ClusterStateResizing = disco.ClusterStateResizing
|
||||
ClusterStateDown = disco.ClusterStateDown
|
||||
|
||||
// nodeStateDown represents the state of a node which is unavailable.
|
||||
nodeStateDown = "DOWN"
|
||||
|
||||
resizeJobActionAdd = "ADD"
|
||||
resizeJobActionRemove = "REMOVE"
|
||||
|
||||
|
|
@ -659,12 +649,8 @@ func (c *cluster) nodeIDs() []string {
|
|||
return topology.Nodes(c.Nodes()).IDs()
|
||||
}
|
||||
|
||||
func (c *cluster) State() (string, error) {
|
||||
state, err := c.stator.ClusterState(context.Background())
|
||||
if err != nil {
|
||||
return string(disco.ClusterStateUnknown), err
|
||||
}
|
||||
return string(state), nil
|
||||
func (c *cluster) State() (disco.ClusterState, error) {
|
||||
return c.stator.ClusterState(context.Background())
|
||||
}
|
||||
|
||||
func (c *cluster) nodeByID(id string) *topology.Node {
|
||||
|
|
@ -732,7 +718,8 @@ func (c *cluster) Nodes() []*topology.Node {
|
|||
|
||||
s, err := c.stator.NodeState(context.Background(), node.ID)
|
||||
if err != nil {
|
||||
node.State = nodeStateDown
|
||||
// TODO should we delete this?
|
||||
node.State = string(disco.NodeStateUnknown)
|
||||
continue
|
||||
}
|
||||
node.State = string(s)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/boltdb"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/http"
|
||||
"github.com/pilosa/pilosa/v2/pql"
|
||||
"github.com/pilosa/pilosa/v2/proto"
|
||||
|
|
@ -3553,7 +3554,7 @@ func TestExecutor_Execute_Existence(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := node0.AwaitState(string(pilosa.ClusterStateNormal), 10*time.Second); err != nil {
|
||||
if err := node0.AwaitState(disco.ClusterStateNormal, 10*time.Second); err != nil {
|
||||
t.Fatalf("restarting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -747,7 +747,7 @@ func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
status := getStatusResponse{
|
||||
State: state,
|
||||
State: string(state),
|
||||
Nodes: h.api.Hosts(r.Context()),
|
||||
LocalID: h.api.Node().ID,
|
||||
ClusterName: h.api.ClusterName(),
|
||||
|
|
|
|||
|
|
@ -562,7 +562,7 @@ func (s *Server) Open() error {
|
|||
ID: s.nodeID,
|
||||
URI: s.uri,
|
||||
GRPCURI: s.grpcURI,
|
||||
State: nodeStateDown,
|
||||
State: string(disco.NodeStateUnknown),
|
||||
IsPrimary: s.IsPrimary(),
|
||||
}
|
||||
|
||||
|
|
@ -730,7 +730,7 @@ func (s *Server) monitorAntiEntropy() {
|
|||
continue
|
||||
}
|
||||
|
||||
if state == string(ClusterStateResizing) {
|
||||
if state == disco.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
|
||||
|
|
@ -966,7 +966,7 @@ func (s *Server) handleRemoteStatus(pb Message) {
|
|||
}
|
||||
|
||||
// Ignore NodeStatus messages until the cluster is in a Normal state.
|
||||
if state != string(ClusterStateNormal) {
|
||||
if state != disco.ClusterStateNormal {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
"github.com/pilosa/pilosa/v2/test"
|
||||
"github.com/pilosa/pilosa/v2/test/port"
|
||||
|
|
@ -121,7 +122,7 @@ func TestClusterResize_EmptyNode(t *testing.T) {
|
|||
defer m0.Close()
|
||||
|
||||
state0, err := m0.API.State()
|
||||
if err != nil || state0 != string(pilosa.ClusterStateNormal) {
|
||||
if err != nil || state0 != disco.ClusterStateNormal {
|
||||
t.Fatalf("unexpected cluster state: %s, error: %v", state0, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -133,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 != string(pilosa.ClusterStateNormal) {
|
||||
if err0 != nil || state0 != disco.ClusterStateNormal {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || state1 != string(pilosa.ClusterStateNormal) {
|
||||
} else if err1 != nil || state1 != disco.ClusterStateNormal {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
}
|
||||
|
|
@ -161,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), string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(clus.GetNode(0), disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(clus.GetNode(1), string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(clus.GetNode(1), disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
})
|
||||
|
|
@ -201,9 +202,9 @@ func TestClusterResize_AddNode(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error; %v", state1, err1)
|
||||
}
|
||||
})
|
||||
|
|
@ -257,9 +258,9 @@ func TestClusterResize_AddNode(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -313,9 +314,9 @@ func TestClusterResize_AddNode(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -376,9 +377,9 @@ func TestClusterResize_AddNode(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -430,9 +431,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -493,9 +494,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -558,9 +559,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
|
||||
|
|
@ -619,9 +620,9 @@ func TestClusterResize_AddNodeConcurrentIndex(t *testing.T) {
|
|||
|
||||
state0, err0 := m0.API.State()
|
||||
state1, err1 := m1.API.State()
|
||||
if err0 != nil || !test.CheckClusterState(m0, string(pilosa.ClusterStateNormal), 1000) {
|
||||
if err0 != nil || !test.CheckClusterState(m0, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node0 cluster state: %s, error: %v", state0, err0)
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, string(pilosa.ClusterStateNormal), 1000) {
|
||||
} else if err1 != nil || !test.CheckClusterState(m1, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected node1 cluster state: %s, error: %v", state1, err1)
|
||||
}
|
||||
m0.QueryExpect(t, "i", "", `Row(f=1)`, exp)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func TestMain_Set_Quick(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := m.AwaitState(string(pilosa.ClusterStateNormal), 10*time.Second); err != nil {
|
||||
if err := m.AwaitState(disco.ClusterStateNormal, 10*time.Second); err != nil {
|
||||
t.Fatalf("restarting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ func TestMain_SetRowAttrs(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := m.AwaitState(string(pilosa.ClusterStateNormal), 10*time.Second); err != nil {
|
||||
if err := m.AwaitState(disco.ClusterStateNormal, 10*time.Second); err != nil {
|
||||
t.Fatalf("restarting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ func TestMain_SetColumnAttrs(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := m.AwaitState(string(pilosa.ClusterStateNormal), 10*time.Second); err != nil {
|
||||
if err := m.AwaitState(disco.ClusterStateNormal, 10*time.Second); err != nil {
|
||||
t.Fatalf("restarting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ func TestConcurrentFieldCreation(t *testing.T) {
|
|||
defer cluster.Close()
|
||||
|
||||
node0 := cluster.GetNode(0)
|
||||
err := node0.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond)
|
||||
err := node0.AwaitState(disco.ClusterStateNormal, 100*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -643,7 +643,7 @@ func TestClusteringNodesReplica1(t *testing.T) {
|
|||
cluster := test.MustRunCluster(t, 3)
|
||||
defer cluster.Close()
|
||||
|
||||
if err := cluster.GetNode(0).AwaitState(string(disco.ClusterStateNormal), 100*time.Millisecond); err != nil {
|
||||
if err := cluster.GetNode(0).AwaitState(disco.ClusterStateNormal, 100*time.Millisecond); err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -651,7 +651,7 @@ func TestClusteringNodesReplica1(t *testing.T) {
|
|||
t.Fatalf("closing third node: %v", err)
|
||||
}
|
||||
|
||||
if err := cluster.GetCoordinator().AwaitState(string(disco.ClusterStateDown), 30*time.Second); err != nil {
|
||||
if err := cluster.GetCoordinator().AwaitState(disco.ClusterStateDown, 30*time.Second); err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -681,7 +681,7 @@ func TestClusteringNodesReplica2(t *testing.T) {
|
|||
t.Fatalf("closing third node: %v", err)
|
||||
}
|
||||
|
||||
err = coord.AwaitState(string(disco.ClusterStateDegraded), 30*time.Second)
|
||||
err = coord.AwaitState(disco.ClusterStateDegraded, 30*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("after closing first server: %v", err)
|
||||
}
|
||||
|
|
@ -699,7 +699,7 @@ func TestClusteringNodesReplica2(t *testing.T) {
|
|||
t.Fatalf("closing 2nd node: %v", err)
|
||||
}
|
||||
|
||||
err = coord.AwaitState(string(pilosa.ClusterStateDown), 30*time.Second)
|
||||
err = coord.AwaitState(disco.ClusterStateDown, 30*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("after closing second server: %v", err)
|
||||
}
|
||||
|
|
@ -730,7 +730,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) {
|
|||
|
||||
coord, others := cluster.GetCoordinator(), cluster.GetNonCoordinators()
|
||||
|
||||
err = coord.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond)
|
||||
err = coord.AwaitState(disco.ClusterStateNormal, 100*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -741,7 +741,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) {
|
|||
t.Fatalf("closing third node: %v", err)
|
||||
}
|
||||
|
||||
err = coord.AwaitState(string(pilosa.ClusterStateDegraded), 30*time.Second)
|
||||
err = coord.AwaitState(disco.ClusterStateDegraded, 30*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -750,7 +750,7 @@ func TestRemoveNodeAfterItDies(t *testing.T) {
|
|||
t.Fatalf("removing failed node: %v", err)
|
||||
}
|
||||
|
||||
err = coord.AwaitState(string(pilosa.ClusterStateNormal), 30*time.Second)
|
||||
err = coord.AwaitState(disco.ClusterStateNormal, 30*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("removing disabled node: %v", err)
|
||||
}
|
||||
|
|
@ -774,7 +774,7 @@ func TestRemoveConcurrentIndexCreation(t *testing.T) {
|
|||
defer cluster.Close()
|
||||
|
||||
node0 := cluster.GetNode(0)
|
||||
err = node0.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond)
|
||||
err = node0.AwaitState(disco.ClusterStateNormal, 100*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -789,7 +789,7 @@ func TestRemoveConcurrentIndexCreation(t *testing.T) {
|
|||
t.Fatalf("removing node: %v", err)
|
||||
}
|
||||
|
||||
err = cluster.GetCoordinator().AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond)
|
||||
err = cluster.GetCoordinator().AwaitState(disco.ClusterStateNormal, 100*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -921,7 +921,7 @@ func TestClusterQueriesAfterRestart(t *testing.T) {
|
|||
defer cluster.Close()
|
||||
cmd1 := cluster.GetNode(1)
|
||||
|
||||
err := cmd1.AwaitState(string(pilosa.ClusterStateNormal), 100*time.Millisecond)
|
||||
err := cmd1.AwaitState(disco.ClusterStateNormal, 100*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
|
|
@ -987,7 +987,7 @@ func TestClusterQueriesAfterRestart(t *testing.T) {
|
|||
if err1 != nil {
|
||||
t.Fatalf("getting state foor node 1: %v", err)
|
||||
}
|
||||
for state1 != string(pilosa.ClusterStateNormal) {
|
||||
for state1 != disco.ClusterStateNormal {
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/api/client"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/proto"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
"github.com/pilosa/pilosa/v2/storage"
|
||||
|
|
@ -420,7 +421,7 @@ func (c *Cluster) Start() error {
|
|||
return err
|
||||
}
|
||||
|
||||
return c.GetNode(0).AwaitState(string(pilosa.ClusterStateNormal), 30*time.Second)
|
||||
return c.GetNode(0).AwaitState(disco.ClusterStateNormal, 30*time.Second)
|
||||
}
|
||||
|
||||
// Close stops a Cluster
|
||||
|
|
@ -473,7 +474,7 @@ func MustNewCluster(tb testing.TB, size int, opts ...[]server.CommandOption) *Cl
|
|||
|
||||
// CheckClusterState polls a given cluster for its state until it
|
||||
// receives a matching state. It polls up to n times before returning.
|
||||
func CheckClusterState(m *Command, state string, n int) bool {
|
||||
func CheckClusterState(m *Command, state disco.ClusterState, n int) bool {
|
||||
for i := 0; i < n; i++ {
|
||||
|
||||
apiState, err := m.API.State()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/encoding/proto"
|
||||
"github.com/pilosa/pilosa/v2/http"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
|
|
@ -388,7 +389,7 @@ func RetryUntil(timeout time.Duration, fn func() error) (err error) {
|
|||
}
|
||||
|
||||
// AwaitState waits for the whole cluster to reach a specified state.
|
||||
func (m *Command) AwaitState(expectedState string, timeout time.Duration) (err error) {
|
||||
func (m *Command) AwaitState(expectedState disco.ClusterState, timeout time.Duration) (err error) {
|
||||
startTime := time.Now()
|
||||
var elapsed time.Duration
|
||||
for elapsed = 0; elapsed <= timeout; elapsed = time.Since(startTime) {
|
||||
|
|
@ -404,7 +405,7 @@ func (m *Command) AwaitState(expectedState string, timeout time.Duration) (err e
|
|||
}
|
||||
|
||||
// exceptionalState returns an error if the node is not in the expected state.
|
||||
func (m *Command) exceptionalState(expectedState string) error {
|
||||
func (m *Command) exceptionalState(expectedState disco.ClusterState) error {
|
||||
state, err := m.API.State()
|
||||
if err != nil || state != expectedState {
|
||||
return fmt.Errorf("node %q: state %s: err %v", m.ID(), state, err)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/test"
|
||||
)
|
||||
|
||||
|
|
@ -77,8 +77,8 @@ func TestNewCluster(t *testing.T) {
|
|||
t.Fatalf("wrong number of nodes in status: %s", bytes)
|
||||
}
|
||||
|
||||
if body.State != string(pilosa.ClusterStateNormal) {
|
||||
t.Fatalf("cluster state should be %s but is %s", pilosa.ClusterStateNormal, body.State)
|
||||
if body.State != string(disco.ClusterStateNormal) {
|
||||
t.Fatalf("cluster state should be %s but is %s", disco.ClusterStateNormal, body.State)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/boltdb"
|
||||
"github.com/pilosa/pilosa/v2/disco"
|
||||
"github.com/pilosa/pilosa/v2/http"
|
||||
"github.com/pilosa/pilosa/v2/mock"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
|
|
@ -499,13 +500,13 @@ func TestTranslation_Replication(t *testing.T) {
|
|||
exp := `{"results":[{"attrs":{},"columns":[],"keys":["x1","x2"]}]}`
|
||||
|
||||
coordState, err := coord.API.State()
|
||||
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)
|
||||
if err != nil || !test.CheckClusterState(coord, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected coord cluster state: %s, got: %s, err: %v", disco.ClusterStateNormal, coordState, err)
|
||||
}
|
||||
|
||||
otherState, err := other.API.State()
|
||||
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)
|
||||
if err != nil || !test.CheckClusterState(other, disco.ClusterStateNormal, 1000) {
|
||||
t.Fatalf("unexpected other cluster state: %s, got: %s, err: %v", disco.ClusterStateNormal, otherState, err)
|
||||
}
|
||||
|
||||
// Verify the data exists
|
||||
|
|
@ -517,8 +518,8 @@ func TestTranslation_Replication(t *testing.T) {
|
|||
}
|
||||
|
||||
coordState, err = coord.API.State()
|
||||
if err != nil || !test.CheckClusterState(coord, string(pilosa.ClusterStateDegraded), 1000) {
|
||||
t.Fatalf("unexpected coord cluster state: %s, got: %s", pilosa.ClusterStateDegraded, coordState)
|
||||
if err != nil || !test.CheckClusterState(coord, disco.ClusterStateDegraded, 1000) {
|
||||
t.Fatalf("unexpected coord cluster state: %s, got: %s", disco.ClusterStateDegraded, coordState)
|
||||
}
|
||||
|
||||
// Verify the data exists with one node down
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue