Add retrying logic to wait for other peers during cluster bootstrapping.

This commit is contained in:
Chris Lu
2014-04-11 16:23:58 -07:00
parent 7c82e2316b
commit 008aee0dc1
4 changed files with 44 additions and 15 deletions

View File

@@ -40,10 +40,10 @@ func (s *RaftServer) HandleFunc(pattern string, handler func(http.ResponseWriter
}
func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) {
if s.topo.Leader() != "" {
if leader, e := s.topo.Leader(); e == nil {
//http.StatusMovedPermanently does not cause http POST following redirection
glog.V(0).Infoln("Redirecting to", http.StatusMovedPermanently, "http://"+s.topo.Leader()+req.URL.Path)
http.Redirect(w, req, "http://"+s.topo.Leader()+req.URL.Path, http.StatusMovedPermanently)
glog.V(0).Infoln("Redirecting to", http.StatusMovedPermanently, "http://"+leader+req.URL.Path)
http.Redirect(w, req, "http://"+leader+req.URL.Path, http.StatusMovedPermanently)
} else {
glog.V(0).Infoln("Error: Leader Unknown")
http.Error(w, "Leader unknown", http.StatusInternalServerError)
@@ -53,7 +53,11 @@ func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request)
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["IsLeader"] = s.topo.IsLeader()
m["Leader"] = s.topo.Leader()
if leader, e := s.topo.Leader(); e == nil {
m["Leader"] = leader
} else {
m["Leader"] = ""
}
m["Peers"] = s.Peers()
writeJsonQuiet(w, r, m)
}