during the leader election, return error to client

release-0.4
Xiang Li 2013-06-30 21:17:51 -07:00
parent e211554b91
commit f6b3d8a2af
2 changed files with 15 additions and 3 deletions

10
etcd.go
View File

@ -168,8 +168,14 @@ func main() {
fatal("%v", err)
}
server.LoadSnapshot()
debug("%s finished load snapshot", server.Name())
err = server.LoadSnapshot()
if err == nil {
debug("%s finished load snapshot", server.Name())
} else {
fmt.Println(err)
debug("%s bad snapshot", server.Name())
}
server.Initialize()
debug("%s finished init", server.Name())
server.SetElectionTimeout(ELECTIONTIMTOUT)

View File

@ -163,6 +163,12 @@ func excute(c Command, w *http.ResponseWriter, req *http.Request) {
return
}
} else {
// current no leader
if server.Leader() == "" {
(*w).WriteHeader(http.StatusInternalServerError)
return
}
// tell the client where is the leader
debug("Redirect to the leader %s", server.Leader())
@ -176,7 +182,7 @@ func excute(c Command, w *http.ResponseWriter, req *http.Request) {
url := scheme + leaderClient() + path
debug("redirect to ", url)
debug("redirect to %s", url)
http.Redirect(*w, req, url, http.StatusTemporaryRedirect)
return
}