Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raft: Export Progress.IsPaused #6938

Merged
merged 1 commit into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the access of pr.Paused is not protect by lock. I am not sure if this access is safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStatus makes a copy of each Progress struct, so it should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. OK. Can you check status is the only way external pkg to access Progress? If yes, then lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is. In any case, if there were other ways to access the Progress struct then all of its fields would have the same synchronization problem.

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