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

replica_rac2: optimize logTracker.admitted #132140

Merged
merged 1 commit into from
Oct 17, 2024
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
16 changes: 11 additions & 5 deletions pkg/kv/kvserver/kvflowcontrol/replica_rac2/log_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
type logTracker struct {
syncutil.Mutex
lt rac2.LogTracker
// av is the latest computed admitted vector. It is stale if dirty is true. In
// this case it will be recomputed when requested.
av rac2.AdmittedVector
// dirty is true when the admitted vector has changed and should be sent to
// the leader.
dirty bool
Expand All @@ -36,6 +39,7 @@ func (l *logTracker) init(stable rac2.LogMark) {
l.Lock()
defer l.Unlock()
l.lt = rac2.NewLogTracker(stable)
l.av = l.lt.Admitted()
}

// admitted returns the current admitted vector, and a bool indicating whether
Expand All @@ -47,15 +51,17 @@ func (l *logTracker) init(stable rac2.LogMark) {
// handler. In this case the scheduled flag is reset, which allows the next
// logAdmitted call to return true and allow scheduling a Ready iteration again.
// This flow avoids unnecessary Ready scheduling events.
func (l *logTracker) admitted(sched bool) (av rac2.AdmittedVector, dirty bool) {
func (l *logTracker) admitted(sched bool) (_ rac2.AdmittedVector, dirty bool) {
l.Lock()
defer l.Unlock()
dirty, l.dirty = l.dirty, false
if sched {
if sched && l.scheduled {
l.scheduled = false
}
av = l.lt.Admitted()
return av, dirty
if dirty = l.dirty; dirty {
l.av = l.lt.Admitted()
l.dirty = false
}
return l.av, dirty
}

func (l *logTracker) snap(ctx context.Context, mark rac2.LogMark) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/kvflowcontrol/replica_rac2/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ func (p *processorImpl) AdmittedLogEntry(

// AdmittedState implements Processor.
func (p *processorImpl) AdmittedState() rac2.AdmittedVector {
admitted, _ := p.logTracker.admitted(false /* sched */)
return admitted
av, _ := p.logTracker.admitted(false /* sched */)
return av
}

// AdmitRaftMuLocked implements Processor.
Expand Down
Loading