mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
rafthttp: print out log when clusterID mismatch instead of exiting
We have heard from several users that they do not expect a clusterID mismatch to kill the cluster.
This commit is contained in:
parent
5d741e4945
commit
0d3d4c5b01
@ -126,6 +126,15 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wcid := h.cid.String()
|
||||||
|
w.Header().Set("X-Etcd-Cluster-ID", wcid)
|
||||||
|
|
||||||
|
if gcid := r.Header.Get("X-Etcd-Cluster-ID"); gcid != wcid {
|
||||||
|
log.Printf("rafthttp: streaming request ignored due to cluster ID mismatch got %s want %s", gcid, wcid)
|
||||||
|
http.Error(w, "clusterID mismatch", http.StatusPreconditionFailed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Add("X-Server-Version", version.Version)
|
w.Header().Add("X-Server-Version", version.Version)
|
||||||
|
|
||||||
var t streamType
|
var t streamType
|
||||||
@ -162,13 +171,6 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wcid := h.cid.String()
|
|
||||||
if gcid := r.Header.Get("X-Etcd-Cluster-ID"); gcid != wcid {
|
|
||||||
log.Printf("rafthttp: streaming request ignored due to cluster ID mismatch got %s want %s", gcid, wcid)
|
|
||||||
http.Error(w, "clusterID mismatch", http.StatusPreconditionFailed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
wto := h.id.String()
|
wto := h.id.String()
|
||||||
if gto := r.Header.Get("X-Raft-To"); gto != wto {
|
if gto := r.Header.Get("X-Raft-To"); gto != wto {
|
||||||
log.Printf("rafthttp: streaming request ignored due to ID mismatch got %s want %s", gto, wto)
|
log.Printf("rafthttp: streaming request ignored due to ID mismatch got %s want %s", gto, wto)
|
||||||
|
@ -148,12 +148,9 @@ func (p *pipeline) post(data []byte) error {
|
|||||||
|
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case http.StatusPreconditionFailed:
|
case http.StatusPreconditionFailed:
|
||||||
err := fmt.Errorf("conflicting cluster ID with the target cluster (%s != %s)", resp.Header.Get("X-Etcd-Cluster-ID"), p.cid)
|
log.Printf("rafthttp: request sent was ignored due to cluster ID mismatch (remote[%s]:%s, local:%s)",
|
||||||
select {
|
uu.Host, resp.Header.Get("X-Etcd-Cluster-ID"), p.cid)
|
||||||
case p.errorc <- err:
|
return fmt.Errorf("cluster ID mismatch")
|
||||||
default:
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case http.StatusForbidden:
|
case http.StatusForbidden:
|
||||||
err := fmt.Errorf("the member has been permanently removed from the cluster")
|
err := fmt.Errorf("the member has been permanently removed from the cluster")
|
||||||
select {
|
select {
|
||||||
|
@ -165,7 +165,6 @@ func TestPipelinePostErrorc(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{"http://localhost:2380", http.StatusForbidden, nil},
|
{"http://localhost:2380", http.StatusForbidden, nil},
|
||||||
{"http://localhost:2380", http.StatusPreconditionFailed, nil},
|
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
picker := mustNewURLPicker(t, []string{tt.u})
|
picker := mustNewURLPicker(t, []string{tt.u})
|
||||||
|
@ -424,6 +424,11 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) {
|
|||||||
case http.StatusNotFound:
|
case http.StatusNotFound:
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return nil, fmt.Errorf("local member has not been added to the peer list of member %s", cr.to)
|
return nil, fmt.Errorf("local member has not been added to the peer list of member %s", cr.to)
|
||||||
|
case http.StatusPreconditionFailed:
|
||||||
|
resp.Body.Close()
|
||||||
|
log.Printf("rafthttp: request sent was ignored due to cluster ID mismatch (remote[%s]:%s, local:%s)",
|
||||||
|
uu.Host, resp.Header.Get("X-Etcd-Cluster-ID"), cr.cid)
|
||||||
|
return nil, fmt.Errorf("cluster ID mismatch")
|
||||||
default:
|
default:
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return nil, fmt.Errorf("unhandled http status %d", resp.StatusCode)
|
return nil, fmt.Errorf("unhandled http status %d", resp.StatusCode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user