Browse Source

Merge pull request #2483 from yichengq/335

rafthttp: report unreachable when dropping messages
Yicheng Qin 10 years ago
parent
commit
62a7e2f41f
2 changed files with 5 additions and 0 deletions
  1. 3 0
      rafthttp/peer.go
  2. 2 0
      rafthttp/stream.go

+ 3 - 0
rafthttp/peer.go

@@ -91,6 +91,7 @@ type Peer interface {
 type peer struct {
 	// id of the remote raft peer node
 	id types.ID
+	r  Raft
 
 	msgAppWriter *streamWriter
 	writer       *streamWriter
@@ -113,6 +114,7 @@ func startPeer(tr http.RoundTripper, urls types.URLs, local, to, cid types.ID, r
 	picker := newURLPicker(urls)
 	p := &peer{
 		id:           to,
+		r:            r,
 		msgAppWriter: startStreamWriter(fs, r),
 		writer:       startStreamWriter(fs, r),
 		pipeline:     newPipeline(tr, picker, to, cid, fs, r, errorc),
@@ -156,6 +158,7 @@ func startPeer(tr http.RoundTripper, urls types.URLs, local, to, cid types.ID, r
 				select {
 				case writec <- m:
 				default:
+					p.r.ReportUnreachable(m.To)
 					log.Printf("peer: dropping %s to %s since %s with %d-size buffer is blocked",
 						m.Type, p.id, name, bufSizeMap[name])
 				}

+ 2 - 0
rafthttp/stream.go

@@ -116,6 +116,8 @@ func (cw *streamWriter) run() {
 				if m.Term > msgAppTerm {
 					cw.resetCloser()
 					heartbeatc, msgc = nil, nil
+					// TODO: report to raft at peer level
+					cw.r.ReportUnreachable(m.To)
 				}
 				continue
 			}