From 0ba1da9c9cdeda0168b2f93ee943e02517091afb Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Fri, 10 Jun 2016 01:16:02 -0400 Subject: [PATCH] Always pass in a snapshot before calling constructNodeServerInfoResponse() --- nomad/node_endpoint.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index 5b61961e4..4784a6fe3 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -102,10 +102,14 @@ func (n *Node) Register(args *structs.NodeRegisterRequest, reply *structs.NodeUp // Set the reply index reply.Index = index + snap, err := n.srv.fsm.State().Snapshot() + if err != nil { + return err + } n.srv.peerLock.RLock() defer n.srv.peerLock.RUnlock() - if err := n.constructNodeServerInfoResponse(nil, reply); err != nil { + if err := n.constructNodeServerInfoResponse(snap, reply); err != nil { n.srv.logger.Printf("[ERR] nomad.client: failed to populate NodeUpdateResponse: %v", err) return err } @@ -129,14 +133,11 @@ func (n *Node) constructNodeServerInfoResponse(snap *state.StateSnapshot, reply }) } - // Capture all the nodes to obtain the node count - if snap == nil { - ss, err := n.srv.fsm.State().Snapshot() - if err != nil { - return err - } - snap = ss - } + // TODO(sean@): Use an indexed node count instead + // + // Snapshot is used only to iterate over all nodes to create a node + // count to send back to Nomad Clients in their heartbeat so Clients + // can estimate the size of the cluster. iter, err := snap.Nodes() if err == nil { for {