Skip to content

Commit

Permalink
Merge pull request #3450 from hashicorp/raft_peers_fix
Browse files Browse the repository at this point in the history
Change member join reconcile step to process joining itself, to handl…
  • Loading branch information
preetapan authored Sep 6, 2017
2 parents 39b3d03 + 084679a commit 65299e9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions agent/consul/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,6 @@ func (s *Server) handleDeregisterMember(reason string, member serf.Member) error

// joinConsulServer is used to try to join another consul server
func (s *Server) joinConsulServer(m serf.Member, parts *metadata.Server) error {
// Do not join ourself
if m.Name == s.config.NodeName {
return nil
}

// Check for possibility of multiple bootstrap nodes
if parts.Bootstrap {
members := s.serfLAN.Members()
Expand All @@ -643,20 +638,28 @@ func (s *Server) joinConsulServer(m serf.Member, parts *metadata.Server) error {
}
}

addr := (&net.TCPAddr{IP: m.Addr, Port: parts.Port}).String()

minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())
if err != nil {
// Processing ourselves could result in trying to remove ourselves to
// fix up our address, which would make us step down. This is only
// safe to attempt if there are multiple servers available.
configFuture := s.raft.GetConfiguration()
if err := configFuture.Error(); err != nil {
s.logger.Printf("[ERR] consul: failed to get raft configuration: %v", err)
return err
}
if m.Name == s.config.NodeName {
if l := len(configFuture.Configuration().Servers); l < 3 {
s.logger.Printf("[DEBUG] consul: Skipping self join check for %q since the cluster is too small", m.Name)
return nil
}
}

// See if it's already in the configuration. It's harmless to re-add it
// but we want to avoid doing that if possible to prevent useless Raft
// log entries. If the address is the same but the ID changed, remove the
// old server before adding the new one.
configFuture := s.raft.GetConfiguration()
if err := configFuture.Error(); err != nil {
s.logger.Printf("[ERR] consul: failed to get raft configuration: %v", err)
addr := (&net.TCPAddr{IP: m.Addr, Port: parts.Port}).String()
minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())
if err != nil {
return err
}
for _, server := range configFuture.Configuration().Servers {
Expand Down

0 comments on commit 65299e9

Please sign in to comment.