From 1085be6582a4f24a2e9c144ae1ed193e97c493f7 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Thu, 8 Feb 2018 15:07:04 -0600 Subject: [PATCH] fix bug in NewServerCluster where each host was its own coordinator --- server/cluster_test.go | 20 ++++++++++---------- test/pilosa.go | 13 ++++--------- test/pilosa_test.go | 9 ++++++++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/server/cluster_test.go b/server/cluster_test.go index 114a25b0c..23284bb00 100644 --- a/server/cluster_test.go +++ b/server/cluster_test.go @@ -222,7 +222,7 @@ func TestClusterResize_EmptyNodes(t *testing.T) { gossipHost := "localhost" gossipPort := 0 - seed, coord, err := m0.RunWithTransport(gossipHost, gossipPort, "", nil) + seed, coord, err := m0.RunWithTransport(gossipHost, gossipPort, "", pilosa.URI{}) if err != nil { t.Fatal(err) } @@ -231,7 +231,7 @@ func TestClusterResize_EmptyNodes(t *testing.T) { m1 := test.NewMainWithCluster() defer m1.Close() - seed, coord, err = m1.RunWithTransport(gossipHost, gossipPort, seed, &coord) + seed, coord, err = m1.RunWithTransport(gossipHost, gossipPort, seed, coord) if err != nil { t.Fatal(err) } @@ -250,7 +250,7 @@ func TestClusterResize_AddNode(t *testing.T) { m0 := test.NewMainWithCluster() defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, "", nil) + seed, coord, err := m0.RunWithTransport("localhost", 0, "", pilosa.URI{}) if err != nil { t.Fatal(err) } @@ -261,7 +261,7 @@ func TestClusterResize_AddNode(t *testing.T) { var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, seed, &coord) + _, _, err = m1.RunWithTransport("localhost", 0, seed, coord) if err != nil { return err } @@ -284,7 +284,7 @@ func TestClusterResize_AddNode(t *testing.T) { m0 := test.NewMainWithCluster() defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, "", nil) + seed, coord, err := m0.RunWithTransport("localhost", 0, "", pilosa.URI{}) if err != nil { t.Fatal(err) } @@ -305,7 +305,7 @@ func TestClusterResize_AddNode(t *testing.T) { var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, seed, &coord) + _, _, err = m1.RunWithTransport("localhost", 0, seed, coord) if err != nil { return err } @@ -330,7 +330,7 @@ func TestClusterResize_AddNode(t *testing.T) { m0 := test.NewMainWithCluster() defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, "", nil) + seed, coord, err := m0.RunWithTransport("localhost", 0, "", pilosa.URI{}) if err != nil { t.Fatal(err) } @@ -360,7 +360,7 @@ func TestClusterResize_AddNode(t *testing.T) { var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, seed, &coord) + _, _, err = m1.RunWithTransport("localhost", 0, seed, coord) if err != nil { return err } @@ -385,7 +385,7 @@ func TestClusterResize_AddNode(t *testing.T) { m0 := test.NewMainWithCluster() defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, "", nil) + seed, coord, err := m0.RunWithTransport("localhost", 0, "", pilosa.URI{}) if err != nil { t.Fatal(err) } @@ -415,7 +415,7 @@ func TestClusterResize_AddNode(t *testing.T) { var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, seed, &coord) + _, _, err = m1.RunWithTransport("localhost", 0, seed, coord) if err != nil { return err } diff --git a/test/pilosa.go b/test/pilosa.go index a467a2f5c..b5d745fe0 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -85,7 +85,7 @@ func runMainWithCluster(size int) ([]*Main, error) { for i := 0; i < size; i++ { m := NewMainWithCluster() - gossipSeed, coordinator, err = m.RunWithTransport(gossipHost, gossipPort, gossipSeed, &coordinator) + gossipSeed, coordinator, err = m.RunWithTransport(gossipHost, gossipPort, gossipSeed, coordinator) if err != nil { return nil, errors.Wrap(err, "RunWithTransport") } @@ -132,7 +132,7 @@ func (m *Main) Reopen() error { } // RunWithTransport runs Main and returns the dynamically allocated gossip port. -func (m *Main) RunWithTransport(host string, bindPort int, joinSeed string, coordinator *pilosa.URI) (seed string, coord pilosa.URI, err error) { +func (m *Main) RunWithTransport(host string, bindPort int, joinSeed string, coordinator pilosa.URI) (seed string, coord pilosa.URI, err error) { defer close(m.Started) /* @@ -185,12 +185,7 @@ func (m *Main) RunWithTransport(host string, bindPort int, joinSeed string, coor return seed, coord, err } - if coordinator != nil { - coord = *coordinator - } else { - coord = m.Server.URI - } - m.Server.Cluster.Coordinator = coord + m.Server.Cluster.Coordinator = coordinator m.Server.Cluster.Static = false // Initialize server. @@ -199,7 +194,7 @@ func (m *Main) RunWithTransport(host string, bindPort int, joinSeed string, coor return seed, coord, err } - return seed, coord, nil + return seed, m.Server.Cluster.Coordinator, nil } // URL returns the base URL string for accessing the running program. diff --git a/test/pilosa_test.go b/test/pilosa_test.go index 0d0f168d5..c4842bf8b 100644 --- a/test/pilosa_test.go +++ b/test/pilosa_test.go @@ -10,7 +10,14 @@ import ( ) func TestNewCluster(t *testing.T) { - cluster := test.MustRunMainWithCluster(t, 3) + numNodes := 3 + cluster := test.MustRunMainWithCluster(t, numNodes) + coordinator := cluster[0].Server.Cluster.Coordinator + for i := 1; i < numNodes; i++ { + if coordi := cluster[i].Server.Cluster.Coordinator; coordi != coordinator { + t.Fatalf("node %d does not have the same coordinator as node 0. '%v' and '%v' respectively", i, coordi, coordinator) + } + } response, err := http.Get("http://" + cluster[0].Server.Addr().String() + "/status") if err != nil {