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

kv: wait on latches on each key in reverse acquisition order #109349

Merged
Merged
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
11 changes: 10 additions & 1 deletion pkg/kv/kvserver/spanlatch/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,16 @@ func (m *Manager) insertLocked(lg *Guard) {
}

func (m *Manager) nextIDLocked() uint64 {
m.idAlloc++
// We allocate IDs from the top of the uint64 space and in reverse order.
// This is done to order latches in the tree on a same key in reverse order
// of acquisition. Doing so ensures that when we iterate over the tree and
// see a key with many conflicting latches, we visit the latches on that key
// in the reverse order that they will be released. In doing so, we minimize
// the number of open channels that we wait on (calls to waitForSignal) and
// minimize the number of goroutine scheduling points. This is important to
// avoid spikes in runnable goroutine after each request completes, which
// can negatively affect node health.
m.idAlloc--
return m.idAlloc
}

Expand Down