|
@@ -200,6 +200,8 @@ func (s *PeerServer) handleDiscovery(discoverURL string) (peers []string, err er
|
|
|
// 1. -discovery
|
|
// 1. -discovery
|
|
|
// 2. -peers
|
|
// 2. -peers
|
|
|
// 3. previous peers in -data-dir
|
|
// 3. previous peers in -data-dir
|
|
|
|
|
+// RaftServer should be started as late as possible. Current implementation
|
|
|
|
|
+// to start it is not that good, and will be refactored in #627.
|
|
|
func (s *PeerServer) findCluster(discoverURL string, peers []string) {
|
|
func (s *PeerServer) findCluster(discoverURL string, peers []string) {
|
|
|
// Attempt cluster discovery
|
|
// Attempt cluster discovery
|
|
|
toDiscover := discoverURL != ""
|
|
toDiscover := discoverURL != ""
|
|
@@ -250,6 +252,7 @@ func (s *PeerServer) findCluster(discoverURL string, peers []string) {
|
|
|
if !ok {
|
|
if !ok {
|
|
|
log.Warn("No living peers are found!")
|
|
log.Warn("No living peers are found!")
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ s.raftServer.Start()
|
|
|
log.Debugf("%s restart as a follower based on peers[%v]", s.Config.Name)
|
|
log.Debugf("%s restart as a follower based on peers[%v]", s.Config.Name)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -257,6 +260,7 @@ func (s *PeerServer) findCluster(discoverURL string, peers []string) {
|
|
|
|
|
|
|
|
if !s.raftServer.IsLogEmpty() {
|
|
if !s.raftServer.IsLogEmpty() {
|
|
|
log.Debug("Entire cluster is down! %v will restart the cluster.", s.Config.Name)
|
|
log.Debug("Entire cluster is down! %v will restart the cluster.", s.Config.Name)
|
|
|
|
|
+ s.raftServer.Start()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -285,7 +289,7 @@ func (s *PeerServer) Start(snapshot bool, discoverURL string, peers []string) er
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- s.raftServer.Start()
|
|
|
|
|
|
|
+ s.raftServer.Init()
|
|
|
|
|
|
|
|
s.findCluster(discoverURL, peers)
|
|
s.findCluster(discoverURL, peers)
|
|
|
|
|
|
|
@@ -351,6 +355,7 @@ func (s *PeerServer) SetServer(server *Server) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *PeerServer) startAsLeader() {
|
|
func (s *PeerServer) startAsLeader() {
|
|
|
|
|
+ s.raftServer.Start()
|
|
|
// leader need to join self as a peer
|
|
// leader need to join self as a peer
|
|
|
for {
|
|
for {
|
|
|
c := &JoinCommandV1{
|
|
c := &JoinCommandV1{
|
|
@@ -373,6 +378,7 @@ func (s *PeerServer) startAsFollower(cluster []string) {
|
|
|
for i := 0; i < s.Config.RetryTimes; i++ {
|
|
for i := 0; i < s.Config.RetryTimes; i++ {
|
|
|
ok := s.joinCluster(cluster)
|
|
ok := s.joinCluster(cluster)
|
|
|
if ok {
|
|
if ok {
|
|
|
|
|
+ s.raftServer.Start()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
log.Warnf("%v is unable to join the cluster using any of the peers %v at %dth time. Retrying in %.1f seconds", s.Config.Name, cluster, i, s.Config.RetryInterval)
|
|
log.Warnf("%v is unable to join the cluster using any of the peers %v at %dth time. Retrying in %.1f seconds", s.Config.Name, cluster, i, s.Config.RetryInterval)
|