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

NRG: Log healthy status when no longer falling behind #4995

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ type raft struct {
llqrt time.Time // Last quorum lost time
lsut time.Time // Last scale-up time

term uint64 // The current vote term
pterm uint64 // Previous term from the last snapshot
pindex uint64 // Previous index from the last snapshot
commit uint64 // Sequence number of the most recent commit
applied uint64 // Sequence number of the most recently applied commit
term uint64 // The current vote term
pterm uint64 // Previous term from the last snapshot
pindex uint64 // Previous index from the last snapshot
commit uint64 // Sequence number of the most recent commit
applied uint64 // Sequence number of the most recently applied commit
hcbehind bool // Were we falling behind at the last health check? (see: isCurrent)

leader string // The ID of the leader
vote string // Our current vote state
Expand Down Expand Up @@ -1269,8 +1270,18 @@ func (n *raft) isCurrent(includeForwardProgress bool) bool {
return false
}

// If we were previously logging about falling behind, also log when the problem
// was cleared.
clearBehindState := func() {
if n.hcbehind {
n.warn("Health check OK, no longer falling behind")
ripienaar marked this conversation as resolved.
Show resolved Hide resolved
n.hcbehind = false
}
}

// Make sure we are the leader or we know we have heard from the leader recently.
if n.State() == Leader {
clearBehindState()
Copy link
Member

Choose a reason for hiding this comment

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

This not only applicable to leaders no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put this here just to cover the case of if you became leader in that time, to ensure the behind state gets cleared.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha..

return true
}

Expand All @@ -1294,6 +1305,7 @@ func (n *raft) isCurrent(includeForwardProgress bool) bool {

if n.commit == n.applied {
// At this point if we are current, we can return saying so.
clearBehindState()
return true
} else if !includeForwardProgress {
// Otherwise, if we aren't allowed to include forward progress
Expand All @@ -1311,11 +1323,13 @@ func (n *raft) isCurrent(includeForwardProgress bool) bool {
n.Lock()
if n.commit-n.applied < startDelta {
// The gap is getting smaller, so we're making forward progress.
clearBehindState()
return true
}
}
}

n.hcbehind = true
n.warn("Falling behind in health check, commit %d != applied %d", n.commit, n.applied)
return false
}
Expand Down