From 80d9899aec33d694ed42c75b1045981991f6152d Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 10 Jan 2014 15:05:34 -0800 Subject: [PATCH] Do not remove ourself when we leave from Raft --- consul/leader.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/consul/leader.go b/consul/leader.go index cf1e434fb..3afb6e545 100644 --- a/consul/leader.go +++ b/consul/leader.go @@ -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 +}