mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
contrib/raftexample: Allow nodes to be removed from a running cluster
A node with ID n can be removed by DELETEing /n on the HTTP server.
This commit is contained in:
parent
7c0b6d9be9
commit
4a527be302
@ -73,12 +73,29 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
h.confChangeC <- cc
|
||||
|
||||
// As above, optimistic that raft will apply the conf change
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
case r.Method == "DELETE":
|
||||
nodeId, err := strconv.ParseUint(key[1:], 0, 64)
|
||||
if err != nil {
|
||||
log.Printf("Failed to convert ID for conf change (%v)\n", err)
|
||||
http.Error(w, "Failed on DELETE", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
cc := raftpb.ConfChange{
|
||||
Type: raftpb.ConfChangeRemoveNode,
|
||||
NodeID: nodeId,
|
||||
}
|
||||
h.confChangeC <- cc
|
||||
|
||||
// As above, optimistic that raft will apply the conf change
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
default:
|
||||
w.Header().Set("Allow", "PUT")
|
||||
w.Header().Add("Allow", "GET")
|
||||
w.Header().Add("Allow", "POST")
|
||||
w.Header().Add("Allow", "DELETE")
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user