Merge pull request #2834 from hashicorp/leave-newapi

Use the new raft api function for leaving if applicable
This commit is contained in:
James Phillips 2017-03-27 14:14:41 -07:00 committed by GitHub
commit 092c16f5ed
1 changed files with 18 additions and 8 deletions

View File

@ -678,21 +678,31 @@ func (s *Server) Leave() error {
return err return err
} }
// TODO (slackpad) - This will need to be updated once we support node
// IDs.
addr := s.raftTransport.LocalAddr() addr := s.raftTransport.LocalAddr()
// If we are the current leader, and we have any other peers (cluster has multiple // If we are the current leader, and we have any other peers (cluster has multiple
// servers), we should do a RemovePeer to safely reduce the quorum size. If we are // servers), we should do a RemoveServer/RemovePeer to safely reduce the quorum size.
// not the leader, then we should issue our leave intention and wait to be removed // If we are not the leader, then we should issue our leave intention and wait to be
// for some sane period of time. // removed for some sane period of time.
isLeader := s.IsLeader() isLeader := s.IsLeader()
if isLeader && numPeers > 1 { if isLeader && numPeers > 1 {
minRaftProtocol, err := ServerMinRaftProtocol(s.serfLAN.Members())
if err != nil {
return err
}
if minRaftProtocol >= 2 && s.config.RaftConfig.ProtocolVersion >= 3 {
future := s.raft.RemoveServer(raft.ServerID(s.config.NodeID), 0, 0)
if err := future.Error(); err != nil {
s.logger.Printf("[ERR] consul: failed to remove ourself as raft peer: %v", err)
}
} else {
future := s.raft.RemovePeer(addr) future := s.raft.RemovePeer(addr)
if err := future.Error(); err != nil { if err := future.Error(); err != nil {
s.logger.Printf("[ERR] consul: failed to remove ourself as raft peer: %v", err) s.logger.Printf("[ERR] consul: failed to remove ourself as raft peer: %v", err)
} }
} }
}
// Leave the WAN pool // Leave the WAN pool
if s.serfWAN != nil { if s.serfWAN != nil {