Do not remove ourself when we leave from Raft

This commit is contained in:
Armon Dadgar 2014-01-10 15:05:34 -08:00
parent ee37fbc6a2
commit 0cdd9071aa
1 changed files with 19 additions and 5 deletions

View File

@ -246,11 +246,7 @@ func (s *Server) handleLeftMember(member serf.Member) error {
// Remove from Raft peers if this was a server // Remove from Raft peers if this was a server
if valid, _, port := isConsulServer(member); valid { if valid, _, port := isConsulServer(member); valid {
peer := &net.TCPAddr{IP: member.Addr, Port: port} if err := s.removeConsulServer(member, port); err != nil {
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 err
} }
} }
@ -280,3 +276,21 @@ func (s *Server) joinConsulServer(m serf.Member, port int) error {
} }
return nil 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
}