From 88a150cee1c3971f7aee01d7fc6650ae6a7f4588 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 6 Sep 2017 18:01:53 -0700 Subject: [PATCH] Moves reconcile loop into segment stub. --- agent/consul/leader.go | 19 ------------------- agent/consul/segment_stub.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/agent/consul/leader.go b/agent/consul/leader.go index 2ad4aea820..e20d5a876e 100644 --- a/agent/consul/leader.go +++ b/agent/consul/leader.go @@ -328,25 +328,6 @@ func (s *Server) getOrCreateAutopilotConfig() (*structs.AutopilotConfig, bool) { return config, true } -// reconcile is used to reconcile the differences between Serf -// membership and what is reflected in our strongly consistent store. -// Mainly we need to ensure all live nodes are registered, all failed -// nodes are marked as such, and all left nodes are de-registered. -func (s *Server) reconcile() (err error) { - defer metrics.MeasureSince([]string{"consul", "leader", "reconcile"}, time.Now()) - members := s.serfLAN.Members() - knownMembers := make(map[string]struct{}) - for _, member := range members { - if err := s.reconcileMember(member); err != nil { - return err - } - knownMembers[member.Name] = struct{}{} - } - - // Reconcile any members that have been reaped while we were not the leader - return s.reconcileReaped(knownMembers) -} - // reconcileReaped is used to reconcile nodes that have failed and been reaped // from Serf but remain in the catalog. This is done by looking for SerfCheckID // in a critical state that does not correspond to a known Serf member. We generate diff --git a/agent/consul/segment_stub.go b/agent/consul/segment_stub.go index 9b89ecb795..c72d0c99fd 100644 --- a/agent/consul/segment_stub.go +++ b/agent/consul/segment_stub.go @@ -4,7 +4,9 @@ package consul import ( "net" + "time" + "github.com/armon/go-metrics" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/serf/serf" ) @@ -51,3 +53,23 @@ func (s *Server) setupSegments(config *Config, port int, rpcListeners map[string // floodSegments is a NOP in the OSS version of Consul. func (s *Server) floodSegments(config *Config) { } + +// reconcile is used to reconcile the differences between Serf membership and +// what is reflected in our strongly consistent store. Mainly we need to ensure +// all live nodes are registered, all failed nodes are marked as such, and all +// left nodes are de-registered. +func (s *Server) reconcile() (err error) { + defer metrics.MeasureSince([]string{"consul", "leader", "reconcile"}, time.Now()) + members := s.serfLAN.Members() + knownMembers := make(map[string]struct{}) + for _, member := range members { + if err := s.reconcileMember(member); err != nil { + return err + } + knownMembers[member.Name] = struct{}{} + } + + // Reconcile any members that have been reaped while we were not the + // leader. + return s.reconcileReaped(knownMembers) +}