do not remove raft files unless it is the node being removed

pull/4233/head
Cory LaNou 2015-09-30 16:24:38 -05:00
parent 96d63cf9f0
commit df08a070f6
2 changed files with 9 additions and 6 deletions

View File

@ -28,7 +28,7 @@ type raftState interface {
sync(index uint64, timeout time.Duration) error
setPeers(addrs []string) error
addPeer(addr string) error
removePeer(addr string) error
removePeer(addr string, cleanup bool) error
peers() ([]string, error)
invalidate() error
close() error
@ -318,12 +318,15 @@ func (r *localRaft) addPeer(addr string) error {
}
// removePeer removes addr from the list of peers in the cluster.
func (r *localRaft) removePeer(addr string) error {
func (r *localRaft) removePeer(addr string, cleanup bool) error {
if fut := r.raft.RemovePeer(addr); fut.Error() != nil {
return fut.Error()
}
// clean up the directories
return r.remove()
// clean up the directories if this is the node removed
if cleanup {
return r.remove()
}
return nil
}
// setPeers sets a list of peers in the cluster.
@ -408,7 +411,7 @@ func (r *remoteRaft) addPeer(addr string) error {
}
// removePeer does nothing for remoteRaft.
func (r *remoteRaft) removePeer(addr string) error {
func (r *remoteRaft) removePeer(addr string, cleanup bool) error {
return nil
}

View File

@ -1686,7 +1686,7 @@ func (fsm *storeFSM) applyRemovePeerCommand(cmd *internal.Command) interface{} {
addr := v.GetAddr()
//Remove that node from the peer
fsm.Logger.Printf("removing peer for node id %d, %s", id, addr)
if err := fsm.raftState.removePeer(addr); err != nil {
if err := fsm.raftState.removePeer(addr, id == fsm.id); err != nil {
fsm.Logger.Printf("error removing peer: %s", err)
}
return nil