Do not remove ourself when we leave from Raft
This commit is contained in:
parent
df1eea834a
commit
80d9899aec
|
@ -246,11 +246,7 @@ func (s *Server) handleLeftMember(member serf.Member) error {
|
|||
|
||||
// Remove from Raft peers if this was a server
|
||||
if valid, _, port := isConsulServer(member); valid {
|
||||
peer := &net.TCPAddr{IP: member.Addr, Port: port}
|
||||
future := s.raft.RemovePeer(peer)
|
||||
if err := future.Error(); err != nil && err != raft.UnknownPeer {
|
||||
s.logger.Printf("[ERR] consul: failed to remove raft peer '%v': %v",
|
||||
peer, err)
|
||||
if err := s.removeConsulServer(member, port); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -280,3 +276,21 @@ func (s *Server) joinConsulServer(m serf.Member, port int) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// joinConsulServer is used to try to join another consul server
|
||||
func (s *Server) removeConsulServer(m serf.Member, port int) error {
|
||||
// Do not remove ourself
|
||||
if m.Name == s.config.NodeName {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Attempt to remove as peer
|
||||
peer := &net.TCPAddr{IP: m.Addr, Port: port}
|
||||
future := s.raft.RemovePeer(peer)
|
||||
if err := future.Error(); err != nil && err != raft.UnknownPeer {
|
||||
s.logger.Printf("[ERR] consul: failed to remove raft peer '%v': %v",
|
||||
peer, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue