From 1086c6c9597b05ebfb360a2ae4418c043e858015 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Fri, 23 Feb 2018 10:18:53 -0600 Subject: [PATCH 01/20] remove old GossipPort and GossipSeed config options --- config.go | 4 ---- ctl/server.go | 4 +--- ctl/server_test.go | 3 --- server/server.go | 2 -- 4 files changed, 1 insertion(+), 12 deletions(-) diff --git a/config.go b/config.go index 05f132db2..2ed26dbfe 100644 --- a/config.go +++ b/config.go @@ -127,10 +127,6 @@ type TLSConfig struct { type Config struct { DataDir string `toml:"data-dir"` Bind string `toml:"bind"` - // GossipPort DEPRECATED - GossipPort string `toml:"gossip-port"` - // GossipSeed DEPRECATED - GossipSeed string `toml:"gossip-seed"` // Limits the number of mutating commands that can be in a single request to // the server. This includes SetBit, ClearBit, SetRowAttrs & SetColumnAttrs. diff --git a/ctl/server.go b/ctl/server.go index 3c5b1a058..2341123dd 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -26,8 +26,6 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { flags := cmd.Flags() flags.StringVarP(&srv.Config.DataDir, "data-dir", "d", srv.Config.DataDir, "Directory to store pilosa data files.") flags.StringVarP(&srv.Config.Bind, "bind", "b", srv.Config.Bind, "Default URI on which pilosa should listen.") - flags.StringVarP(&srv.Config.GossipPort, "gossip-port", "", "", "(DEPRECATED) Port to which pilosa should bind for internal state sharing.") - flags.StringVarP(&srv.Config.GossipSeed, "gossip-seed", "", "", "(DEPRECATED) Host with which to seed the gossip membership.") flags.IntVarP(&srv.Config.MaxWritesPerRequest, "max-writes-per-request", "", srv.Config.MaxWritesPerRequest, "Number of write commands per request.") flags.StringVar(&srv.Config.LogPath, "log-path", srv.Config.LogPath, "Log path") @@ -38,7 +36,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { flags.BoolVarP(&srv.Config.Cluster.Disabled, "cluster.disabled", "", srv.Config.Cluster.Disabled, "Disabled multi-node cluster communication (used for testing)") flags.StringVarP(&srv.Config.Cluster.Coordinator, "cluster.coordinator", "", "", "Host that will act as cluster coordinator during startup and resizing.") flags.IntVarP(&srv.Config.Cluster.ReplicaN, "cluster.replicas", "", 1, "Number of hosts each piece of data should be stored on.") - flags.StringSliceVarP(&srv.Config.Cluster.Hosts, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster.") + flags.StringSliceVarP(&srv.Config.Cluster.Hosts, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster. Only used for testing.") flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.LongQueryTime), "cluster.long-query-time", "", time.Minute, "Duration that will trigger log and stat messages for slow queries.") // Gossip diff --git a/ctl/server_test.go b/ctl/server_test.go index dc31426ac..9866b497d 100644 --- a/ctl/server_test.go +++ b/ctl/server_test.go @@ -28,9 +28,6 @@ func TestBuildServerFlags(t *testing.T) { stdin, stdout, stderr := GetIO(buf) Server := server.NewCommand(stdin, stdout, stderr) BuildServerFlags(cm, Server) - if cm.Flags().Lookup("gossip-port").Name == "" { - t.Fatal("gossip-port flag is required") - } if cm.Flags().Lookup("data-dir").Name == "" { t.Fatal("data-dir flag is required") } diff --git a/server/server.go b/server/server.go index 19a08f982..5b6bd573d 100644 --- a/server/server.go +++ b/server/server.go @@ -240,8 +240,6 @@ func (m *Command) SetupNetworking() error { // Config.GossipPort is deprecated, so Config.Gossip.Port has priority if m.Config.Gossip.Port != "" { gossipPortStr = m.Config.Gossip.Port - } else if m.Config.GossipPort != "" { - gossipPortStr = m.Config.GossipPort } gossipPort, err := strconv.Atoi(gossipPortStr) From 1233226aa0deaa1927d476299e9978857179f089 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Tue, 6 Mar 2018 12:18:44 -0600 Subject: [PATCH 02/20] remove Join method from StaticMemberSet struct --- broadcast.go | 12 ++++-------- server/server.go | 6 +----- test/cluster.go | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/broadcast.go b/broadcast.go index dd8802f47..62d69e9ff 100644 --- a/broadcast.go +++ b/broadcast.go @@ -35,8 +35,10 @@ type StaticMemberSet struct { } // NewStaticMemberSet creates a statically defined MemberSet. -func NewStaticMemberSet() *StaticMemberSet { - return &StaticMemberSet{} +func NewStaticMemberSet(nodes []*Node) *StaticMemberSet { + return &StaticMemberSet{ + nodes: nodes, + } } // Open implements the MemberSet interface to start network activity, but for a static MemberSet it does nothing. @@ -44,12 +46,6 @@ func (s *StaticMemberSet) Open(n *Node) error { return nil } -// Join sets the MemberSet nodes to the slice of Nodes passed in. -func (s *StaticMemberSet) Join(nodes []*Node) error { - s.nodes = nodes - return nil -} - // Broadcaster is an interface for broadcasting messages. type Broadcaster interface { SendSync(pb proto.Message) error diff --git a/server/server.go b/server/server.go index f0d3314fa..cd98ce594 100644 --- a/server/server.go +++ b/server/server.go @@ -227,13 +227,9 @@ func (m *Command) SetupNetworking() error { } m.Server.Broadcaster = pilosa.NopBroadcaster - m.Server.Cluster.MemberSet = pilosa.NewStaticMemberSet() + m.Server.Cluster.MemberSet = pilosa.NewStaticMemberSet(m.Server.Cluster.Nodes) m.Server.BroadcastReceiver = pilosa.NopBroadcastReceiver m.Server.Gossiper = pilosa.NopGossiper - err := m.Server.Cluster.MemberSet.(*pilosa.StaticMemberSet).Join(m.Server.Cluster.Nodes) - if err != nil { - return err - } return nil } diff --git a/test/cluster.go b/test/cluster.go index f5e0dc7a9..536641b13 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -260,7 +260,7 @@ func (t *TestCluster) addCluster(i int, saveTopology bool) (*pilosa.Cluster, err c.Path = path c.Topology = pilosa.NewTopology() c.Holder = h - c.MemberSet = pilosa.NewStaticMemberSet() + c.MemberSet = pilosa.NewStaticMemberSet(c.Nodes) c.Node = node c.Coordinator = t.common.Nodes[0].URI // the first node is the coordinator c.Broadcaster = t From d0009206b457b55495e0cdd39e622b9315be08eb Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Tue, 6 Mar 2018 12:42:29 -0600 Subject: [PATCH 03/20] add comments to exported methods. remove debugging test. --- cluster.go | 6 ++++-- holder_test.go | 31 ------------------------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/cluster.go b/cluster.go index ed5318917..a2d537b11 100644 --- a/cluster.go +++ b/cluster.go @@ -74,7 +74,7 @@ func (n Node) String() string { return fmt.Sprintf("Node: %s", n.ID) } -// EncodeNodes converts a into its internal representation. +// EncodeNodes converts a slice of Nodes into its internal representation. func EncodeNodes(a []*Node) []*internal.Node { other := make([]*internal.Node, len(a)) for i := range a { @@ -83,7 +83,7 @@ func EncodeNodes(a []*Node) []*internal.Node { return other } -// EncodeNode converts n into its internal representation. +// EncodeNode converts a Node into its internal representation. func EncodeNode(n *Node) *internal.Node { return &internal.Node{ ID: n.ID, @@ -91,6 +91,7 @@ func EncodeNode(n *Node) *internal.Node { } } +// DecodeNodes converts a proto message into a slice of Nodes. func DecodeNodes(a []*internal.Node) []*Node { if len(a) == 0 { return nil @@ -102,6 +103,7 @@ func DecodeNodes(a []*internal.Node) []*Node { return other } +// DecodeNode converts a proto message into a Node. func DecodeNode(node *internal.Node) *Node { return &Node{ ID: node.ID, diff --git a/holder_test.go b/holder_test.go index 3422fe081..5a06a9272 100644 --- a/holder_test.go +++ b/holder_test.go @@ -338,37 +338,6 @@ func TestHolder_HasData(t *testing.T) { }) } -/* -func TestHolder_Schema(t *testing.T) { - t.Run("Schema", func(t *testing.T) { - h := test.MustOpenHolder() - defer h.Close() - - if idx, err := h.CreateIndex("i", pilosa.IndexOptions{}); err != nil { - t.Fatal(err) - } else if frame, err := idx.CreateFrame("f", pilosa.FrameOptions{}); err != nil { - t.Fatal(err) - } else if view, err := frame.CreateViewIfNotExists(pilosa.ViewStandard); err != nil { - t.Fatal(err) - } else if _, err := view.SetBit(0, 0); err != nil { - t.Fatal(err) - } else if err := h.Holder.Close(); err != nil { - t.Fatal(err) - } else if err := os.Chmod(filepath.Join(h.Path, "i", "f", "views", "standard", "fragments", "0"), 0000); err != nil { - t.Fatal(err) - } - fmt.Printf("%v\n", h.Schema()) - defer os.Chmod(filepath.Join(h.Path, "i", "f", "views", "standard", "fragments", "0"), 0666) - - if err := h.Reopen(); err == nil || !strings.Contains(err.Error(), "permission denied") { - t.Fatalf("unexpected error: %s", err) - } - - t.Fatalf("STOPPER") - }) -} -*/ - // Ensure holder can delete an index and its underlying files. func TestHolder_DeleteIndex(t *testing.T) { hldr := test.MustOpenHolder() From d28a30ebd411acaee94ce218a2a2d4cd5a4e726c Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 6 Mar 2018 15:11:46 -0600 Subject: [PATCH 04/20] Proper error handling when attempting to remove node when there aren't enough replicas --- cluster.go | 15 +++++++++++++-- server/cluster_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/cluster.go b/cluster.go index ed5318917..12d6fba50 100644 --- a/cluster.go +++ b/cluster.go @@ -737,7 +737,7 @@ func (c *Cluster) fragSources(to *Cluster, idx *Index) (map[string][]*internal.R // the fragment. srcNodeID, ok := srcNodesByFrag[frag] if !ok { - return nil, errors.New("not enough data to perform resize") + return nil, errors.New("not enough data to perform resize (replica factor may need to be increased)") } src := &internal.ResizeSource{ @@ -937,7 +937,11 @@ func (c *Cluster) allNodesReady() bool { func (c *Cluster) handleNodeAction(nodeAction nodeAction) error { j, err := c.generateResizeJob(nodeAction) if err != nil { - return err + c.logger().Printf("generateResizeJob error: err=%s", err) + if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { + c.logger().Printf("setStateAndBroadcast error: err=%s", err) + } + return c.setStateAndBroadcast(ClusterStateNormal) } // j.Run() runs in a goroutine because in the case where the @@ -1702,6 +1706,13 @@ func (c *Cluster) NodeLeave(node *Node) error { return fmt.Errorf("The coordinator node cannot be removed. First, make a different node the new coordinator.") } + // See if resize job can be generated + _, err := c.generateResizeJobByAction(nodeAction{c.nodeByID(node.ID), ResizeJobActionRemove}) + + if err != nil { + return err + } + return c.nodeLeave(node) } diff --git a/server/cluster_test.go b/server/cluster_test.go index 5ec805f81..9c518aecb 100644 --- a/server/cluster_test.go +++ b/server/cluster_test.go @@ -545,4 +545,35 @@ func TestClusterResize_RemoveNode(t *testing.T) { t.Fatalf("expected Body '%s' but got '%s'", expBody, strings.TrimSpace(resp.Body)) } }) + + t.Run("ErrorRemoveWithoutReplicas", func(t *testing.T) { + client0 := m0.Client() + + // Create indexes and frames on one node. + if err := client0.CreateIndex(context.Background(), "i", pilosa.IndexOptions{}); err != nil && err != pilosa.ErrIndexExists { + t.Fatal(err) + } else if err := client0.CreateFrame(context.Background(), "i", "f", pilosa.FrameOptions{}); err != nil { + t.Fatal(err) + } + + setBits := "" + for i := 0; i < 20; i++ { + setBits += fmt.Sprintf("SetBit(rowID=1, frame=\"f\", columnID=%d) ", i*pilosa.SliceWidth) + } + + if _, err := m0.Query("i", "", setBits); err != nil { + t.Fatal(err) + } + + resp := test.MustDo("GET", m1.URL()+fmt.Sprintf("/id"), "") + nodeID := resp.Body + + resp = test.MustDo("POST", m0.URL()+fmt.Sprintf("/cluster/resize/remove-node"), fmt.Sprintf(`{"id": "%s"}`, nodeID)) + expBody := "not enough data to perform resize" + if resp.StatusCode != http.StatusInternalServerError { + t.Fatalf("expected StatusCode %d but got %d", http.StatusInternalServerError, resp.StatusCode) + } else if !strings.Contains(resp.Body, expBody) { + t.Fatalf("expected to contain '%s' but got '%s'", expBody, strings.TrimSpace(resp.Body)) + } + }) } From b7b92913d9c0013e21f7e582fcd9c0cb47565212 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 6 Mar 2018 15:13:24 -0600 Subject: [PATCH 05/20] Add comment to listenForJoins --- cluster.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cluster.go b/cluster.go index 12d6fba50..dcb9e0ecc 100644 --- a/cluster.go +++ b/cluster.go @@ -1002,7 +1002,13 @@ func (c *Cluster) ListenForJoins() { } func (c *Cluster) listenForJoins() { - var uriJoined bool + // When a cluster starts, the state is STARTING. + // We first want to wait for at least one node to join. + // Then we want to clear out the joiningLeavingNodes queue (buffered channel). + // Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events. + // We use a bool `setNormal` to indicate when at least one node has joined. + + var setNormal bool for { @@ -1014,13 +1020,13 @@ func (c *Cluster) listenForJoins() { c.logger().Printf("handleNodeAction error: err=%s", err) continue } - uriJoined = true + setNormal = true continue default: } // Only change state to NORMAL if we have successfully added at least one host. - if uriJoined { + if setNormal { // Put the cluster back to state NORMAL and broadcast. if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { c.logger().Printf("setStateAndBroadcast error: err=%s", err) @@ -1037,7 +1043,7 @@ func (c *Cluster) listenForJoins() { c.logger().Printf("handleNodeAction error: err=%s", err) continue } - uriJoined = true + setNormal = true continue } } From 42682e12a828639aa953baf06e526cdb500ed5b4 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 7 Mar 2018 09:45:27 -0600 Subject: [PATCH 06/20] Address code review: Fix error handling and add comment --- cluster.go | 2 +- server/cluster_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cluster.go b/cluster.go index dcb9e0ecc..8b56edaaf 100644 --- a/cluster.go +++ b/cluster.go @@ -941,7 +941,7 @@ func (c *Cluster) handleNodeAction(nodeAction nodeAction) error { if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { c.logger().Printf("setStateAndBroadcast error: err=%s", err) } - return c.setStateAndBroadcast(ClusterStateNormal) + return err } // j.Run() runs in a goroutine because in the case where the diff --git a/server/cluster_test.go b/server/cluster_test.go index 9c518aecb..299415bc3 100644 --- a/server/cluster_test.go +++ b/server/cluster_test.go @@ -556,6 +556,8 @@ func TestClusterResize_RemoveNode(t *testing.T) { t.Fatal(err) } + // This is an attempt to ensure there is data on both nodes, but is not guaranteed. + // TODO: Deterministic node IDs would ensure consistent results setBits := "" for i := 0; i < 20; i++ { setBits += fmt.Sprintf("SetBit(rowID=1, frame=\"f\", columnID=%d) ", i*pilosa.SliceWidth) From 1cc45b22a2edf49cab4b2bdf9d9e957c1d6f2e2c Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Mon, 5 Mar 2018 12:14:10 -0600 Subject: [PATCH 07/20] Change Config.Coordinator from URI to bool --- cluster.go | 30 ++++-- cluster_internal_test.go | 16 +-- cluster_test.go | 8 +- config.go | 4 +- ctl/server.go | 2 +- handler_test.go | 4 +- internal/private.pb.go | 210 +++++++++++++++++++++++---------------- internal/private.proto | 1 + server.go | 11 +- server/cluster_test.go | 56 +++++------ server/server.go | 27 ++--- test/cluster.go | 4 +- test/pilosa.go | 25 +++-- 13 files changed, 218 insertions(+), 180 deletions(-) diff --git a/cluster.go b/cluster.go index ee0912b09..8cdd1e922 100644 --- a/cluster.go +++ b/cluster.go @@ -66,8 +66,9 @@ const ( // Node represents a node in the cluster. type Node struct { - ID string `json:"id"` - URI URI `json:"uri"` + ID string `json:"id"` + URI URI `json:"uri"` + IsCoordinator bool `json:"isCoordinator"` } func (n Node) String() string { @@ -86,8 +87,9 @@ func EncodeNodes(a []*Node) []*internal.Node { // EncodeNode converts a Node into its internal representation. func EncodeNode(n *Node) *internal.Node { return &internal.Node{ - ID: n.ID, - URI: n.URI.Encode(), + ID: n.ID, + URI: n.URI.Encode(), + IsCoordinator: n.IsCoordinator, } } @@ -106,8 +108,9 @@ func DecodeNodes(a []*internal.Node) []*Node { // DecodeNode converts a proto message into a Node. func DecodeNode(node *internal.Node) *Node { return &Node{ - ID: node.ID, - URI: decodeURI(node.URI), + ID: node.ID, + URI: decodeURI(node.URI), + IsCoordinator: node.IsCoordinator, } } @@ -238,7 +241,7 @@ type Cluster struct { // Required for cluster Resize. Static bool // Static is primarily used for testing in a non-gossip environment. state string - Coordinator URI + Coordinator string Holder *Holder Broadcaster Broadcaster @@ -291,12 +294,12 @@ func (c *Cluster) logger() *log.Logger { // Coordinator returns the coordinator node. func (c *Cluster) CoordinatorNode() *Node { - return c.nodeByURI(c.Coordinator) + return c.nodeByID(c.Coordinator) } // IsCoordinator is true if this node is the coordinator. func (c *Cluster) IsCoordinator() bool { - return c.Static || c.Coordinator == c.Node.URI + return c.Coordinator == c.Node.ID } // SetCoordinator updates the Coordinator to n. @@ -308,8 +311,8 @@ func (c *Cluster) SetCoordinator(n *Node) bool { return false } - if c.Coordinator != newNode.URI { - c.Coordinator = newNode.URI + if c.Coordinator != newNode.ID { + c.Coordinator = newNode.ID return true } return false @@ -320,6 +323,11 @@ func (c *Cluster) SetCoordinator(n *Node) bool { func (c *Cluster) AddNode(node *Node) error { c.logger().Printf("add node %s to cluster on %s", node, c.Node) + // If the node being added is the coordinator, set it for this node. + if node.IsCoordinator { + c.Coordinator = node.ID + } + // add to cluster if !c.addNodeBasicSorted(node) { return nil diff --git a/cluster_internal_test.go b/cluster_internal_test.go index 6c2c98e40..da9989760 100644 --- a/cluster_internal_test.go +++ b/cluster_internal_test.go @@ -180,8 +180,8 @@ func TestFragSources(t *testing.T) { "node0": []*internal.ResizeSource{}, "node1": []*internal.ResizeSource{}, "node2": []*internal.ResizeSource{ - {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}}, "i", "f", "standard", uint64(0)}, - {&internal.Node{"node1", &internal.URI{"http", "host1", 10101}}, "i", "f", "standard", uint64(2)}, + {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}, false}, "i", "f", "standard", uint64(0)}, + {&internal.Node{"node1", &internal.URI{"http", "host1", 10101}, false}, "i", "f", "standard", uint64(2)}, }, }, err: "", @@ -192,11 +192,11 @@ func TestFragSources(t *testing.T) { idx: idx, expected: map[string][]*internal.ResizeSource{ "node0": []*internal.ResizeSource{ - {&internal.Node{"node1", &internal.URI{"http", "host1", 10101}}, "i", "f", "standard", uint64(1)}, + {&internal.Node{"node1", &internal.URI{"http", "host1", 10101}, false}, "i", "f", "standard", uint64(1)}, }, "node1": []*internal.ResizeSource{ - {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}}, "i", "f", "standard", uint64(0)}, - {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}}, "i", "f", "standard", uint64(2)}, + {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}, false}, "i", "f", "standard", uint64(0)}, + {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}, false}, "i", "f", "standard", uint64(2)}, }, }, err: "", @@ -207,11 +207,11 @@ func TestFragSources(t *testing.T) { idx: idx, expected: map[string][]*internal.ResizeSource{ "node0": []*internal.ResizeSource{ - {&internal.Node{"node2", &internal.URI{"http", "host2", 10101}}, "i", "f", "standard", uint64(0)}, - {&internal.Node{"node2", &internal.URI{"http", "host2", 10101}}, "i", "f", "standard", uint64(2)}, + {&internal.Node{"node2", &internal.URI{"http", "host2", 10101}, false}, "i", "f", "standard", uint64(0)}, + {&internal.Node{"node2", &internal.URI{"http", "host2", 10101}, false}, "i", "f", "standard", uint64(2)}, }, "node1": []*internal.ResizeSource{ - {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}}, "i", "f", "standard", uint64(3)}, + {&internal.Node{"node0", &internal.URI{"http", "host0", 10101}, false}, "i", "f", "standard", uint64(3)}, }, "node2": []*internal.ResizeSource{}, }, diff --git a/cluster_test.go b/cluster_test.go index 5a5fa4de4..5c5c5f89c 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -180,10 +180,10 @@ func TestCluster_Coordinator(t *testing.T) { c1 := *pilosa.NewCluster() c1.Node = node1 - c1.Coordinator = node1.URI + c1.Coordinator = node1.ID c2 := *pilosa.NewCluster() c2.Node = node2 - c2.Coordinator = node1.URI + c2.Coordinator = node1.ID t.Run("IsCoordinator", func(t *testing.T) { if !c1.IsCoordinator() { @@ -519,14 +519,14 @@ func TestCluster_SetCoordinator(t *testing.T) { // Set coordinator to the same value. if c.SetCoordinator(oldNode) { t.Errorf("did not expect coordinator to change") - } else if c.Coordinator != oldNode.URI { + } else if c.Coordinator != oldNode.ID { t.Errorf("expected coordinator: %s, but got: %s", c.Coordinator, oldNode.URI) } // Set coordinator to a new value. if !c.SetCoordinator(newNode) { t.Errorf("expected coordinator to change") - } else if c.Coordinator != newNode.URI { + } else if c.Coordinator != newNode.ID { t.Errorf("expected coordinator: %s, but got: %s", c.Coordinator, newNode.URI) } }) diff --git a/config.go b/config.go index 4fa06fc51..17841c967 100644 --- a/config.go +++ b/config.go @@ -139,7 +139,7 @@ type Config struct { Cluster struct { Disabled bool `toml:"disabled"` - Coordinator string `toml:"coordinator"` + Coordinator bool `toml:"coordinator"` ReplicaN int `toml:"replicas"` Hosts []string `toml:"hosts"` LongQueryTime Duration `toml:"long-query-time"` @@ -183,7 +183,7 @@ func NewConfig() *Config { // Cluster config. c.Cluster.Disabled = DefaultClusterDisabled - // c.Cluster.Coordinator = "" + // c.Cluster.Coordinator = false c.Cluster.ReplicaN = DefaultReplicaN c.Cluster.Hosts = []string{} c.Cluster.LongQueryTime = Duration(time.Minute) diff --git a/ctl/server.go b/ctl/server.go index 18f4f6f93..80eb909d2 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -34,7 +34,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { // Cluster flags.BoolVarP(&srv.Config.Cluster.Disabled, "cluster.disabled", "", srv.Config.Cluster.Disabled, "Disabled multi-node cluster communication (used for testing)") - flags.StringVarP(&srv.Config.Cluster.Coordinator, "cluster.coordinator", "", "", "Host that will act as cluster coordinator during startup and resizing.") + flags.BoolVarP(&srv.Config.Cluster.Coordinator, "cluster.coordinator", "", srv.Config.Cluster.Coordinator, "Host that will act as cluster coordinator during startup and resizing.") flags.IntVarP(&srv.Config.Cluster.ReplicaN, "cluster.replicas", "", 1, "Number of hosts each piece of data should be stored on.") flags.StringSliceVarP(&srv.Config.Cluster.Hosts, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster.") flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.LongQueryTime), "cluster.long-query-time", "", time.Minute, "Duration that will trigger log and stat messages for slow queries.") diff --git a/handler_test.go b/handler_test.go index 1caf7bf99..0f527514d 100644 --- a/handler_test.go +++ b/handler_test.go @@ -147,7 +147,7 @@ func TestHandler_Status(t *testing.T) { h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/status", nil)) if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) - } else if body := w.Body.String(); body != `{"state":"NORMAL","nodes":[{"id":"test-node","uri":{"scheme":"http","host":"localhost","port":10101}}]}`+"\n" { + } else if body := w.Body.String(); body != `{"state":"NORMAL","nodes":[{"id":"test-node","uri":{"scheme":"http","host":"localhost","port":10101},"isCoordinator":false}]}`+"\n" { t.Fatalf("unexpected body: %s", body) } } @@ -1212,7 +1212,7 @@ func TestHandler_Fragment_Nodes(t *testing.T) { h.ServeHTTP(w, r) if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) - } else if body := w.Body.String(); body != `[{"id":"node2","uri":{"scheme":"http","host":"host2"}},{"id":"node0","uri":{"scheme":"http","host":"host0"}}]`+"\n" { + } else if body := w.Body.String(); body != `[{"id":"node2","uri":{"scheme":"http","host":"host2"},"isCoordinator":false},{"id":"node0","uri":{"scheme":"http","host":"host0"},"isCoordinator":false}]`+"\n" { t.Fatalf("unexpected body: %q", body) } diff --git a/internal/private.pb.go b/internal/private.pb.go index cdf0dab40..4d2bcdd08 100644 --- a/internal/private.pb.go +++ b/internal/private.pb.go @@ -742,8 +742,9 @@ func (m *URI) GetPort() uint32 { } type Node struct { - ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` - URI *URI `protobuf:"bytes,2,opt,name=URI" json:"URI,omitempty"` + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` + URI *URI `protobuf:"bytes,2,opt,name=URI" json:"URI,omitempty"` + IsCoordinator bool `protobuf:"varint,3,opt,name=IsCoordinator,proto3" json:"IsCoordinator,omitempty"` } func (m *Node) Reset() { *m = Node{} } @@ -765,6 +766,13 @@ func (m *Node) GetURI() *URI { return nil } +func (m *Node) GetIsCoordinator() bool { + if m != nil { + return m.IsCoordinator + } + return false +} + type NodeStateMessage struct { NodeID string `protobuf:"bytes,1,opt,name=NodeID,proto3" json:"NodeID,omitempty"` State string `protobuf:"bytes,2,opt,name=State,proto3" json:"State,omitempty"` @@ -2136,6 +2144,16 @@ func (m *Node) MarshalTo(dAtA []byte) (int, error) { } i += n12 } + if m.IsCoordinator { + dAtA[i] = 0x18 + i++ + if m.IsCoordinator { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } return i, nil } @@ -3068,6 +3086,9 @@ func (m *Node) Size() (n int) { l = m.URI.Size() n += 1 + l + sovPrivate(uint64(l)) } + if m.IsCoordinator { + n += 2 + } return n } @@ -6575,6 +6596,26 @@ func (m *Node) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsCoordinator", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.IsCoordinator = bool(v != 0) default: iNdEx = preIndex skippy, err := skipPrivate(dAtA[iNdEx:]) @@ -8313,86 +8354,87 @@ var ( func init() { proto.RegisterFile("private.proto", fileDescriptorPrivate) } var fileDescriptorPrivate = []byte{ - // 1296 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0x67, 0xbd, 0xb6, 0x63, 0x3f, 0xc7, 0x89, 0x33, 0x4d, 0x83, 0x13, 0x45, 0xae, 0x19, 0x01, - 0x0d, 0x95, 0x88, 0x8a, 0x2b, 0x01, 0x0d, 0xaa, 0x54, 0x12, 0xbb, 0xea, 0x02, 0x09, 0x65, 0x9c, - 0x06, 0x89, 0x03, 0xd2, 0xc4, 0x1e, 0xd2, 0x55, 0xd6, 0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xff, 0x60, 0xc1, 0x62, 0x9a, 0xc2, 0x7f, 0x3a, 0x18, 0x71, 0x45, 0x32, 0x53, 0x2b, 0x62, 0x4f, - 0xab, 0x48, 0x36, 0xa9, 0x48, 0xf2, 0xe6, 0xcc, 0xa5, 0xde, 0x9c, 0xf8, 0x14, 0xd6, 0x27, 0xca, - 0xb4, 0x17, 0xf4, 0xfa, 0xa2, 0x1f, 0xfe, 0x47, 0xb9, 0x56, 0x21, 0xd7, 0x0a, 0x43, 0x5d, 0xa8, - 0x22, 0x51, 0x02, 0x7e, 0x08, 0xb7, 0xdb, 0x8c, 0xa7, 0x8a, 0x64, 0xba, 0xad, 0x0e, 0xf6, 0x01, - 0x3b, 0x9f, 0xb1, 0x7d, 0xa1, 0xc2, 0xbb, 0x50, 0x38, 0x0c, 0xfa, 0x81, 0x17, 0x9c, 0x0c, 0xaf, - 0x38, 0xb4, 0x55, 0x58, 0x50, 0x33, 0x49, 0x5d, 0xf9, 0x45, 0x62, 0x44, 0x7c, 0x4b, 0xb4, 0x64, - 0x87, 0x7a, 0x9d, 0x81, 0x47, 0x39, 0x93, 0x7f, 0x32, 0xd1, 0x6e, 0xe5, 0xb7, 0xcb, 0x9a, 0xf5, - 0xfb, 0x65, 0xcd, 0xfa, 0xe3, 0xb2, 0x66, 0xfd, 0xfc, 0x67, 0xed, 0xb5, 0xe3, 0xbc, 0xfc, 0x67, - 0x7e, 0xf0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0x23, 0x92, 0x89, 0x44, 0x0f, 0x00, 0x00, + // 1306 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xdd, 0x6e, 0x1b, 0x45, + 0x14, 0x66, 0xbd, 0xb6, 0x63, 0x1f, 0xd7, 0xa9, 0x33, 0x4d, 0x83, 0x13, 0x45, 0xae, 0x19, 0x15, + 0x1a, 0x2a, 0x11, 0x15, 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d, 0xd1, 0x56, 0xcc, + 0xd4, 0x32, 0x31, 0x6a, 0xa9, 0x3a, 0xca, 0x2d, 0xae, 0x23, 0xf4, 0x78, 0xa2, 0x8e, 0xe4, 0xbf, + 0x46, 0xa9, 0xf1, 0x7a, 0x62, 0x30, 0xb6, 0x4c, 0xc6, 0xb5, 0xf1, 0xf7, 0x16, 0xdc, 0x48, 0x53, + 0xf8, 0x57, 0x8d, 0x11, 0x67, 0x24, 0x33, 0x33, 0x23, 0xf6, 0xac, 0x8c, 0x64, 0x93, 0x8c, 0x24, + 0x2f, 0xd3, 0x5c, 0xea, 0x65, 0x8a, 0x4f, 0x60, 0x7d, 0x2a, 0x4d, 0xcd, 0xa0, 0x3f, 0x10, 0xf5, + 0xf0, 0x1f, 0xd2, 0xb5, 0x0a, 0xb9, 0x76, 0x18, 0xea, 0x44, 0x15, 0x89, 0x12, 0xf0, 0x23, 0xb8, + 0xdd, 0x61, 0x3c, 0x95, 0x24, 0x53, 0x6d, 0x75, 0xb0, 0xf7, 0xd9, 0xd9, 0x9c, 0xe3, 0x8b, 0x25, + 0xbc, 0x0b, 0x85, 0x83, 0x60, 0x10, 0x78, 0xc1, 0xf1, 0xe8, 0x92, 0xa6, 0xad, 0xc2, 0x92, 0x9a, + 0x49, 0xea, 0x61, 0x50, 0x24, 0x46, 0xc4, 0xb7, 0x44, 0x49, 0x76, 0xa9, 0xd7, 0x1d, 0x7a, 0x94, + 0x33, 0xf9, 0xbf, 0x13, 0xed, 0x56, 0x7e, 0xbd, 0xa8, 0x59, 0xbf, 0x5d, 0xd4, 0xac, 0xdf, 0x2f, + 0x6a, 0xd6, 0x4f, 0x7f, 0xd4, 0x5e, 0x3b, 0xca, 0xcb, 0x3f, 0xeb, 0x87, 0xff, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xd7, 0xef, 0xfa, 0x68, 0x6a, 0x0f, 0x00, 0x00, } diff --git a/internal/private.proto b/internal/private.proto index b012936d9..5f4a1c6f6 100644 --- a/internal/private.proto +++ b/internal/private.proto @@ -136,6 +136,7 @@ message URI { message Node { string ID = 1; URI URI = 2; + bool IsCoordinator = 3; } message NodeStateMessage { diff --git a/server.go b/server.go index be63a39e3..0dcca4d1e 100644 --- a/server.go +++ b/server.go @@ -132,7 +132,11 @@ func (s *Server) Open() error { s.NodeID = s.LoadNodeID() // Set Cluster Node. - node := &Node{ID: s.NodeID, URI: s.URI} + node := &Node{ + ID: s.NodeID, + URI: s.URI, + IsCoordinator: s.Cluster.Coordinator == s.NodeID, + } s.Cluster.Node = node // Append the NodeID tag to stats. @@ -185,11 +189,6 @@ func (s *Server) Open() error { return fmt.Errorf("starting BroadcastReceiver: %v", err) } - // If a Coordinator is not specified, then default to s.URI. - if s.Cluster.Coordinator.Port() == 0 { - s.Cluster.Coordinator = s.URI - } - // Open Cluster management. if err := s.Cluster.Open(); err != nil { return fmt.Errorf("opening Cluster: %v", err) diff --git a/server/cluster_test.go b/server/cluster_test.go index 299415bc3..81a410e83 100644 --- a/server/cluster_test.go +++ b/server/cluster_test.go @@ -52,7 +52,7 @@ func TestMain_SendReceiveMessage(t *testing.T) { m0.Config.Gossip.Port = "0" m0.Config.Gossip.Seeds = []string{} - m0.Server.Cluster.Coordinator = m0.Server.URI + m0.Server.Cluster.Coordinator = m0.Server.NodeID m0.Server.Cluster.Topology = &pilosa.Topology{NodeIDs: []string{m0.Server.NodeID, m1.Server.NodeID}} m0.Server.Cluster.EventReceiver = gossip.NewGossipEventReceiver(m0.Server.LogOutput) gossipMemberSet0, err := gossip.NewGossipMemberSet(m0.Server.URI.HostPort(), m0.Config, m0.Server) @@ -80,7 +80,7 @@ func TestMain_SendReceiveMessage(t *testing.T) { m1.Config.Gossip.Port = "0" m1.Config.Gossip.Seeds = gossipMemberSet0.Seeds() - m1.Server.Cluster.Coordinator = m0.Server.URI + m1.Server.Cluster.Coordinator = m0.Server.NodeID m1.Server.Cluster.EventReceiver = gossip.NewGossipEventReceiver(m1.Server.LogOutput) gossipMemberSet1, err := gossip.NewGossipMemberSet(m1.Server.URI.HostPort(), m1.Config, m1.Server) if err != nil { @@ -220,21 +220,21 @@ func TestClusterResize_EmptyNode(t *testing.T) { // Ensure that a cluster of empty nodes comes up in a NORMAL state. func TestClusterResize_EmptyNodes(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() gossipHost := "localhost" gossipPort := 0 - seed, coord, err := m0.RunWithTransport(gossipHost, gossipPort, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport(gossipHost, gossipPort, []string{}) if err != nil { t.Fatal(err) } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() - seed, coord, err = m1.RunWithTransport(gossipHost, gossipPort, []string{seed}, coord) + seed, err = m1.RunWithTransport(gossipHost, gossipPort, []string{seed}) if err != nil { t.Fatal(err) } @@ -250,21 +250,21 @@ func TestClusterResize_EmptyNodes(t *testing.T) { func TestClusterResize_AddNode(t *testing.T) { t.Run("NoData", func(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport("localhost", 0, []string{}) if err != nil { t.Fatal(err) } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, []string{seed}, coord) + _, err = m1.RunWithTransport("localhost", 0, []string{seed}) if err != nil { return err } @@ -284,10 +284,10 @@ func TestClusterResize_AddNode(t *testing.T) { }) t.Run("WithIndex", func(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport("localhost", 0, []string{}) if err != nil { t.Fatal(err) } @@ -303,12 +303,12 @@ func TestClusterResize_AddNode(t *testing.T) { } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, []string{seed}, coord) + _, err = m1.RunWithTransport("localhost", 0, []string{seed}) if err != nil { return err } @@ -330,10 +330,10 @@ func TestClusterResize_AddNode(t *testing.T) { t.Run("ContinuousSlices", func(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport("localhost", 0, []string{}) if err != nil { t.Fatal(err) } @@ -358,12 +358,12 @@ func TestClusterResize_AddNode(t *testing.T) { } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, []string{seed}, coord) + _, err = m1.RunWithTransport("localhost", 0, []string{seed}) if err != nil { return err } @@ -385,10 +385,10 @@ func TestClusterResize_AddNode(t *testing.T) { t.Run("SkippedSlice", func(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport("localhost", 0, []string{}) if err != nil { t.Fatal(err) } @@ -413,12 +413,12 @@ func TestClusterResize_AddNode(t *testing.T) { } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() var eg errgroup.Group eg.Go(func() error { - _, _, err = m1.RunWithTransport("localhost", 0, []string{seed}, coord) + _, err = m1.RunWithTransport("localhost", 0, []string{seed}) if err != nil { return err } @@ -443,22 +443,22 @@ func TestClusterResize_AddNode(t *testing.T) { func TestCluster_GossipMembership(t *testing.T) { t.Run("Node0Down", func(t *testing.T) { // Configure node0 - m0 := test.NewMainWithCluster() + m0 := test.NewMainWithCluster(true) defer m0.Close() - seed, coord, err := m0.RunWithTransport("localhost", 0, []string{}, pilosa.URI{}) + seed, err := m0.RunWithTransport("localhost", 0, []string{}) if err != nil { t.Fatal(err) } // Configure node1 - m1 := test.NewMainWithCluster() + m1 := test.NewMainWithCluster(false) defer m1.Close() var eg errgroup.Group eg.Go(func() error { // Pass invalid seed as first in list - _, _, err = m1.RunWithTransport("localhost", 0, []string{"http://localhost:8765", seed}, coord) + _, err = m1.RunWithTransport("localhost", 0, []string{"http://localhost:8765", seed}) if err != nil { return err } @@ -466,12 +466,12 @@ func TestCluster_GossipMembership(t *testing.T) { }) // Configure node2 - m2 := test.NewMainWithCluster() + m2 := test.NewMainWithCluster(false) defer m2.Close() eg.Go(func() error { // Pass invalid seed as last in list - _, _, err = m2.RunWithTransport("localhost", 0, []string{seed, "http://localhost:8765"}, coord) + _, err = m2.RunWithTransport("localhost", 0, []string{seed, "http://localhost:8765"}) if err != nil { return err } diff --git a/server/server.go b/server/server.go index cd98ce594..240b8b16b 100644 --- a/server/server.go +++ b/server/server.go @@ -181,31 +181,13 @@ func (m *Command) SetupServer() error { InsecureSkipVerify: m.Config.TLS.SkipVerify, } - // TODO Review this location - TLSConfig = m.Server.TLS - } c := pilosa.GetHTTPClient(TLSConfig) m.Server.RemoteClient = c m.Server.Handler.RemoteClient = c m.Server.Cluster.RemoteClient = c - // Default coordintor to port 0 when not specified so that coordinator - // can be set to the value of server.URI after server binds to a port. - // This would only be useful in a one-node cluster. - coord := m.Config.Cluster.Coordinator - if coord == "" { - coord = ":0" - } - - // Set the coordinator node. - curi, err := pilosa.AddressWithDefaults(coord) - if err != nil { - return err - } - m.Server.Cluster.Coordinator = *curi - // Set configuration options. m.Server.AntiEntropyInterval = time.Duration(m.Config.AntiEntropy.Interval) m.Server.Cluster.LongQueryTime = time.Duration(m.Config.Cluster.LongQueryTime) @@ -214,8 +196,12 @@ func (m *Command) SetupServer() error { // SetupNetworking sets up internode communication based on the configuration. func (m *Command) SetupNetworking() error { + + m.Server.NodeID = m.Server.LoadNodeID() + if m.Config.Cluster.Disabled { m.Server.Cluster.Static = true + m.Server.Cluster.Coordinator = m.Server.NodeID for _, address := range m.Config.Cluster.Hosts { uri, err := pilosa.NewURIFromAddress(address) if err != nil { @@ -256,7 +242,10 @@ func (m *Command) SetupNetworking() error { } } - m.Server.NodeID = m.Server.LoadNodeID() + // Set Coordinator. + if m.Config.Cluster.Coordinator || len(m.Config.Gossip.Seeds) == 0 { + m.Server.Cluster.Coordinator = m.Server.NodeID + } m.Server.Cluster.EventReceiver = gossip.NewGossipEventReceiver(m.Server.LogOutput) gossipMemberSet, err := gossip.NewGossipMemberSetWithTransport(m.Server.NodeID, m.Config, transport, m.Server) diff --git a/test/cluster.go b/test/cluster.go index 536641b13..8362ca964 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -49,7 +49,7 @@ func NewCluster(n int) *pilosa.Cluster { } c.Node = c.Nodes[0] - c.Coordinator = c.Nodes[0].URI + c.Coordinator = c.Nodes[0].ID return c } @@ -262,7 +262,7 @@ func (t *TestCluster) addCluster(i int, saveTopology bool) (*pilosa.Cluster, err c.Holder = h c.MemberSet = pilosa.NewStaticMemberSet(c.Nodes) c.Node = node - c.Coordinator = t.common.Nodes[0].URI // the first node is the coordinator + c.Coordinator = t.common.Nodes[0].ID // the first node is the coordinator c.Broadcaster = t // add nodes diff --git a/test/pilosa.go b/test/pilosa.go index 8facad563..2bfd0c1a6 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -65,9 +65,10 @@ func NewMain() *Main { } // NewMainWithCluster returns a new instance of Main with clustering enabled. -func NewMainWithCluster() *Main { +func NewMainWithCluster(isCoordinator bool) *Main { m := NewMain() m.Config.Cluster.Disabled = false + m.Config.Cluster.Coordinator = isCoordinator return m } @@ -94,12 +95,11 @@ func runMainWithCluster(size int) ([]*Main, error) { gossipPort := 0 var err error var gossipSeeds = make([]string, size) - var coordinator pilosa.URI for i := 0; i < size; i++ { - m := NewMainWithCluster() + m := NewMainWithCluster(i == 0) - gossipSeeds[i], coordinator, err = m.RunWithTransport(gossipHost, gossipPort, gossipSeeds[:i], coordinator) + gossipSeeds[i], err = m.RunWithTransport(gossipHost, gossipPort, gossipSeeds[:i]) if err != nil { return nil, errors.Wrap(err, "RunWithTransport") } @@ -146,7 +146,7 @@ func (m *Main) Reopen() error { } // RunWithTransport runs Main and returns the dynamically allocated gossip port. -func (m *Main) RunWithTransport(host string, bindPort int, joinSeeds []string, coordinator pilosa.URI) (seed string, coord pilosa.URI, err error) { +func (m *Main) RunWithTransport(host string, bindPort int, joinSeeds []string) (seed string, err error) { defer close(m.Started) /* @@ -166,19 +166,19 @@ func (m *Main) RunWithTransport(host string, bindPort int, joinSeeds []string, c // SetupServer err = m.SetupServer() if err != nil { - return seed, coord, err + return seed, err } // Open server listener. err = m.Server.OpenListener() if err != nil { - return seed, coord, err + return seed, err } // Open gossip transport to use in SetupServer. transport, err := gossip.NewTransport(host, bindPort) if err != nil { - return seed, coord, err + return seed, err } m.GossipTransport = transport @@ -193,23 +193,22 @@ func (m *Main) RunWithTransport(host string, bindPort int, joinSeeds []string, c // SetupNetworking err = m.SetupNetworking() if err != nil { - return seed, coord, err + return seed, err } if err = m.Server.BroadcastReceiver.Start(m.Server); err != nil { - return seed, coord, err + return seed, err } - m.Server.Cluster.Coordinator = coordinator m.Server.Cluster.Static = false // Initialize server. err = m.Server.Open() if err != nil { - return seed, coord, err + return seed, err } - return seed, m.Server.Cluster.Coordinator, nil + return seed, nil } // URL returns the base URL string for accessing the running program. From fa4e543e84c5ecaa4ea5222da2454d35085f54f7 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Mon, 26 Feb 2018 15:41:04 -0600 Subject: [PATCH 08/20] send a NodeJoin event on startup for cases where a quick restart has occurred and memberlist is not aware of it --- broadcast.go | 5 + cluster.go | 31 ++- internal/private.pb.go | 421 +++++++++++++++++++++++++++++------------ internal/private.proto | 5 + server.go | 2 + 5 files changed, 338 insertions(+), 126 deletions(-) diff --git a/broadcast.go b/broadcast.go index 62d69e9ff..6dbb0f771 100644 --- a/broadcast.go +++ b/broadcast.go @@ -136,6 +136,7 @@ const ( MessageTypeSetCoordinator MessageTypeNodeState MessageTypeRecalculateCaches + MessageTypeNodeEvent ) // MarshalMessage encodes the protobuf message into a byte slice. @@ -176,6 +177,8 @@ func MarshalMessage(m proto.Message) ([]byte, error) { typ = MessageTypeNodeState case *internal.RecalculateCaches: typ = MessageTypeRecalculateCaches + case *internal.NodeEventMessage: + typ = MessageTypeNodeEvent default: return nil, fmt.Errorf("message type not implemented for marshalling: %s", reflect.TypeOf(obj)) } @@ -226,6 +229,8 @@ func UnmarshalMessage(buf []byte) (proto.Message, error) { m = &internal.NodeStateMessage{} case MessageTypeRecalculateCaches: m = &internal.RecalculateCaches{} + case MessageTypeNodeEvent: + m = &internal.NodeEventMessage{} default: return nil, fmt.Errorf("invalid message type: %d", typ) } diff --git a/cluster.go b/cluster.go index 8cdd1e922..b93e6105c 100644 --- a/cluster.go +++ b/cluster.go @@ -114,6 +114,13 @@ func DecodeNode(node *internal.Node) *Node { } } +func DecodeNodeEvent(ne *internal.NodeEventMessage) *NodeEvent { + return &NodeEvent{ + Event: NodeEventType(ne.Event), + Node: DecodeNode(ne.Node), + } +} + // Nodes represents a list of nodes. type Nodes []*Node @@ -897,6 +904,22 @@ func (c *Cluster) Open() error { // If not coordinator then wait for ClusterStatus from coordinator. if !c.IsCoordinator() { + // In the case where a node has been restarted and memberlist has + // not had enough time to determine the node went down/up, then + // the coorninator needs to be alerted that this node is back up + // (and now in a state of STARTING) so that it can be put to the correct + // cluster state. + // TODO: Because the normal code path already sends a NodeJoin event (via + // memberlist), this it a bit redundant in most cases. Perhaps determine + // that the node has been restarted and don't do this step. + msg := &internal.NodeEventMessage{ + Event: uint32(NodeJoin), + Node: EncodeNode(c.Node), + } + if err := c.Broadcaster.SendAsync(msg); err != nil { + return fmt.Errorf("sending restart NodeJoin: %v", err) + } + c.logger().Printf("wait for joining to complete") <-c.joining c.logger().Printf("joining has completed") @@ -1678,9 +1701,11 @@ func (c *Cluster) nodeJoin(node *Node) error { return nil } - // Don't do anything else if the cluster already contains the node. - if c.nodeByID(node.ID) != nil { - return nil + // If the cluster already contains the node, just send it the cluster status. + // This is useful in the case where a node is restarted or temporarily leaves + // the cluster. + if node := c.nodeByID(node.ID); node != nil { + return c.sendTo(node, c.Status()) } // If the holder does not yet contain data, go ahead and add the node. diff --git a/internal/private.pb.go b/internal/private.pb.go index 4d2bcdd08..37b109014 100644 --- a/internal/private.pb.go +++ b/internal/private.pb.go @@ -34,6 +34,7 @@ URI Node NodeStateMessage + NodeEventMessage NodeStatus ClusterStatus Field @@ -797,6 +798,30 @@ func (m *NodeStateMessage) GetState() string { return "" } +type NodeEventMessage struct { + Event uint32 `protobuf:"varint,1,opt,name=Event,proto3" json:"Event,omitempty"` + Node *Node `protobuf:"bytes,2,opt,name=Node" json:"Node,omitempty"` +} + +func (m *NodeEventMessage) Reset() { *m = NodeEventMessage{} } +func (m *NodeEventMessage) String() string { return proto.CompactTextString(m) } +func (*NodeEventMessage) ProtoMessage() {} +func (*NodeEventMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{25} } + +func (m *NodeEventMessage) GetEvent() uint32 { + if m != nil { + return m.Event + } + return 0 +} + +func (m *NodeEventMessage) GetNode() *Node { + if m != nil { + return m.Node + } + return nil +} + type NodeStatus struct { Node *Node `protobuf:"bytes,1,opt,name=Node" json:"Node,omitempty"` MaxSlices *MaxSlices `protobuf:"bytes,2,opt,name=MaxSlices" json:"MaxSlices,omitempty"` @@ -806,7 +831,7 @@ type NodeStatus struct { func (m *NodeStatus) Reset() { *m = NodeStatus{} } func (m *NodeStatus) String() string { return proto.CompactTextString(m) } func (*NodeStatus) ProtoMessage() {} -func (*NodeStatus) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{25} } +func (*NodeStatus) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{26} } func (m *NodeStatus) GetNode() *Node { if m != nil { @@ -838,7 +863,7 @@ type ClusterStatus struct { func (m *ClusterStatus) Reset() { *m = ClusterStatus{} } func (m *ClusterStatus) String() string { return proto.CompactTextString(m) } func (*ClusterStatus) ProtoMessage() {} -func (*ClusterStatus) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{26} } +func (*ClusterStatus) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{27} } func (m *ClusterStatus) GetClusterID() string { if m != nil { @@ -871,7 +896,7 @@ type Field struct { func (m *Field) Reset() { *m = Field{} } func (m *Field) String() string { return proto.CompactTextString(m) } func (*Field) ProtoMessage() {} -func (*Field) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{27} } +func (*Field) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{28} } func (m *Field) GetName() string { if m != nil { @@ -910,7 +935,7 @@ type CreateViewMessage struct { func (m *CreateViewMessage) Reset() { *m = CreateViewMessage{} } func (m *CreateViewMessage) String() string { return proto.CompactTextString(m) } func (*CreateViewMessage) ProtoMessage() {} -func (*CreateViewMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{28} } +func (*CreateViewMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{29} } func (m *CreateViewMessage) GetIndex() string { if m != nil { @@ -942,7 +967,7 @@ type DeleteViewMessage struct { func (m *DeleteViewMessage) Reset() { *m = DeleteViewMessage{} } func (m *DeleteViewMessage) String() string { return proto.CompactTextString(m) } func (*DeleteViewMessage) ProtoMessage() {} -func (*DeleteViewMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{29} } +func (*DeleteViewMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{30} } func (m *DeleteViewMessage) GetIndex() string { if m != nil { @@ -977,7 +1002,7 @@ type ResizeInstruction struct { func (m *ResizeInstruction) Reset() { *m = ResizeInstruction{} } func (m *ResizeInstruction) String() string { return proto.CompactTextString(m) } func (*ResizeInstruction) ProtoMessage() {} -func (*ResizeInstruction) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{30} } +func (*ResizeInstruction) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{31} } func (m *ResizeInstruction) GetJobID() int64 { if m != nil { @@ -1032,7 +1057,7 @@ type ResizeSource struct { func (m *ResizeSource) Reset() { *m = ResizeSource{} } func (m *ResizeSource) String() string { return proto.CompactTextString(m) } func (*ResizeSource) ProtoMessage() {} -func (*ResizeSource) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{31} } +func (*ResizeSource) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{32} } func (m *ResizeSource) GetNode() *Node { if m != nil { @@ -1079,7 +1104,7 @@ func (m *ResizeInstructionComplete) Reset() { *m = ResizeInstructionComp func (m *ResizeInstructionComplete) String() string { return proto.CompactTextString(m) } func (*ResizeInstructionComplete) ProtoMessage() {} func (*ResizeInstructionComplete) Descriptor() ([]byte, []int) { - return fileDescriptorPrivate, []int{32} + return fileDescriptorPrivate, []int{33} } func (m *ResizeInstructionComplete) GetJobID() int64 { @@ -1110,7 +1135,7 @@ type SetCoordinatorMessage struct { func (m *SetCoordinatorMessage) Reset() { *m = SetCoordinatorMessage{} } func (m *SetCoordinatorMessage) String() string { return proto.CompactTextString(m) } func (*SetCoordinatorMessage) ProtoMessage() {} -func (*SetCoordinatorMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{33} } +func (*SetCoordinatorMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{34} } func (m *SetCoordinatorMessage) GetNew() *Node { if m != nil { @@ -1127,7 +1152,7 @@ type Topology struct { func (m *Topology) Reset() { *m = Topology{} } func (m *Topology) String() string { return proto.CompactTextString(m) } func (*Topology) ProtoMessage() {} -func (*Topology) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{34} } +func (*Topology) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{35} } func (m *Topology) GetClusterID() string { if m != nil { @@ -1149,7 +1174,7 @@ type RecalculateCaches struct { func (m *RecalculateCaches) Reset() { *m = RecalculateCaches{} } func (m *RecalculateCaches) String() string { return proto.CompactTextString(m) } func (*RecalculateCaches) ProtoMessage() {} -func (*RecalculateCaches) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{35} } +func (*RecalculateCaches) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{36} } func init() { proto.RegisterType((*IndexMeta)(nil), "internal.IndexMeta") @@ -1177,6 +1202,7 @@ func init() { proto.RegisterType((*URI)(nil), "internal.URI") proto.RegisterType((*Node)(nil), "internal.Node") proto.RegisterType((*NodeStateMessage)(nil), "internal.NodeStateMessage") + proto.RegisterType((*NodeEventMessage)(nil), "internal.NodeEventMessage") proto.RegisterType((*NodeStatus)(nil), "internal.NodeStatus") proto.RegisterType((*ClusterStatus)(nil), "internal.ClusterStatus") proto.RegisterType((*Field)(nil), "internal.Field") @@ -2187,6 +2213,39 @@ func (m *NodeStateMessage) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *NodeEventMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *NodeEventMessage) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Event != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.Event)) + } + if m.Node != nil { + dAtA[i] = 0x12 + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.Node.Size())) + n13, err := m.Node.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n13 + } + return i, nil +} + func (m *NodeStatus) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2206,32 +2265,32 @@ func (m *NodeStatus) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0xa i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Node.Size())) - n13, err := m.Node.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n13 - } - if m.MaxSlices != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintPrivate(dAtA, i, uint64(m.MaxSlices.Size())) - n14, err := m.MaxSlices.MarshalTo(dAtA[i:]) + n14, err := m.Node.MarshalTo(dAtA[i:]) if err != nil { return 0, err } i += n14 } - if m.Schema != nil { - dAtA[i] = 0x1a + if m.MaxSlices != nil { + dAtA[i] = 0x12 i++ - i = encodeVarintPrivate(dAtA, i, uint64(m.Schema.Size())) - n15, err := m.Schema.MarshalTo(dAtA[i:]) + i = encodeVarintPrivate(dAtA, i, uint64(m.MaxSlices.Size())) + n15, err := m.MaxSlices.MarshalTo(dAtA[i:]) if err != nil { return 0, err } i += n15 } + if m.Schema != nil { + dAtA[i] = 0x1a + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.Schema.Size())) + n16, err := m.Schema.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n16 + } return i, nil } @@ -2413,21 +2472,21 @@ func (m *ResizeInstruction) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0x12 i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Node.Size())) - n16, err := m.Node.MarshalTo(dAtA[i:]) + n17, err := m.Node.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n16 + i += n17 } if m.Coordinator != nil { dAtA[i] = 0x1a i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Coordinator.Size())) - n17, err := m.Coordinator.MarshalTo(dAtA[i:]) + n18, err := m.Coordinator.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n17 + i += n18 } if len(m.Sources) > 0 { for _, msg := range m.Sources { @@ -2445,21 +2504,21 @@ func (m *ResizeInstruction) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0x2a i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Schema.Size())) - n18, err := m.Schema.MarshalTo(dAtA[i:]) + n19, err := m.Schema.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n18 + i += n19 } if m.ClusterStatus != nil { dAtA[i] = 0x32 i++ i = encodeVarintPrivate(dAtA, i, uint64(m.ClusterStatus.Size())) - n19, err := m.ClusterStatus.MarshalTo(dAtA[i:]) + n20, err := m.ClusterStatus.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n19 + i += n20 } return i, nil } @@ -2483,11 +2542,11 @@ func (m *ResizeSource) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0xa i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Node.Size())) - n20, err := m.Node.MarshalTo(dAtA[i:]) + n21, err := m.Node.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n20 + i += n21 } if len(m.Index) > 0 { dAtA[i] = 0x12 @@ -2539,11 +2598,11 @@ func (m *ResizeInstructionComplete) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0x12 i++ i = encodeVarintPrivate(dAtA, i, uint64(m.Node.Size())) - n21, err := m.Node.MarshalTo(dAtA[i:]) + n22, err := m.Node.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n21 + i += n22 } if len(m.Error) > 0 { dAtA[i] = 0x1a @@ -2573,11 +2632,11 @@ func (m *SetCoordinatorMessage) MarshalTo(dAtA []byte) (int, error) { dAtA[i] = 0xa i++ i = encodeVarintPrivate(dAtA, i, uint64(m.New.Size())) - n22, err := m.New.MarshalTo(dAtA[i:]) + n23, err := m.New.MarshalTo(dAtA[i:]) if err != nil { return 0, err } - i += n22 + i += n23 } return i, nil } @@ -3106,6 +3165,19 @@ func (m *NodeStateMessage) Size() (n int) { return n } +func (m *NodeEventMessage) Size() (n int) { + var l int + _ = l + if m.Event != 0 { + n += 1 + sovPrivate(uint64(m.Event)) + } + if m.Node != nil { + l = m.Node.Size() + n += 1 + l + sovPrivate(uint64(l)) + } + return n +} + func (m *NodeStatus) Size() (n int) { var l int _ = l @@ -6745,6 +6817,108 @@ func (m *NodeStateMessage) Unmarshal(dAtA []byte) error { } return nil } +func (m *NodeEventMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: NodeEventMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NodeEventMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Event", wireType) + } + m.Event = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Event |= (uint32(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Node", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivate + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Node == nil { + m.Node = &Node{} + } + if err := m.Node.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivate(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrivate + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *NodeStatus) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -8354,87 +8528,88 @@ var ( func init() { proto.RegisterFile("private.proto", fileDescriptorPrivate) } var fileDescriptorPrivate = []byte{ - // 1306 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0x66, 0xbd, 0xb6, 0x63, 0x1f, 0xd7, 0xa9, 0x33, 0x4d, 0x83, 0x13, 0x45, 0xae, 0x19, 0x15, - 0x1a, 0x2a, 0x11, 0x15, 0x57, 0x42, 0x34, 0xa8, 0x52, 0x89, 0xed, 0xaa, 0x0b, 0x24, 0x94, 0x71, - 0x1a, 0x24, 0x24, 0x90, 0x26, 0xf6, 0x90, 0xae, 0xb2, 0xde, 0x35, 0xbb, 0xe3, 0x24, 0xee, 0x05, - 0x97, 0x08, 0x09, 0x71, 0x8f, 0xb8, 0xe5, 0x65, 0xb8, 0xe4, 0x11, 0x50, 0x78, 0x08, 0x24, 0x6e, - 0x40, 0xf3, 0xb7, 0xbb, 0xfe, 0x0d, 0x09, 0xdc, 0xed, 0xf9, 0xe6, 0x9c, 0x33, 0xdf, 0x9c, 0xbf, - 0x99, 0x85, 0xf2, 0x20, 0x74, 0x4f, 0x29, 0x67, 0xdb, 0x83, 0x30, 0xe0, 0x01, 0x2a, 0xb8, 0x3e, - 0x67, 0xa1, 0x4f, 0x3d, 0xfc, 0x29, 0x14, 0x1d, 0xbf, 0xc7, 0xce, 0xf7, 0x18, 0xa7, 0xa8, 0x0e, - 0xa5, 0x66, 0xe0, 0x0d, 0xfb, 0xfe, 0x27, 0xf4, 0x88, 0x79, 0x55, 0xab, 0x6e, 0x6d, 0x15, 0x49, - 0x1a,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 0xf1, 0xe8, 0x92, 0xa6, 0xad, 0xc2, 0x92, 0x9a, - 0x49, 0xea, 0x61, 0x50, 0x24, 0x46, 0xc4, 0xb7, 0x44, 0x49, 0x76, 0xa9, 0xd7, 0x1d, 0x7a, 0x94, - 0x33, 0xf9, 0xbf, 0x13, 0xed, 0x56, 0x7e, 0xbd, 0xa8, 0x59, 0xbf, 0x5d, 0xd4, 0xac, 0xdf, 0x2f, - 0x6a, 0xd6, 0x4f, 0x7f, 0xd4, 0x5e, 0x3b, 0xca, 0xcb, 0x3f, 0xeb, 0x87, 0xff, 0x04, 0x00, 0x00, - 0xff, 0xff, 0xd7, 0xef, 0xfa, 0x68, 0x6a, 0x0f, 0x00, 0x00, + // 1325 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0x67, 0xbd, 0xb6, 0x13, 0xbf, 0xd4, 0xa9, 0x33, 0x6d, 0x83, 0x5b, 0x45, 0xae, 0x19, 0x15, + 0x1a, 0x2a, 0x11, 0x95, 0x54, 0x42, 0xb4, 0xa8, 0x52, 0xa9, 0xed, 0xaa, 0x0b, 0x4d, 0x29, 0xe3, + 0xb6, 0x48, 0x48, 0x20, 0x4d, 0xec, 0x21, 0x5d, 0x65, 0xbd, 0x6b, 0x76, 0xc7, 0x49, 0xdc, 0x03, + 0x47, 0x84, 0x84, 0xb8, 0x23, 0xae, 0x7c, 0x19, 0x8e, 0x7c, 0x04, 0x54, 0x3e, 0x04, 0x12, 0x17, + 0xd0, 0xbc, 0x99, 0xd9, 0x5d, 0xff, 0x4b, 0x9a, 0xc0, 0x6d, 0xdf, 0x6f, 0xde, 0x7b, 0xf3, 0x9b, + 0xf7, 0x6f, 0x66, 0xa1, 0x3a, 0x8c, 0xfd, 0x03, 0x2e, 0xc5, 0xd6, 0x30, 0x8e, 0x64, 0x44, 0x96, + 0xfd, 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0x73, 0xe9, 0x3e, 0x5c, 0x9e, 0x49, 0x53, 0x2b, 0x1a, + 0x0c, 0x55, 0x3d, 0xfc, 0x87, 0x74, 0xa9, 0x91, 0x11, 0xc7, 0x26, 0x51, 0x15, 0xa6, 0x05, 0x7a, + 0x1b, 0x2e, 0x75, 0x85, 0xcc, 0x25, 0xc9, 0x56, 0x5b, 0x13, 0xdc, 0xc7, 0xe2, 0x70, 0xc1, 0xf1, + 0xd5, 0x12, 0xbd, 0x0f, 0xcb, 0x4f, 0xa3, 0x61, 0x14, 0x44, 0x7b, 0xe3, 0x13, 0x9a, 0xb6, 0x0e, + 0x4b, 0x7a, 0xc2, 0xe9, 0x67, 0x46, 0x85, 0x59, 0x91, 0x5e, 0x50, 0x25, 0xd9, 0xe3, 0x41, 0x6f, + 0x14, 0x70, 0x29, 0xf0, 0xef, 0x29, 0xb9, 0x5f, 0xfb, 0xed, 0x55, 0xc3, 0xf9, 0xfd, 0x55, 0xc3, + 0xf9, 0xe3, 0x55, 0xc3, 0xf9, 0xf9, 0xcf, 0xc6, 0x1b, 0xbb, 0x65, 0xfc, 0x4f, 0xbf, 0xf5, 0x6f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x30, 0x4b, 0x92, 0xf6, 0xb8, 0x0f, 0x00, 0x00, } diff --git a/internal/private.proto b/internal/private.proto index 5f4a1c6f6..5755ce2f6 100644 --- a/internal/private.proto +++ b/internal/private.proto @@ -144,6 +144,11 @@ message NodeStateMessage { string State = 2; } +message NodeEventMessage { + uint32 Event = 1; + Node Node = 2; +} + message NodeStatus { Node Node = 1; MaxSlices MaxSlices = 2; diff --git a/server.go b/server.go index 0dcca4d1e..c52c28cbd 100644 --- a/server.go +++ b/server.go @@ -463,6 +463,8 @@ func (s *Server) ReceiveMessage(pb proto.Message) error { } case *internal.RecalculateCaches: s.Holder.RecalculateCaches() + case *internal.NodeEventMessage: + s.Cluster.ReceiveEvent(DecodeNodeEvent(obj)) } return nil From 2a462d5e42c0fb413a37e10261a41476d62bdfbe Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Thu, 8 Mar 2018 14:18:10 -0600 Subject: [PATCH 09/20] make sure cluster.Nodes[].IsCoordinator values get updated. return old coordinator node in response. --- broadcast.go | 5 + cluster.go | 53 +++++-- cluster_test.go | 12 +- handler.go | 15 +- internal/private.pb.go | 312 +++++++++++++++++++++++++++++------------ internal/private.proto | 4 + server.go | 2 + 7 files changed, 295 insertions(+), 108 deletions(-) diff --git a/broadcast.go b/broadcast.go index 6dbb0f771..a4e6403c1 100644 --- a/broadcast.go +++ b/broadcast.go @@ -134,6 +134,7 @@ const ( MessageTypeResizeInstruction MessageTypeResizeInstructionComplete MessageTypeSetCoordinator + MessageTypeUpdateCoordinator MessageTypeNodeState MessageTypeRecalculateCaches MessageTypeNodeEvent @@ -173,6 +174,8 @@ func MarshalMessage(m proto.Message) ([]byte, error) { typ = MessageTypeResizeInstructionComplete case *internal.SetCoordinatorMessage: typ = MessageTypeSetCoordinator + case *internal.UpdateCoordinatorMessage: + typ = MessageTypeUpdateCoordinator case *internal.NodeStateMessage: typ = MessageTypeNodeState case *internal.RecalculateCaches: @@ -225,6 +228,8 @@ func UnmarshalMessage(buf []byte) (proto.Message, error) { m = &internal.ResizeInstructionComplete{} case MessageTypeSetCoordinator: m = &internal.SetCoordinatorMessage{} + case MessageTypeUpdateCoordinator: + m = &internal.UpdateCoordinatorMessage{} case MessageTypeNodeState: m = &internal.NodeStateMessage{} case MessageTypeRecalculateCaches: diff --git a/cluster.go b/cluster.go index b93e6105c..a5b7b654f 100644 --- a/cluster.go +++ b/cluster.go @@ -309,20 +309,51 @@ func (c *Cluster) IsCoordinator() bool { return c.Coordinator == c.Node.ID } -// SetCoordinator updates the Coordinator to n. -// Returns true if the Coordinator changed. -func (c *Cluster) SetCoordinator(n *Node) bool { - // Get new node. - newNode := c.nodeByID(n.ID) - if newNode == nil { - return false +// SetCoordinator tells the current node to become the +// Coordinator. In response to this, the current node +// will consider itself coordinator and update the other +// nodes with its version of Cluster.Status. +func (c *Cluster) SetCoordinator(n *Node) error { + // Verify that the new Coordinator value matches + // this node. + if c.Node.ID != n.ID { + return fmt.Errorf("coordinator node does not match this node") } - if c.Coordinator != newNode.ID { - c.Coordinator = newNode.ID - return true + // Update IsCoordinator on all nodes (locally). + _ = c.UpdateCoordinator(n) + + // Send the update coordinator message to all nodes. + err := c.Broadcaster.SendSync( + &internal.UpdateCoordinatorMessage{ + New: EncodeNode(n), + }) + if err != nil { + return fmt.Errorf("problem sending UpdateCoordinator message: %v", err) } - return false + + // Broadcast cluster status. + return c.Broadcaster.SendSync(c.Status()) +} + +// UpdateCoordinator updates this nodes Coordinator value as well as +// changing the corresponding node's IsCoordinator value +// to true, and sets all other nodes to false. Returns true if the value +// changed. +func (c *Cluster) UpdateCoordinator(n *Node) bool { + var changed bool + if c.Coordinator != n.ID { + c.Coordinator = n.ID + changed = true + } + for _, node := range c.Nodes { + if node.ID == n.ID { + node.IsCoordinator = true + } else { + node.IsCoordinator = false + } + } + return changed } // AddNode adds a node to the Cluster and updates and saves the diff --git a/cluster_test.go b/cluster_test.go index 5c5c5f89c..c5c01d58d 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -509,22 +509,22 @@ func TestCluster_ResizeStates(t *testing.T) { } // Ensures that coordinator can be changed. -func TestCluster_SetCoordinator(t *testing.T) { - t.Run("SetCoordinator", func(t *testing.T) { +func TestCluster_UpdateCoordinator(t *testing.T) { + t.Run("UpdateCoordinator", func(t *testing.T) { c := test.NewCluster(2) oldNode := c.Nodes[0] newNode := c.Nodes[1] - // Set coordinator to the same value. - if c.SetCoordinator(oldNode) { + // Update coordinator to the same value. + if c.UpdateCoordinator(oldNode) { t.Errorf("did not expect coordinator to change") } else if c.Coordinator != oldNode.ID { t.Errorf("expected coordinator: %s, but got: %s", c.Coordinator, oldNode.URI) } - // Set coordinator to a new value. - if !c.SetCoordinator(newNode) { + // Update coordinator to a new value. + if !c.UpdateCoordinator(newNode) { t.Errorf("expected coordinator to change") } else if c.Coordinator != newNode.ID { t.Errorf("expected coordinator: %s, but got: %s", c.Coordinator, newNode.URI) diff --git a/handler.go b/handler.go index 38fd24eca..cea42e6ac 100644 --- a/handler.go +++ b/handler.go @@ -2026,6 +2026,7 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r return } + oldNode := h.Cluster.nodeByID(h.Cluster.Coordinator) newNode := h.Cluster.nodeByID(req.ID) if newNode == nil { http.Error(w, "Node with provided ID does not exist", http.StatusBadRequest) @@ -2033,8 +2034,14 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r } if err := func() error { - // Send the set-coordinator message to all nodes. - err := h.Broadcaster.SendSync( + // If the new coordinator is this node, do the SetCoordinator directly. + if newNode.ID == h.Node.ID { + return h.Cluster.SetCoordinator(newNode) + } + + // Send the set-coordinator message to new node. + err := h.Broadcaster.SendTo( + newNode, &internal.SetCoordinatorMessage{ New: EncodeNode(newNode), }) @@ -2042,9 +2049,6 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r return fmt.Errorf("problem sending SetCoordinator message: %s", err) } - // Set Coordinator on local node. - _ = h.Cluster.SetCoordinator(newNode) - return nil }(); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -2053,6 +2057,7 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r // Encode response. if err := json.NewEncoder(w).Encode(setCoordinatorResponse{ + Old: oldNode, New: newNode, }); err != nil { h.logger().Printf("response encoding error: %s", err) diff --git a/internal/private.pb.go b/internal/private.pb.go index 37b109014..1b7f71ac4 100644 --- a/internal/private.pb.go +++ b/internal/private.pb.go @@ -44,6 +44,7 @@ ResizeSource ResizeInstructionComplete SetCoordinatorMessage + UpdateCoordinatorMessage Topology RecalculateCaches */ @@ -1144,6 +1145,22 @@ func (m *SetCoordinatorMessage) GetNew() *Node { return nil } +type UpdateCoordinatorMessage struct { + New *Node `protobuf:"bytes,1,opt,name=New" json:"New,omitempty"` +} + +func (m *UpdateCoordinatorMessage) Reset() { *m = UpdateCoordinatorMessage{} } +func (m *UpdateCoordinatorMessage) String() string { return proto.CompactTextString(m) } +func (*UpdateCoordinatorMessage) ProtoMessage() {} +func (*UpdateCoordinatorMessage) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{35} } + +func (m *UpdateCoordinatorMessage) GetNew() *Node { + if m != nil { + return m.New + } + return nil +} + type Topology struct { ClusterID string `protobuf:"bytes,1,opt,name=ClusterID,proto3" json:"ClusterID,omitempty"` NodeIDs []string `protobuf:"bytes,2,rep,name=NodeIDs" json:"NodeIDs,omitempty"` @@ -1152,7 +1169,7 @@ type Topology struct { func (m *Topology) Reset() { *m = Topology{} } func (m *Topology) String() string { return proto.CompactTextString(m) } func (*Topology) ProtoMessage() {} -func (*Topology) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{35} } +func (*Topology) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{36} } func (m *Topology) GetClusterID() string { if m != nil { @@ -1174,7 +1191,7 @@ type RecalculateCaches struct { func (m *RecalculateCaches) Reset() { *m = RecalculateCaches{} } func (m *RecalculateCaches) String() string { return proto.CompactTextString(m) } func (*RecalculateCaches) ProtoMessage() {} -func (*RecalculateCaches) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{36} } +func (*RecalculateCaches) Descriptor() ([]byte, []int) { return fileDescriptorPrivate, []int{37} } func init() { proto.RegisterType((*IndexMeta)(nil), "internal.IndexMeta") @@ -1212,6 +1229,7 @@ func init() { proto.RegisterType((*ResizeSource)(nil), "internal.ResizeSource") proto.RegisterType((*ResizeInstructionComplete)(nil), "internal.ResizeInstructionComplete") proto.RegisterType((*SetCoordinatorMessage)(nil), "internal.SetCoordinatorMessage") + proto.RegisterType((*UpdateCoordinatorMessage)(nil), "internal.UpdateCoordinatorMessage") proto.RegisterType((*Topology)(nil), "internal.Topology") proto.RegisterType((*RecalculateCaches)(nil), "internal.RecalculateCaches") } @@ -2641,6 +2659,34 @@ func (m *SetCoordinatorMessage) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *UpdateCoordinatorMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UpdateCoordinatorMessage) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.New != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintPrivate(dAtA, i, uint64(m.New.Size())) + n24, err := m.New.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n24 + } + return i, nil +} + func (m *Topology) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -3355,6 +3401,16 @@ func (m *SetCoordinatorMessage) Size() (n int) { return n } +func (m *UpdateCoordinatorMessage) Size() (n int) { + var l int + _ = l + if m.New != nil { + l = m.New.Size() + n += 1 + l + sovPrivate(uint64(l)) + } + return n +} + func (m *Topology) Size() (n int) { var l int _ = l @@ -8262,6 +8318,89 @@ func (m *SetCoordinatorMessage) Unmarshal(dAtA []byte) error { } return nil } +func (m *UpdateCoordinatorMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UpdateCoordinatorMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UpdateCoordinatorMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field New", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrivate + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrivate + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.New == nil { + m.New = &Node{} + } + if err := m.New.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrivate(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPrivate + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Topology) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -8528,88 +8667,89 @@ var ( func init() { proto.RegisterFile("private.proto", fileDescriptorPrivate) } var fileDescriptorPrivate = []byte{ - // 1325 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0x67, 0xbd, 0xb6, 0x13, 0xbf, 0xd4, 0xa9, 0x33, 0x6d, 0x83, 0x5b, 0x45, 0xae, 0x19, 0x15, - 0x1a, 0x2a, 0x11, 0x95, 0x54, 0x42, 0xb4, 0xa8, 0x52, 0xa9, 0xed, 0xaa, 0x0b, 0x4d, 0x29, 0xe3, - 0xb6, 0x48, 0x48, 0x20, 0x4d, 0xec, 0x21, 0x5d, 0x65, 0xbd, 0x6b, 0x76, 0xc7, 0x49, 0xdc, 0x03, - 0x47, 0x84, 0x84, 0xb8, 0x23, 0xae, 0x7c, 0x19, 0x8e, 0x7c, 0x04, 0x54, 0x3e, 0x04, 0x12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xac, 0x6c, 0xbf, 0x99, 0x19, 0x4c, 0x2c, 0xb3, 0x49, 0x6d, 0xfa, 0x83, 0x03, - 0xe7, 0xf2, 0x14, 0x5e, 0xab, 0x31, 0xd2, 0x8c, 0x14, 0xe6, 0x66, 0xc4, 0x9d, 0x97, 0x91, 0x62, - 0x96, 0x91, 0xec, 0x9d, 0x5b, 0xca, 0xbd, 0x73, 0xe9, 0x3e, 0x5c, 0x9e, 0x49, 0x53, 0x2b, 0x1a, - 0x0c, 0x55, 0x3d, 0xfc, 0x87, 0x74, 0xa9, 0x91, 0x11, 0xc7, 0x26, 0x51, 0x15, 0xa6, 0x05, 0x7a, - 0x1b, 0x2e, 0x75, 0x85, 0xcc, 0x25, 0xc9, 0x56, 0x5b, 0x13, 0xdc, 0xc7, 0xe2, 0x70, 0xc1, 0xf1, - 0xd5, 0x12, 0xbd, 0x0f, 0xcb, 0x4f, 0xa3, 0x61, 0x14, 0x44, 0x7b, 0xe3, 0x13, 0x9a, 0xb6, 0x0e, - 0x4b, 0x7a, 0xc2, 0xe9, 0x67, 0x46, 0x85, 0x59, 0x91, 0x5e, 0x50, 0x25, 0xd9, 0xe3, 0x41, 0x6f, - 0x14, 0x70, 0x29, 0xf0, 0xef, 0x29, 0xb9, 0x5f, 0xfb, 0xed, 0x55, 0xc3, 0xf9, 0xfd, 0x55, 0xc3, - 0xf9, 0xe3, 0x55, 0xc3, 0xf9, 0xf9, 0xcf, 0xc6, 0x1b, 0xbb, 0x65, 0xfc, 0x4f, 0xbf, 0xf5, 0x6f, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x30, 0x4b, 0x92, 0xf6, 0xb8, 0x0f, 0x00, 0x00, + // 1334 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x5d, 0x6f, 0x1b, 0x45, + 0x17, 0x7e, 0xd7, 0x6b, 0x3b, 0xf6, 0x71, 0x9c, 0x38, 0xd3, 0x34, 0xaf, 0x13, 0x45, 0xae, 0x19, + 0x15, 0x1a, 0x2a, 0x11, 0x95, 0x54, 0x42, 0x34, 0x50, 0xa9, 0xc4, 0x76, 0xd5, 0x85, 0x26, 0x94, + 0x71, 0x12, 0x24, 0x24, 0x90, 0x26, 0xf6, 0x90, 0xae, 0xb2, 0xde, 0x35, 0xbb, 0xe3, 0x24, 0xee, + 0x05, 0x97, 0x08, 0x09, 0x71, 0x8f, 0xb8, 0xe5, 0xcf, 0x70, 0xc9, 0x4f, 0x40, 0xe1, 0x47, 0x20, + 0x71, 0x03, 0x9a, 0xaf, 0xdd, 0xf5, 0x57, 0xd2, 0x04, 0xee, 0xf6, 0x3c, 0x73, 0xce, 0x99, 0x67, + 0xce, 0xd7, 0xcc, 0x42, 0xb9, 0x1f, 0xba, 0xa7, 0x94, 0xb3, 0xcd, 0x7e, 0x18, 0xf0, 0x00, 0x15, + 0x5c, 0x9f, 0xb3, 0xd0, 0xa7, 0x1e, 0xfe, 0x14, 0x8a, 0x8e, 0xdf, 0x65, 0xe7, 0xbb, 0x8c, 0x53, + 0x54, 0x87, 0x52, 0x23, 0xf0, 0x06, 0x3d, 0xff, 0x39, 0x3d, 0x62, 0x5e, 0xd5, 0xaa, 0x5b, 0x1b, + 0x45, 0x92, 0x86, 0x84, 0xc6, 0xbe, 0xdb, 0x63, 0x9f, 0x0d, 0xa8, 0xcf, 0x07, 0xbd, 0x6a, 0x46, + 0x69, 0xa4, 0x20, 0xfc, 0x97, 0x05, 0xc5, 0xa7, 0x21, 0xed, 0x31, 0xe9, 0x71, 0x0d, 0x0a, 0x24, + 0x38, 0x4b, 0xbb, 0x8b, 0x65, 0xf4, 0x16, 0x2c, 0x38, 0xfe, 0x29, 0x0b, 0x23, 0xd6, 0xf2, 0xe9, + 0x91, 0xc7, 0xba, 0xd2, 0x5d, 0x81, 0x8c, 0xa1, 0x68, 0x1d, 0x8a, 0x0d, 0xda, 0x79, 0xc9, 0xf6, + 0x87,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c8, 0x0b, 0x2c, + 0xde, 0x4e, 0x4b, 0xf2, 0xde, 0x13, 0x7a, 0x66, 0x00, 0x4a, 0x01, 0x3f, 0x57, 0x1e, 0x5a, 0xa7, + 0xcc, 0xe7, 0xa9, 0x28, 0x49, 0x59, 0x3a, 0x28, 0x13, 0x25, 0x20, 0xac, 0x8e, 0xa2, 0x39, 0x2f, + 0x24, 0x9c, 0x05, 0x4a, 0xe4, 0x1a, 0xfe, 0xd1, 0x02, 0x30, 0x84, 0x06, 0x51, 0x6c, 0x62, 0xcd, + 0x36, 0x41, 0xef, 0xa6, 0xde, 0x2e, 0x93, 0x33, 0x35, 0x5e, 0x22, 0xa9, 0x17, 0xce, 0x86, 0x19, + 0xa1, 0xba, 0x38, 0x2a, 0x89, 0xbe, 0xc2, 0x75, 0x9a, 0xc4, 0xb5, 0x59, 0x6e, 0x78, 0x83, 0x88, + 0xb3, 0x50, 0x33, 0x12, 0x6f, 0x2c, 0x05, 0xc4, 0xf1, 0x49, 0x80, 0xe9, 0x21, 0x42, 0x77, 0x21, + 0x27, 0x98, 0x9a, 0x39, 0x30, 0x7e, 0x0c, 0xb5, 0x88, 0xdb, 0xfa, 0x26, 0x99, 0x3a, 0x7b, 0x10, + 0x64, 0xe5, 0x8b, 0x5a, 0x97, 0x8b, 0x7c, 0x4c, 0x57, 0xc0, 0xde, 0x75, 0x55, 0x7d, 0xdb, 0x44, + 0x7c, 0x4a, 0x84, 0x9e, 0xcb, 0xfe, 0x13, 0x08, 0x15, 0x6f, 0x89, 0x25, 0xd5, 0x40, 0xe2, 0xee, + 0xb8, 0xc9, 0xfd, 0x66, 0x1e, 0xa5, 0x76, 0xea, 0x51, 0xda, 0x86, 0x25, 0xd5, 0x24, 0xff, 0xa5, + 0xd3, 0x9f, 0x33, 0xb0, 0x44, 0x58, 0xe4, 0xbe, 0x62, 0x8e, 0x1f, 0xf1, 0x70, 0x10, 0x0f, 0xb8, + 0x8f, 0x83, 0x23, 0x1d, 0x6a, 0x9b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0x59, 0x3f, 0xfd, + 0x51, 0xfb, 0xdf, 0x51, 0x5e, 0xfe, 0xe5, 0x3f, 0xfc, 0x27, 0x00, 0x00, 0xff, 0xff, 0x66, 0x19, + 0x3d, 0xd2, 0xf6, 0x0f, 0x00, 0x00, } diff --git a/internal/private.proto b/internal/private.proto index 5755ce2f6..8642d9a13 100644 --- a/internal/private.proto +++ b/internal/private.proto @@ -207,6 +207,10 @@ message SetCoordinatorMessage { Node New = 1; } +message UpdateCoordinatorMessage { + Node New = 1; +} + message Topology { string ClusterID = 1; repeated string NodeIDs = 2; diff --git a/server.go b/server.go index c52c28cbd..531609278 100644 --- a/server.go +++ b/server.go @@ -456,6 +456,8 @@ func (s *Server) ReceiveMessage(pb proto.Message) error { } case *internal.SetCoordinatorMessage: s.Cluster.SetCoordinator(DecodeNode(obj.New)) + case *internal.UpdateCoordinatorMessage: + s.Cluster.UpdateCoordinator(DecodeNode(obj.New)) case *internal.NodeStateMessage: err := s.Cluster.ReceiveNodeState(obj.NodeID, obj.State) if err != nil { From 510c64ef0649df4905cfe4c8353b148d8bcf9c85 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Mon, 12 Mar 2018 16:32:35 -0500 Subject: [PATCH 10/20] Move diagnostics into package pilosa --- broadcast.go | 8 +- diagnostics/diagnostics.go => diagnostics.go | 103 +++++++++--------- ...diagnostics_test.go => diagnostics_test.go | 41 +++---- gc.go | 4 +- server.go | 43 +------- 5 files changed, 77 insertions(+), 122 deletions(-) rename diagnostics/diagnostics.go => diagnostics.go (73%) rename diagnostics/diagnostics_test.go => diagnostics_test.go (83%) diff --git a/broadcast.go b/broadcast.go index a4e6403c1..de43f3b85 100644 --- a/broadcast.go +++ b/broadcast.go @@ -63,17 +63,17 @@ var NopBroadcaster Broadcaster type nopBroadcaster struct{} -// SendSync A no-op implemenetation of Broadcaster SendSync method. +// SendSync A no-op implementation of Broadcaster SendSync method. func (n *nopBroadcaster) SendSync(pb proto.Message) error { return nil } -// SendAsync A no-op implemenetation of Broadcaster SendAsync method. +// SendAsync A no-op implementation of Broadcaster SendAsync method. func (n *nopBroadcaster) SendAsync(pb proto.Message) error { return nil } -// SendTo is a no-op implemenetation of Broadcaster SendTo method. +// SendTo is a no-op implementation of Broadcaster SendTo method. func (c *nopBroadcaster) SendTo(to *Node, pb proto.Message) error { return nil } @@ -112,7 +112,7 @@ var NopGossiper Gossiper type nopGossiper struct{} -// SendAsync A no-op implemenetation of Gossiper SendAsync method. +// SendAsync A no-op implementation of Gossiper SendAsync method. func (n *nopGossiper) SendAsync(pb proto.Message) error { return nil } diff --git a/diagnostics/diagnostics.go b/diagnostics.go similarity index 73% rename from diagnostics/diagnostics.go rename to diagnostics.go index 60248d6bb..602e910e0 100644 --- a/diagnostics/diagnostics.go +++ b/diagnostics.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package diagnostics +package pilosa import ( "bytes" @@ -36,7 +36,7 @@ import ( // Default version check URL. const ( - DefaultVersionCheckURL = "https://diagnostics.pilosa.com/v0/version" + defaultVersionCheckURL = "https://diagnostics.pilosa.com/v0/version" ) type versionResponse struct { @@ -44,11 +44,9 @@ type versionResponse struct { Message string `json:"message"` } -// Diagnostics represents a client to the Pilosa cluster. -type Diagnostics struct { +// DiagnosticsCollector represents a collector/sender of diagnostics data +type DiagnosticsCollector struct { mu sync.Mutex - wg sync.WaitGroup - closing chan struct{} host string VersionURL string version string @@ -65,13 +63,12 @@ type Diagnostics struct { logOutput io.Writer } -// New returns a pointer to a new Diagnostics Client given an addr in the format "hostname:port". -func New(host string) *Diagnostics { +// New returns a pointer to a new DiagnosticsCollector Client given an addr in the format "hostname:port". +func NewDiagnosticsCollector(host string) *DiagnosticsCollector { - return &Diagnostics{ - closing: make(chan struct{}), + return &DiagnosticsCollector{ host: host, - VersionURL: DefaultVersionCheckURL, + VersionURL: defaultVersionCheckURL, startTime: time.Now().Unix(), start: time.Now(), client: http.DefaultClient, @@ -81,37 +78,21 @@ func New(host string) *Diagnostics { } // SetVersion of locally running Pilosa Cluster to check against master. -func (d *Diagnostics) SetVersion(v string) { +func (d *DiagnosticsCollector) SetVersion(v string) { d.version = v d.Set("Version", v) } // SetInterval of the diagnostic go routine and match with the circuit breaker timeout. -func (d *Diagnostics) SetInterval(i time.Duration) { +func (d *DiagnosticsCollector) SetInterval(i time.Duration) { d.interval = i } -// schedule start the diagnostics service ticker. -func (d *Diagnostics) schedule() { - ticker := time.NewTicker(d.interval) - defer ticker.Stop() - - for { - select { - case <-d.closing: - return - case <-ticker.C: - d.CheckVersion() - d.Flush() - } - } -} - // Flush sends the current metrics. -func (d *Diagnostics) Flush() error { +func (d *DiagnosticsCollector) Flush() error { d.mu.Lock() d.metrics["Uptime"] = (time.Now().Unix() - d.startTime) - buf, _ := d.Encode() + buf, _ := d.encode() d.mu.Unlock() _, err := d.cb.Execute(func() (interface{}, error) { @@ -135,7 +116,7 @@ func (d *Diagnostics) Flush() error { } // Open configures the circuit breaker used by the HTTP client. -func (d *Diagnostics) Open() { +func (d *DiagnosticsCollector) Open() { var st gobreaker.Settings if d.interval > 0 { st.Timeout = d.interval * 2 @@ -145,15 +126,8 @@ func (d *Diagnostics) Open() { d.logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every hour. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics") } -// Close notify goroutine to stop. -func (d *Diagnostics) Close() error { - close(d.closing) - d.wg.Wait() - return nil -} - // CheckVersion of the local build against Pilosa master. -func (d *Diagnostics) CheckVersion() error { +func (d *DiagnosticsCollector) CheckVersion() error { var rsp versionResponse req, err := http.NewRequest("GET", d.VersionURL, nil) resp, err := d.client.Do(req) @@ -174,15 +148,15 @@ func (d *Diagnostics) CheckVersion() error { } d.lastVersion = rsp.Version - if err := d.CompareVersion(rsp.Version); err != nil { + if err := d.compareVersion(rsp.Version); err != nil { d.logger().Printf("%s\n", err.Error()) } return nil } -// CompareVersion check version strings. -func (d *Diagnostics) CompareVersion(value string) error { +// compareVersion check version strings. +func (d *DiagnosticsCollector) compareVersion(value string) error { currentVersion := VersionSegments(value) localVersion := VersionSegments(d.version) @@ -198,29 +172,29 @@ func (d *Diagnostics) CompareVersion(value string) error { } // Encode metrics maps into the json message format. -func (d *Diagnostics) Encode() ([]byte, error) { +func (d *DiagnosticsCollector) encode() ([]byte, error) { return json.Marshal(d.metrics) } // Set adds a key value metric. -func (d *Diagnostics) Set(name string, value interface{}) { +func (d *DiagnosticsCollector) Set(name string, value interface{}) { d.mu.Lock() defer d.mu.Unlock() d.metrics[name] = value } // SetLogger Set the logger output type. -func (d *Diagnostics) SetLogger(logger io.Writer) { +func (d *DiagnosticsCollector) SetLogger(logger io.Writer) { d.logOutput = logger } // logger returns a logger that writes to LogOutput. -func (d *Diagnostics) logger() *log.Logger { +func (d *DiagnosticsCollector) logger() *log.Logger { return log.New(d.logOutput, "", log.LstdFlags) } // EnrichWithOSInfo adds OS information to the diagnostics payload. -func (d *Diagnostics) EnrichWithOSInfo() { +func (d *DiagnosticsCollector) EnrichWithOSInfo() { osInfo, err := host.Info() if err != nil { d.logOutput.Write([]byte(err.Error())) @@ -243,7 +217,7 @@ func (d *Diagnostics) EnrichWithOSInfo() { } // EnrichWithMemoryInfo adds memory information to the diagnostics payload. -func (d *Diagnostics) EnrichWithMemoryInfo() { +func (d *DiagnosticsCollector) EnrichWithMemoryInfo() { memory, err := mem.VirtualMemory() if err != nil { d.logOutput.Write([]byte(err.Error())) @@ -254,6 +228,37 @@ func (d *Diagnostics) EnrichWithMemoryInfo() { } +// EnrichWithSchemaProperties adds schema info to the diagnostics payload. +func (d *DiagnosticsCollector) EnrichWithSchemaProperties(holder *Holder) { + var numSlices uint64 + numFrames := 0 + numIndexes := 0 + bsiFieldCount := 0 + timeQuantumEnabled := false + + for _, index := range holder.Indexes() { + numSlices += index.MaxSlice() + 1 + numIndexes += 1 + for _, frame := range index.Frames() { + numFrames += 1 + if frame.rangeEnabled { + if fields, err := frame.GetFields(); err == nil { + bsiFieldCount += len(fields) + } + } + if frame.TimeQuantum() != "" { + timeQuantumEnabled = true + } + } + } + + d.Set("NumIndexes", numIndexes) + d.Set("NumFrames", numFrames) + d.Set("NumSlices", numSlices) + d.Set("BSIFieldCount", bsiFieldCount) + d.Set("TimeQuantumEnabled", timeQuantumEnabled) +} + // VersionSegments returns the numeric segments of the version as a slice of ints. func VersionSegments(segments string) []int { segments = strings.Trim(segments, "v") diff --git a/diagnostics/diagnostics_test.go b/diagnostics_test.go similarity index 83% rename from diagnostics/diagnostics_test.go rename to diagnostics_test.go index 8f85a57db..9d8e35d76 100644 --- a/diagnostics/diagnostics_test.go +++ b/diagnostics_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package diagnostics_test +package pilosa import ( "encoding/json" @@ -23,25 +23,21 @@ import ( "runtime" "strings" "testing" - - "github.com/pilosa/pilosa/diagnostics" ) func TestDiagnosticsClient(t *testing.T) { // Mock server. server := httptest.NewServer(nil) - defer server.Close() // Create a new client. - d := diagnostics.New(server.URL) + d := NewDiagnosticsCollector(server.URL) d.SetLogger(ioutil.Discard) d.Open() - defer d.Close() d.Set("gg", 10) d.Set("ss", "ss") - data, err := d.Encode() + data, err := d.encode() if err != nil { t.Fatal(err) } @@ -58,7 +54,7 @@ func TestDiagnosticsClient(t *testing.T) { // Test the metrics after a flush. d.Flush() - data, err = d.Encode() + data, err = d.encode() if err != nil { t.Fatal(err) } @@ -74,7 +70,7 @@ func TestDiagnosticsClient(t *testing.T) { func TestDiagnosticsVersion_Parse(t *testing.T) { version := "0.1.1" - vs := diagnostics.VersionSegments(version) + vs := VersionSegments(version) output := []int{0, 1, 1} if !reflect.DeepEqual(vs, output) { @@ -83,35 +79,34 @@ func TestDiagnosticsVersion_Parse(t *testing.T) { } func TestDiagnosticsVersion_Compare(t *testing.T) { - d := diagnostics.New("localhost:10101") + d := NewDiagnosticsCollector("localhost:10101") d.Open() - defer d.Close() version := "v0.1.1" d.SetVersion(version) - err := d.CompareVersion("v1.7.0") + err := d.compareVersion("v1.7.0") if !strings.Contains(err.Error(), "A newer version") { t.Fatalf("Expected a newer version is available, actual error: %s", err) } - err = d.CompareVersion("1.7.0") + err = d.compareVersion("1.7.0") if !strings.Contains(err.Error(), "A newer version") { t.Fatalf("Expected a newer version is available, actual error: %s", err) } - err = d.CompareVersion("0.7.0") + err = d.compareVersion("0.7.0") if !strings.Contains(err.Error(), "The latest Minor release is") { t.Fatalf("Expected Minor Version Missmatch, actual error: %s", err) } - err = d.CompareVersion("0.1.2") + err = d.compareVersion("0.1.2") if !strings.Contains(err.Error(), "There is a new patch release of Pilosa") { t.Fatalf("Expected Patch Version Missmatch, actual error: %s", err) } - err = d.CompareVersion("0.1.1") + err = d.compareVersion("0.1.1") if err != nil { t.Fatalf("Versions should match") } d.SetVersion("v1.7.0") - err = d.CompareVersion("0.7.2") + err = d.compareVersion("0.7.2") if err != nil { t.Fatalf("Local version is greater") } @@ -125,11 +120,9 @@ func TestDiagnosticsVersion_Check(t *testing.T) { Version: "1.1.1", }) })) - defer server.Close() // Create a new client. - d := diagnostics.New("localhost:10101") - defer d.Close() + d := NewDiagnosticsCollector("localhost:10101") version := "0.1.1" d.SetVersion(version) @@ -138,10 +131,6 @@ func TestDiagnosticsVersion_Check(t *testing.T) { d.CheckVersion() } -type versionResponse struct { - Version string `json:"version"` -} - func compareJSON(a, b []byte) (bool, error) { var j1, j2 interface{} if err := json.Unmarshal(a, &j1); err != nil { @@ -156,12 +145,10 @@ func compareJSON(a, b []byte) (bool, error) { func BenchmarkDiagnostics(b *testing.B) { // Mock server. server := httptest.NewServer(nil) - defer server.Close() // Create a new client. - d := diagnostics.New(server.URL) + d := NewDiagnosticsCollector(server.URL) d.SetLogger(ioutil.Discard) - defer d.Close() prev := runtime.GOMAXPROCS(4) defer runtime.GOMAXPROCS(prev) diff --git a/gc.go b/gc.go index a260cc0b5..3f036bdcd 100644 --- a/gc.go +++ b/gc.go @@ -29,10 +29,10 @@ var NopGCNotifier GCNotifier type nopGCNotifier struct{} -// Close is a no-op implemenetation of GCNotifier Close method. +// Close is a no-op implementation of GCNotifier Close method. func (n *nopGCNotifier) Close() {} -// AfterGC is a no-op implemenetation of GCNotifier AfterGC method. +// AfterGC is a no-op implementation of GCNotifier AfterGC method. func (c *nopGCNotifier) AfterGC() <-chan struct{} { return nil } diff --git a/server.go b/server.go index 531609278..82ca2db2d 100644 --- a/server.go +++ b/server.go @@ -32,7 +32,6 @@ import ( "time" "github.com/gogo/protobuf/proto" - "github.com/pilosa/pilosa/diagnostics" "github.com/pilosa/pilosa/internal" "golang.org/x/sync/errgroup" @@ -70,7 +69,7 @@ type Server struct { NodeID string URI URI Cluster *Cluster - diagnostics *diagnostics.Diagnostics + diagnostics *DiagnosticsCollector GCNotifier GCNotifier @@ -100,7 +99,7 @@ func NewServer() *Server { Handler: NewHandler(), Broadcaster: NopBroadcaster, BroadcastReceiver: NopBroadcastReceiver, - diagnostics: diagnostics.New(DefaultDiagnosticServer), + diagnostics: NewDiagnosticsCollector(DefaultDiagnosticServer), Network: "tcp", @@ -622,13 +621,13 @@ func (s *Server) monitorDiagnostics() { // Flush the diagnostics metrics at startup, then on each tick interval flush := func() { - enrichDiagnosticsWithSchemaProperties(s.diagnostics, s.Holder) openFiles, err := CountOpenFiles() if err == nil { s.diagnostics.Set("OpenFiles", openFiles) } s.diagnostics.Set("GoRoutines", runtime.NumGoroutine()) s.diagnostics.EnrichWithMemoryInfo() + s.diagnostics.EnrichWithSchemaProperties(s.Holder) s.diagnostics.CheckVersion() s.diagnostics.Flush() } @@ -725,39 +724,3 @@ type StatusHandler interface { ClusterStatus() (proto.Message, error) HandleRemoteStatus(proto.Message) error } - -type diagnosticsFrameProperties struct { - BSIFieldCount int - TimeQuantumEnabled bool -} - -func enrichDiagnosticsWithSchemaProperties(d *diagnostics.Diagnostics, holder *Holder) { - // NOTE: this function is not in the diagnostics package, since circular imports are not allowed. - var numSlices uint64 - numFrames := 0 - numIndexes := 0 - bsiFieldCount := 0 - timeQuantumEnabled := false - - for _, index := range holder.Indexes() { - numSlices += index.MaxSlice() + 1 - numIndexes += 1 - for _, frame := range index.Frames() { - numFrames += 1 - if frame.rangeEnabled { - if fields, err := frame.GetFields(); err == nil { - bsiFieldCount += len(fields) - } - } - if frame.TimeQuantum() != "" { - timeQuantumEnabled = true - } - } - } - - d.Set("NumIndexes", numIndexes) - d.Set("NumFrames", numFrames) - d.Set("NumSlices", numSlices) - d.Set("BSIFieldCount", bsiFieldCount) - d.Set("TimeQuantumEnabled", timeQuantumEnabled) -} From f4c1e0c492f772b979279f591461f825c7980151 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 13 Mar 2018 11:41:45 -0500 Subject: [PATCH 11/20] Refactor gopsutil into SystemInfo interface/subpackage for dependency injection. --- diagnostics.go | 131 ++++++++++++++++++++++++++++++++--------- gc.go | 3 + gopsutil/systeminfo.go | 116 ++++++++++++++++++++++++++++++++++++ server.go | 5 +- server/server.go | 2 + 5 files changed, 227 insertions(+), 30 deletions(-) create mode 100644 gopsutil/systeminfo.go diff --git a/diagnostics.go b/diagnostics.go index 602e910e0..a4caf84cd 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -27,13 +27,9 @@ import ( "sync" "time" - "github.com/shirou/gopsutil/host" - "github.com/shirou/gopsutil/mem" "github.com/sony/gobreaker" ) -// TODO: unique Cluster ID - // Default version check URL. const ( defaultVersionCheckURL = "https://diagnostics.pilosa.com/v0/version" @@ -61,6 +57,8 @@ type DiagnosticsCollector struct { cb *gobreaker.CircuitBreaker logOutput io.Writer + + server *Server } // New returns a pointer to a new DiagnosticsCollector Client given an addr in the format "hostname:port". @@ -193,50 +191,64 @@ func (d *DiagnosticsCollector) logger() *log.Logger { return log.New(d.logOutput, "", log.LstdFlags) } +// logErr logs the error and returns true if an error exists +func (d *DiagnosticsCollector) logErr(err error) bool { + if err != nil { + d.logOutput.Write([]byte(err.Error())) + return true + } + return false +} + // EnrichWithOSInfo adds OS information to the diagnostics payload. func (d *DiagnosticsCollector) EnrichWithOSInfo() { - osInfo, err := host.Info() - if err != nil { - d.logOutput.Write([]byte(err.Error())) + uptime, err := d.server.SystemInfo.Uptime() + if !d.logErr(err) { + d.Set("HostUptime", uptime) } - d.Set("HostUptime", osInfo.Uptime) - - platform, family, version, err := host.PlatformInformation() - if err != nil { - d.logOutput.Write([]byte(err.Error())) + platform, err := d.server.SystemInfo.Platform() + if !d.logErr(err) { + d.Set("OSPlatform", platform) } - d.Set("OSPlatform", platform) - d.Set("OSFamily", family) - d.Set("OSVersion", version) - - kernelVersion, err := host.KernelVersion() - if err != nil { - d.logOutput.Write([]byte(err.Error())) + family, err := d.server.SystemInfo.Family() + if !d.logErr(err) { + d.Set("OSFamily", family) + } + version, err := d.server.SystemInfo.OSVersion() + if !d.logErr(err) { + d.Set("OSVersion", version) + } + kernelVersion, err := d.server.SystemInfo.KernelVersion() + if !d.logErr(err) { + d.Set("OSKernelVersion", kernelVersion) } - d.Set("OSKernelVersion", kernelVersion) } // EnrichWithMemoryInfo adds memory information to the diagnostics payload. func (d *DiagnosticsCollector) EnrichWithMemoryInfo() { - memory, err := mem.VirtualMemory() - if err != nil { - d.logOutput.Write([]byte(err.Error())) + memFree, err := d.server.SystemInfo.MemFree() + if !d.logErr(err) { + d.Set("MemFree", memFree) + } + memTotal, err := d.server.SystemInfo.MemTotal() + if !d.logErr(err) { + d.Set("MemTotal", memTotal) + } + memUsed, err := d.server.SystemInfo.MemUsed() + if !d.logErr(err) { + d.Set("MemUsed", memUsed) } - d.Set("MemFree", memory.Free) - d.Set("MemTotal", memory.Total) - d.Set("MemUsed", memory.Used) - } // EnrichWithSchemaProperties adds schema info to the diagnostics payload. -func (d *DiagnosticsCollector) EnrichWithSchemaProperties(holder *Holder) { +func (d *DiagnosticsCollector) EnrichWithSchemaProperties() { var numSlices uint64 numFrames := 0 numIndexes := 0 bsiFieldCount := 0 timeQuantumEnabled := false - for _, index := range holder.Indexes() { + for _, index := range d.server.Holder.Indexes() { numSlices += index.MaxSlice() + 1 numIndexes += 1 for _, frame := range index.Frames() { @@ -270,3 +282,64 @@ func VersionSegments(segments string) []int { } return segmentSlice } + +// SystemInfo collects information about the host OS +type SystemInfo interface { + Uptime() (uint64, error) + Platform() (string, error) + Family() (string, error) + OSVersion() (string, error) + KernelVersion() (string, error) + MemFree() (uint64, error) + MemTotal() (uint64, error) + MemUsed() (uint64, error) +} + +// NewNopSystemInfo creates a no-op implementation of SystemInfo +func NewNopSystemInfo() *NopSystemInfo { + return &NopSystemInfo{} +} + +// NopSystemInfo is a no-op implementation of SystemInfo +type NopSystemInfo struct { +} + +// Uptime is a no-op implementation of SystemInfo.Uptime +func (n *NopSystemInfo) Uptime() (uint64, error) { + return 0, nil +} + +// Platform is a no-op implementation of SystemInfo.Platform +func (n *NopSystemInfo) Platform() (string, error) { + return "", nil +} + +// Family is a no-op implementation of SystemInfo.Family +func (n *NopSystemInfo) Family() (string, error) { + return "", nil +} + +// OSVersion is a no-op implementation of SystemInfo.OSVersion +func (n *NopSystemInfo) OSVersion() (string, error) { + return "", nil +} + +// KernelVersion is a no-op implementation of SystemInfo.KernelVersion +func (n *NopSystemInfo) KernelVersion() (string, error) { + return "", nil +} + +// MemFree is a no-op implementation of SystemInfo.MemFree +func (n *NopSystemInfo) MemFree() (uint64, error) { + return 0, nil +} + +// MemTotal is a no-op implementation of SystemInfo.MemTotal +func (n *NopSystemInfo) MemTotal() (uint64, error) { + return 0, nil +} + +// MemUsed is a no-op implementation of SystemInfo.MemUsed +func (n *NopSystemInfo) MemUsed() (uint64, error) { + return 0, nil +} diff --git a/gc.go b/gc.go index 3f036bdcd..23dd0f0d0 100644 --- a/gc.go +++ b/gc.go @@ -14,6 +14,9 @@ package pilosa +// Ensure nopGCNotifier implements interface. +var _ GCNotifier = &nopGCNotifier{} + // GCNotifier represents an interface for garbage collection notificationss. type GCNotifier interface { Close() diff --git a/gopsutil/systeminfo.go b/gopsutil/systeminfo.go new file mode 100644 index 000000000..12c300ba5 --- /dev/null +++ b/gopsutil/systeminfo.go @@ -0,0 +1,116 @@ +package gopsutil + +import ( + "github.com/pilosa/pilosa" + "github.com/shirou/gopsutil/host" + "github.com/shirou/gopsutil/mem" +) + +var _ pilosa.SystemInfo = NewSystemInfo() + +// SystemInfo is an implementation of pilosa.SystemInfo that uses gopsutil to collect information about the host OS +type SystemInfo struct { + hostInfo *host.InfoStat + memInfo *mem.VirtualMemoryStat + platform string + family string + osVersion string +} + +// Uptime returns the system uptime in seconds +func (s *SystemInfo) Uptime() (uptime uint64, err error) { + if s.hostInfo == nil { + s.hostInfo, err = host.Info() + if err != nil { + return 0, err + } + } + return s.hostInfo.Uptime, nil +} + +// Uptime returns the system platform +func (s *SystemInfo) Platform() (string, error) { + err := s.collectPlatformInfo() + if err != nil { + return "", err + } + return s.platform, nil +} + +// Family returns the system family +func (s *SystemInfo) Family() (string, error) { + err := s.collectPlatformInfo() + if err != nil { + return "", err + } + return s.family, err +} + +// OSVersion returns the OS Version +func (s *SystemInfo) OSVersion() (string, error) { + err := s.collectPlatformInfo() + if err != nil { + return "", err + } + return s.osVersion, err +} + +// collectPlatformInfo fetches and caches system platform information +func (s *SystemInfo) collectPlatformInfo() error { + var err error + if s.platform == "" { + s.platform, s.family, s.osVersion, err = host.PlatformInformation() + if err != nil { + return err + } + } + return nil +} + +// collectMemoryInfo fetches and caches memory stats +func (s *SystemInfo) collectMemoryInfo() (err error) { + if s.memInfo == nil { + s.memInfo, err = mem.VirtualMemory() + if err != nil { + return err + } + } + return nil +} + +// MemFree returns the amount of free memory in bytes +func (s *SystemInfo) MemFree() (uint64, error) { + err := s.collectMemoryInfo() + if err != nil { + return 0, err + } + return s.memInfo.Free, err +} + +// MemFree returns the amount of total memory in bytes +func (s *SystemInfo) MemTotal() (uint64, error) { + err := s.collectMemoryInfo() + if err != nil { + return 0, err + } + return s.memInfo.Total, err +} + +// MemFree returns the amount of used memory in bytes +func (s *SystemInfo) MemUsed() (uint64, error) { + err := s.collectMemoryInfo() + if err != nil { + return 0, err + } + return s.memInfo.Used, err +} + +// KernelVersion returns the kernel version as a string +func (s *SystemInfo) KernelVersion() (string, error) { + return host.KernelVersion() +} + +// NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo +func NewSystemInfo() *SystemInfo { + return &SystemInfo{} +} diff --git a/server.go b/server.go index 82ca2db2d..bd0611041 100644 --- a/server.go +++ b/server.go @@ -70,6 +70,7 @@ type Server struct { URI URI Cluster *Cluster diagnostics *DiagnosticsCollector + SystemInfo SystemInfo GCNotifier GCNotifier @@ -100,6 +101,7 @@ func NewServer() *Server { Broadcaster: NopBroadcaster, BroadcastReceiver: NopBroadcastReceiver, diagnostics: NewDiagnosticsCollector(DefaultDiagnosticServer), + SystemInfo: NewNopSystemInfo(), Network: "tcp", @@ -114,6 +116,7 @@ func NewServer() *Server { s.logger = log.New(s.LogOutput, "", log.LstdFlags) s.Handler.Holder = s.Holder + s.diagnostics.server = s return s } @@ -627,7 +630,7 @@ func (s *Server) monitorDiagnostics() { } s.diagnostics.Set("GoRoutines", runtime.NumGoroutine()) s.diagnostics.EnrichWithMemoryInfo() - s.diagnostics.EnrichWithSchemaProperties(s.Holder) + s.diagnostics.EnrichWithSchemaProperties() s.diagnostics.CheckVersion() s.diagnostics.Flush() } diff --git a/server/server.go b/server/server.go index 240b8b16b..eac98121d 100644 --- a/server/server.go +++ b/server/server.go @@ -34,6 +34,7 @@ import ( "github.com/pilosa/pilosa" "github.com/pilosa/pilosa/gcnotify" + "github.com/pilosa/pilosa/gopsutil" "github.com/pilosa/pilosa/gossip" "github.com/pilosa/pilosa/statsd" ) @@ -152,6 +153,7 @@ func (m *Command) SetupServer() error { if m.Config.Metric.Diagnostics { m.Server.DiagnosticInterval = time.Duration(DefaultDiagnosticsInterval) } + m.Server.SystemInfo = gopsutil.NewSystemInfo() m.Server.GCNotifier = gcnotify.NewActiveGCNotifier() m.Server.Holder.Stats, err = NewStatsClient(m.Config.Metric.Service, m.Config.Metric.Host) if err != nil { From c2444870c6835c6e5d4cf785f001f23610391617 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 13 Mar 2018 12:27:49 -0500 Subject: [PATCH 12/20] Remove gobreaker dep and add HTTP timeout --- Gopkg.lock | 6 ----- diagnostics.go | 60 ++++++++++++++------------------------------- diagnostics_test.go | 2 -- server.go | 12 ++++++--- 4 files changed, 27 insertions(+), 53 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c77dc951a..af6174c08 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -205,12 +205,6 @@ packages = ["."] revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" -[[projects]] - name = "github.com/sony/gobreaker" - packages = ["."] - revision = "e9556a45379ef1da12e54847edb2fb3d7d566f36" - version = "0.3.0" - [[projects]] branch = "master" name = "github.com/spf13/afero" diff --git a/diagnostics.go b/diagnostics.go index a4caf84cd..1abcdd144 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -26,8 +26,6 @@ import ( "strings" "sync" "time" - - "github.com/sony/gobreaker" ) // Default version check URL. @@ -52,10 +50,8 @@ type DiagnosticsCollector struct { metrics map[string]interface{} - client *http.Client - interval time.Duration + client *http.Client - cb *gobreaker.CircuitBreaker logOutput io.Writer server *Server @@ -69,7 +65,7 @@ func NewDiagnosticsCollector(host string) *DiagnosticsCollector { VersionURL: defaultVersionCheckURL, startTime: time.Now().Unix(), start: time.Now(), - client: http.DefaultClient, + client: &http.Client{Timeout: 10 * time.Second}, metrics: make(map[string]interface{}), logOutput: ioutil.Discard, } @@ -81,47 +77,29 @@ func (d *DiagnosticsCollector) SetVersion(v string) { d.Set("Version", v) } -// SetInterval of the diagnostic go routine and match with the circuit breaker timeout. -func (d *DiagnosticsCollector) SetInterval(i time.Duration) { - d.interval = i -} - // Flush sends the current metrics. func (d *DiagnosticsCollector) Flush() error { d.mu.Lock() + defer d.mu.Unlock() d.metrics["Uptime"] = (time.Now().Unix() - d.startTime) - buf, _ := d.encode() - d.mu.Unlock() - - _, err := d.cb.Execute(func() (interface{}, error) { - req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf)) - req.Header.Set("Content-Type", "application/json") - resp, err := d.client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - // TODO verify response - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - return body, nil - }) - - return err -} - -// Open configures the circuit breaker used by the HTTP client. -func (d *DiagnosticsCollector) Open() { - var st gobreaker.Settings - if d.interval > 0 { - st.Timeout = d.interval * 2 + buf, err := d.encode() + if err != nil { + return err } - d.cb = gobreaker.NewCircuitBreaker(st) + req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf)) + req.Header.Set("Content-Type", "application/json") + resp, err := d.client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() - d.logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every hour. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics") + // TODO verify response + _, err = ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + return nil } // CheckVersion of the local build against Pilosa master. diff --git a/diagnostics_test.go b/diagnostics_test.go index 9d8e35d76..7b66d8e18 100644 --- a/diagnostics_test.go +++ b/diagnostics_test.go @@ -32,7 +32,6 @@ func TestDiagnosticsClient(t *testing.T) { // Create a new client. d := NewDiagnosticsCollector(server.URL) d.SetLogger(ioutil.Discard) - d.Open() d.Set("gg", 10) d.Set("ss", "ss") @@ -80,7 +79,6 @@ func TestDiagnosticsVersion_Parse(t *testing.T) { func TestDiagnosticsVersion_Compare(t *testing.T) { d := NewDiagnosticsCollector("localhost:10101") - d.Open() version := "v0.1.1" d.SetVersion(version) diff --git a/server.go b/server.go index bd0611041..dd8811463 100644 --- a/server.go +++ b/server.go @@ -605,15 +605,16 @@ func (s *Server) mergeRemoteStatus(ns *internal.NodeStatus) error { // monitorDiagnostics periodically polls the Pilosa Indexes for cluster info. func (s *Server) monitorDiagnostics() { - if s.DiagnosticInterval <= 0 { + // Do not send more than once a minute + if s.DiagnosticInterval < time.Minute { s.Logger().Printf("diagnostics disabled") return + } else { + s.Logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every hour. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics") } s.diagnostics.SetLogger(s.LogOutput) s.diagnostics.SetVersion(Version) - s.diagnostics.SetInterval(s.DiagnosticInterval) - s.diagnostics.Open() s.diagnostics.Set("Host", s.URI.host) s.diagnostics.Set("Cluster", strings.Join(s.Cluster.NodeIDs(), ",")) s.diagnostics.Set("NumNodes", len(s.Cluster.Nodes)) @@ -632,7 +633,10 @@ func (s *Server) monitorDiagnostics() { s.diagnostics.EnrichWithMemoryInfo() s.diagnostics.EnrichWithSchemaProperties() s.diagnostics.CheckVersion() - s.diagnostics.Flush() + err = s.diagnostics.Flush() + if err != nil { + s.Logger().Printf("Diagnostics error: %s", err) + } } ticker := time.NewTicker(s.DiagnosticInterval) From 88471e94f197e5c6064042bc03eb8f91b9bd2ed7 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 14 Mar 2018 15:34:33 -0500 Subject: [PATCH 13/20] Remove caching (the lib code is fast) and add tests --- gopsutil/systeminfo.go | 55 ++++++++++++------------------- gopsutil/systeminfo_test.go | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 gopsutil/systeminfo_test.go diff --git a/gopsutil/systeminfo.go b/gopsutil/systeminfo.go index 12c300ba5..433aacc30 100644 --- a/gopsutil/systeminfo.go +++ b/gopsutil/systeminfo.go @@ -10,8 +10,6 @@ var _ pilosa.SystemInfo = NewSystemInfo() // SystemInfo is an implementation of pilosa.SystemInfo that uses gopsutil to collect information about the host OS type SystemInfo struct { - hostInfo *host.InfoStat - memInfo *mem.VirtualMemoryStat platform string family string osVersion string @@ -19,13 +17,23 @@ type SystemInfo struct { // Uptime returns the system uptime in seconds func (s *SystemInfo) Uptime() (uptime uint64, err error) { - if s.hostInfo == nil { - s.hostInfo, err = host.Info() + hostInfo, err := host.Info() + if err != nil { + return 0, err + } + return hostInfo.Uptime, nil +} + +// collectPlatformInfo fetches and caches system platform information +func (s *SystemInfo) collectPlatformInfo() error { + var err error + if s.platform == "" { + s.platform, s.family, s.osVersion, err = host.PlatformInformation() if err != nil { - return 0, err + return err } } - return s.hostInfo.Uptime, nil + return nil } // Uptime returns the system platform @@ -55,54 +63,31 @@ func (s *SystemInfo) OSVersion() (string, error) { return s.osVersion, err } -// collectPlatformInfo fetches and caches system platform information -func (s *SystemInfo) collectPlatformInfo() error { - var err error - if s.platform == "" { - s.platform, s.family, s.osVersion, err = host.PlatformInformation() - if err != nil { - return err - } - } - return nil -} - -// collectMemoryInfo fetches and caches memory stats -func (s *SystemInfo) collectMemoryInfo() (err error) { - if s.memInfo == nil { - s.memInfo, err = mem.VirtualMemory() - if err != nil { - return err - } - } - return nil -} - // MemFree returns the amount of free memory in bytes func (s *SystemInfo) MemFree() (uint64, error) { - err := s.collectMemoryInfo() + memInfo, err := mem.VirtualMemory() if err != nil { return 0, err } - return s.memInfo.Free, err + return memInfo.Free, err } // MemFree returns the amount of total memory in bytes func (s *SystemInfo) MemTotal() (uint64, error) { - err := s.collectMemoryInfo() + memInfo, err := mem.VirtualMemory() if err != nil { return 0, err } - return s.memInfo.Total, err + return memInfo.Total, err } // MemFree returns the amount of used memory in bytes func (s *SystemInfo) MemUsed() (uint64, error) { - err := s.collectMemoryInfo() + memInfo, err := mem.VirtualMemory() if err != nil { return 0, err } - return s.memInfo.Used, err + return memInfo.Used, err } // KernelVersion returns the kernel version as a string diff --git a/gopsutil/systeminfo_test.go b/gopsutil/systeminfo_test.go new file mode 100644 index 000000000..41b58ec1c --- /dev/null +++ b/gopsutil/systeminfo_test.go @@ -0,0 +1,64 @@ +package gopsutil_test + +import ( + "log" + "runtime" + "testing" + + "github.com/pilosa/pilosa" + "github.com/pilosa/pilosa/gopsutil" +) + +func TestSystemInfo(t *testing.T) { + var systemInfo pilosa.SystemInfo = gopsutil.NewSystemInfo() + + // Uptime()(uint64, error) + // Platform()(string, error) + // Family()(string, error) + // OSVersion()(string, error) + // KernelVersion()(string, error) + // MemFree()(uint64, error) + // MemTotal()(uint64, error) + // MemUsed()(uint64, error) + // + uptime, err := systemInfo.Uptime() + if err != nil || uptime == 0 { + t.Fatalf("Error collecting uptime (error: %v)", err) + } + + platform, err := systemInfo.Platform() + if err != nil || platform != runtime.GOOS { + t.Fatalf("Platform must be %s. (error: %v)", runtime.GOOS, err) + } + + family, err := systemInfo.Family() + if err != nil { + t.Fatalf("Error getting OS family. (family: %v, error: %v)", family, err) + } + + osversion, err := systemInfo.OSVersion() + if err != nil { + t.Fatalf("Error getting OS version. (osversion: %v, error: %v)", osversion, err) + } + + kernelversion, err := systemInfo.KernelVersion() + if err != nil { + t.Fatalf("Error getting kernel version. (kernelversion: %v, error: %v)", kernelversion, err) + } + + memfree, err := systemInfo.MemFree() + if err != nil { + t.Fatalf("Error getting memfree. (memfree: %v, error: %v)", memfree, err) + } + + memused, err := systemInfo.MemUsed() + if err != nil { + t.Fatalf("Error getting memused. (memused: %v, error: %v)", memused, err) + } + + memtotal, err := systemInfo.MemTotal() + log.Println(memtotal) + if err != nil { + t.Fatalf("Error getting memtotal. (memtotal: %v, error: %v)", memtotal, err) + } +} From 20dc1212f8d62f8e7db7eca49abc046ce85811f6 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 14 Mar 2018 16:51:40 -0500 Subject: [PATCH 14/20] Address code review (mostly comments) --- diagnostics.go | 37 +++++++++---------- ...cs_test.go => diagnostics_internal_test.go | 2 +- gopsutil/systeminfo.go | 22 +++++------ 3 files changed, 30 insertions(+), 31 deletions(-) rename diagnostics_test.go => diagnostics_internal_test.go (99%) diff --git a/diagnostics.go b/diagnostics.go index 1abcdd144..710f66c2d 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -38,7 +38,7 @@ type versionResponse struct { Message string `json:"message"` } -// DiagnosticsCollector represents a collector/sender of diagnostics data +// DiagnosticsCollector represents a collector/sender of diagnostics data. type DiagnosticsCollector struct { mu sync.Mutex host string @@ -57,9 +57,8 @@ type DiagnosticsCollector struct { server *Server } -// New returns a pointer to a new DiagnosticsCollector Client given an addr in the format "hostname:port". +// NewDiagnosticsCollector returns a new DiagnosticsCollector given an addr in the format "hostname:port". func NewDiagnosticsCollector(host string) *DiagnosticsCollector { - return &DiagnosticsCollector{ host: host, VersionURL: defaultVersionCheckURL, @@ -118,7 +117,7 @@ func (d *DiagnosticsCollector) CheckVersion() error { return fmt.Errorf("json decode: %s", err) } - // Same a version as last test + // If version has not changed since the last check, return if rsp.Version == d.lastVersion { return nil } @@ -133,8 +132,8 @@ func (d *DiagnosticsCollector) CheckVersion() error { // compareVersion check version strings. func (d *DiagnosticsCollector) compareVersion(value string) error { - currentVersion := VersionSegments(value) - localVersion := VersionSegments(d.version) + currentVersion := versionSegments(value) + localVersion := versionSegments(d.version) if localVersion[0] < currentVersion[0] { //Major return fmt.Errorf("Warning: You are running Pilosa %s. A newer version (%s) is available: https://github.com/pilosa/pilosa/releases", d.version, value) @@ -249,8 +248,8 @@ func (d *DiagnosticsCollector) EnrichWithSchemaProperties() { d.Set("TimeQuantumEnabled", timeQuantumEnabled) } -// VersionSegments returns the numeric segments of the version as a slice of ints. -func VersionSegments(segments string) []int { +// versionSegments returns the numeric segments of the version as a slice of ints. +func versionSegments(segments string) []int { segments = strings.Trim(segments, "v") segments = strings.Split(segments, "-")[0] s := strings.Split(segments, ".") @@ -261,7 +260,7 @@ func VersionSegments(segments string) []int { return segmentSlice } -// SystemInfo collects information about the host OS +// SystemInfo collects information about the host OS. type SystemInfo interface { Uptime() (uint64, error) Platform() (string, error) @@ -273,51 +272,51 @@ type SystemInfo interface { MemUsed() (uint64, error) } -// NewNopSystemInfo creates a no-op implementation of SystemInfo +// NewNopSystemInfo creates a no-op implementation of SystemInfo. func NewNopSystemInfo() *NopSystemInfo { return &NopSystemInfo{} } -// NopSystemInfo is a no-op implementation of SystemInfo +// NopSystemInfo is a no-op implementation of SystemInfo. type NopSystemInfo struct { } -// Uptime is a no-op implementation of SystemInfo.Uptime +// Uptime is a no-op implementation of SystemInfo.Uptime. func (n *NopSystemInfo) Uptime() (uint64, error) { return 0, nil } -// Platform is a no-op implementation of SystemInfo.Platform +// Platform is a no-op implementation of SystemInfo.Platform. func (n *NopSystemInfo) Platform() (string, error) { return "", nil } -// Family is a no-op implementation of SystemInfo.Family +// Family is a no-op implementation of SystemInfo.Family. func (n *NopSystemInfo) Family() (string, error) { return "", nil } -// OSVersion is a no-op implementation of SystemInfo.OSVersion +// OSVersion is a no-op implementation of SystemInfo.OSVersion. func (n *NopSystemInfo) OSVersion() (string, error) { return "", nil } -// KernelVersion is a no-op implementation of SystemInfo.KernelVersion +// KernelVersion is a no-op implementation of SystemInfo.KernelVersion. func (n *NopSystemInfo) KernelVersion() (string, error) { return "", nil } -// MemFree is a no-op implementation of SystemInfo.MemFree +// MemFree is a no-op implementation of SystemInfo.MemFree. func (n *NopSystemInfo) MemFree() (uint64, error) { return 0, nil } -// MemTotal is a no-op implementation of SystemInfo.MemTotal +// MemTotal is a no-op implementation of SystemInfo.MemTotal. func (n *NopSystemInfo) MemTotal() (uint64, error) { return 0, nil } -// MemUsed is a no-op implementation of SystemInfo.MemUsed +// MemUsed is a no-op implementation of SystemInfo.MemUsed. func (n *NopSystemInfo) MemUsed() (uint64, error) { return 0, nil } diff --git a/diagnostics_test.go b/diagnostics_internal_test.go similarity index 99% rename from diagnostics_test.go rename to diagnostics_internal_test.go index 7b66d8e18..eb2498297 100644 --- a/diagnostics_test.go +++ b/diagnostics_internal_test.go @@ -69,7 +69,7 @@ func TestDiagnosticsClient(t *testing.T) { func TestDiagnosticsVersion_Parse(t *testing.T) { version := "0.1.1" - vs := VersionSegments(version) + vs := versionSegments(version) output := []int{0, 1, 1} if !reflect.DeepEqual(vs, output) { diff --git a/gopsutil/systeminfo.go b/gopsutil/systeminfo.go index 433aacc30..e6285ade8 100644 --- a/gopsutil/systeminfo.go +++ b/gopsutil/systeminfo.go @@ -8,14 +8,14 @@ import ( var _ pilosa.SystemInfo = NewSystemInfo() -// SystemInfo is an implementation of pilosa.SystemInfo that uses gopsutil to collect information about the host OS +// SystemInfo is an implementation of pilosa.SystemInfo that uses gopsutil to collect information about the host OS. type SystemInfo struct { platform string family string osVersion string } -// Uptime returns the system uptime in seconds +// Uptime returns the system uptime in seconds. func (s *SystemInfo) Uptime() (uptime uint64, err error) { hostInfo, err := host.Info() if err != nil { @@ -24,7 +24,7 @@ func (s *SystemInfo) Uptime() (uptime uint64, err error) { return hostInfo.Uptime, nil } -// collectPlatformInfo fetches and caches system platform information +// collectPlatformInfo fetches and caches system platform information. func (s *SystemInfo) collectPlatformInfo() error { var err error if s.platform == "" { @@ -36,7 +36,7 @@ func (s *SystemInfo) collectPlatformInfo() error { return nil } -// Uptime returns the system platform +// Platform returns the system platform. func (s *SystemInfo) Platform() (string, error) { err := s.collectPlatformInfo() if err != nil { @@ -45,7 +45,7 @@ func (s *SystemInfo) Platform() (string, error) { return s.platform, nil } -// Family returns the system family +// Family returns the system family. func (s *SystemInfo) Family() (string, error) { err := s.collectPlatformInfo() if err != nil { @@ -54,7 +54,7 @@ func (s *SystemInfo) Family() (string, error) { return s.family, err } -// OSVersion returns the OS Version +// OSVersion returns the OS Version. func (s *SystemInfo) OSVersion() (string, error) { err := s.collectPlatformInfo() if err != nil { @@ -63,7 +63,7 @@ func (s *SystemInfo) OSVersion() (string, error) { return s.osVersion, err } -// MemFree returns the amount of free memory in bytes +// MemFree returns the amount of free memory in bytes. func (s *SystemInfo) MemFree() (uint64, error) { memInfo, err := mem.VirtualMemory() if err != nil { @@ -72,7 +72,7 @@ func (s *SystemInfo) MemFree() (uint64, error) { return memInfo.Free, err } -// MemFree returns the amount of total memory in bytes +// MemTotal returns the amount of total memory in bytes. func (s *SystemInfo) MemTotal() (uint64, error) { memInfo, err := mem.VirtualMemory() if err != nil { @@ -81,7 +81,7 @@ func (s *SystemInfo) MemTotal() (uint64, error) { return memInfo.Total, err } -// MemFree returns the amount of used memory in bytes +// MemUsed returns the amount of used memory in bytes. func (s *SystemInfo) MemUsed() (uint64, error) { memInfo, err := mem.VirtualMemory() if err != nil { @@ -90,12 +90,12 @@ func (s *SystemInfo) MemUsed() (uint64, error) { return memInfo.Used, err } -// KernelVersion returns the kernel version as a string +// KernelVersion returns the kernel version as a string. func (s *SystemInfo) KernelVersion() (string, error) { return host.KernelVersion() } -// NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo +// NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo. func NewSystemInfo() *SystemInfo { return &SystemInfo{} } From 2d425e32e91aa9385631bbba7a5f6b6f8ca3286e Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 14 Mar 2018 17:33:54 -0500 Subject: [PATCH 15/20] Log platform --- gopsutil/systeminfo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gopsutil/systeminfo_test.go b/gopsutil/systeminfo_test.go index 41b58ec1c..4131942a2 100644 --- a/gopsutil/systeminfo_test.go +++ b/gopsutil/systeminfo_test.go @@ -28,7 +28,7 @@ func TestSystemInfo(t *testing.T) { platform, err := systemInfo.Platform() if err != nil || platform != runtime.GOOS { - t.Fatalf("Platform must be %s. (error: %v)", runtime.GOOS, err) + t.Fatalf("Platform must be %s. (platform: %v, error: %v)", platform, runtime.GOOS, err) } family, err := systemInfo.Family() From 680acf4e3dc175a6199f4cefdcb4afdd06440c93 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 14 Mar 2018 17:41:44 -0500 Subject: [PATCH 16/20] Fix error on linux --- gopsutil/systeminfo_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gopsutil/systeminfo_test.go b/gopsutil/systeminfo_test.go index 4131942a2..5d96a499c 100644 --- a/gopsutil/systeminfo_test.go +++ b/gopsutil/systeminfo_test.go @@ -2,7 +2,6 @@ package gopsutil_test import ( "log" - "runtime" "testing" "github.com/pilosa/pilosa" @@ -27,8 +26,8 @@ func TestSystemInfo(t *testing.T) { } platform, err := systemInfo.Platform() - if err != nil || platform != runtime.GOOS { - t.Fatalf("Platform must be %s. (platform: %v, error: %v)", platform, runtime.GOOS, err) + if err != nil { + t.Fatalf("Error getting platform. (platform: %v, error: %v)", platform, err) } family, err := systemInfo.Family() From 754de2e057e53026d6f09faf94cd3d8da733faf7 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Thu, 15 Mar 2018 15:26:36 -0500 Subject: [PATCH 17/20] Add correct diagnostics interval to startup message. --- server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.go b/server.go index dd8811463..54bacda1d 100644 --- a/server.go +++ b/server.go @@ -610,7 +610,7 @@ func (s *Server) monitorDiagnostics() { s.Logger().Printf("diagnostics disabled") return } else { - s.Logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every hour. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics") + s.Logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every %v. More information here: https://www.pilosa.com/docs/latest/administration/#diagnostics", s.DiagnosticInterval) } s.diagnostics.SetLogger(s.LogOutput) From 85b33f1bfb11835b830bcef8fd291cbc9185c614 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Thu, 15 Mar 2018 15:27:01 -0500 Subject: [PATCH 18/20] Remove unused code and TODO and clarify with comment. --- diagnostics.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/diagnostics.go b/diagnostics.go index 710f66c2d..08d77a03c 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -91,13 +91,8 @@ func (d *DiagnosticsCollector) Flush() error { if err != nil { return err } + // Intentionally ignoring response body, as user does not need to be notified of error. defer resp.Body.Close() - - // TODO verify response - _, err = ioutil.ReadAll(resp.Body) - if err != nil { - return err - } return nil } From be70bbfed2f5b3032d166bac549e7dec4d713135 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Thu, 15 Mar 2018 15:27:48 -0500 Subject: [PATCH 19/20] Fix bug: backend won't store empty strings. --- diagnostics.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/diagnostics.go b/diagnostics.go index 08d77a03c..3ad07ed42 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -148,6 +148,13 @@ func (d *DiagnosticsCollector) encode() ([]byte, error) { // Set adds a key value metric. func (d *DiagnosticsCollector) Set(name string, value interface{}) { + switch v := value.(type) { + case string: + if v == "" { + // Do not set empty string + return + } + } d.mu.Lock() defer d.mu.Unlock() d.metrics[name] = value From b424811da900493d9daa895a07f262db885765a9 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 16 Mar 2018 15:28:03 -0500 Subject: [PATCH 20/20] Add license text --- gopsutil/systeminfo.go | 14 ++++++++++++++ gopsutil/systeminfo_test.go | 14 ++++++++++++++ security_manager.go | 14 ++++++++++++++ statik/doc.go | 14 ++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/gopsutil/systeminfo.go b/gopsutil/systeminfo.go index e6285ade8..3310aeae1 100644 --- a/gopsutil/systeminfo.go +++ b/gopsutil/systeminfo.go @@ -1,3 +1,17 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package gopsutil import ( diff --git a/gopsutil/systeminfo_test.go b/gopsutil/systeminfo_test.go index 5d96a499c..0f76b62da 100644 --- a/gopsutil/systeminfo_test.go +++ b/gopsutil/systeminfo_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package gopsutil_test import ( diff --git a/security_manager.go b/security_manager.go index fc174866a..80b696c38 100644 --- a/security_manager.go +++ b/security_manager.go @@ -1,3 +1,17 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package pilosa // SecurityManager provides the ability to limit access to restricted endpoints diff --git a/statik/doc.go b/statik/doc.go index 85edd9e6f..e9ca40ffd 100644 --- a/statik/doc.go +++ b/statik/doc.go @@ -1,3 +1,17 @@ +// Copyright 2017 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Package statik contains static assets for the Web UI. `go generate` will // produce statik.go, which is ignored by git. package statik