better fix for single master restart without peers changing

This commit is contained in:
Chris Lu 2017-12-06 00:14:14 -08:00
parent 9026b3e86e
commit 70f6740309

View file

@ -55,7 +55,7 @@ func NewRaftServer(r *mux.Router, peers []string, httpAddr string, dataDir strin
if oldPeers, changed := isPeersChanged(s.dataDir, httpAddr, s.peers); changed {
glog.V(0).Infof("Peers Change: %v => %v", oldPeers, s.peers)
os.RemoveAll(path.Join(s.dataDir, "conf"))
// os.RemoveAll(path.Join(s.dataDir, "log"))
os.RemoveAll(path.Join(s.dataDir, "log"))
os.RemoveAll(path.Join(s.dataDir, "snapshot"))
}
@ -141,6 +141,10 @@ func isPeersChanged(dir string, self string, peers []string) (oldPeers []string,
}
oldPeers = append(oldPeers, self)
if len(peers) == 0 && len(oldPeers) <= 1 {
return oldPeers, false
}
sort.Strings(peers)
sort.Strings(oldPeers)