mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
during the leader election, return error to client
This commit is contained in:
parent
e211554b91
commit
f6b3d8a2af
10
etcd.go
10
etcd.go
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user