From f60a5d6025a4f25d6d0413c9e27134d691ccda2a Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 4 Dec 2016 13:14:08 +0800 Subject: [PATCH] raft: Export Progress.IsPaused CockroachDB would like to use this method for monitoring. --- raft/progress.go | 9 ++++++--- raft/raft.go | 4 ++-- raft/raft_test.go | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/raft/progress.go b/raft/progress.go index 1da20990e..77c7b52ef 100644 --- a/raft/progress.go +++ b/raft/progress.go @@ -155,8 +155,11 @@ func (pr *Progress) maybeDecrTo(rejected, last uint64) bool { func (pr *Progress) pause() { pr.Paused = true } func (pr *Progress) resume() { pr.Paused = false } -// isPaused returns whether progress stops sending message. -func (pr *Progress) isPaused() bool { +// IsPaused returns whether sending log entries to this node has been +// paused. A node may be paused because it has rejected recent +// MsgApps, is currently waiting for a snapshot, or has reached the +// MaxInflightMsgs limit. +func (pr *Progress) IsPaused() bool { switch pr.State { case ProgressStateProbe: return pr.Paused @@ -178,7 +181,7 @@ func (pr *Progress) needSnapshotAbort() bool { } func (pr *Progress) String() string { - return fmt.Sprintf("next = %d, match = %d, state = %s, waiting = %v, pendingSnapshot = %d", pr.Next, pr.Match, pr.State, pr.isPaused(), pr.PendingSnapshot) + return fmt.Sprintf("next = %d, match = %d, state = %s, waiting = %v, pendingSnapshot = %d", pr.Next, pr.Match, pr.State, pr.IsPaused(), pr.PendingSnapshot) } type inflights struct { diff --git a/raft/raft.go b/raft/raft.go index 288989d16..b2f3716d6 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -367,7 +367,7 @@ func (r *raft) send(m pb.Message) { // sendAppend sends RPC, with entries to the given peer. func (r *raft) sendAppend(to uint64) { pr := r.prs[to] - if pr.isPaused() { + if pr.IsPaused() { return } m := pb.Message{} @@ -870,7 +870,7 @@ func stepLeader(r *raft, m pb.Message) { r.sendAppend(m.From) } } else { - oldPaused := pr.isPaused() + oldPaused := pr.IsPaused() if pr.maybeUpdate(m.Index) { switch { case pr.State == ProgressStateProbe: diff --git a/raft/raft_test.go b/raft/raft_test.go index 99579d94f..4781048f2 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -236,7 +236,7 @@ func TestProgressIsPaused(t *testing.T) { Paused: tt.paused, ins: newInflights(256), } - if g := p.isPaused(); g != tt.w { + if g := p.IsPaused(); g != tt.w { t.Errorf("#%d: paused= %t, want %t", i, g, tt.w) } }