Skip to content

Commit

Permalink
Merge pull request #6938 from bdarnell/ispaused
Browse files Browse the repository at this point in the history
raft: Export Progress.IsPaused
  • Loading branch information
xiang90 authored Dec 4, 2016
2 parents d844440 + f60a5d6 commit 40f0193
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions raft/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 40f0193

Please sign in to comment.