Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
130616: rac2: make reads of RangeController state shared r=kvoli,sumeerbhola a=pav-kv

There can be many parallel `WaitForEval` readers trying to access the `RangeController`. Make the mutex an `RWMutex`, and lock it only for read in `WaitForEval`.

Epic: none
Release note: none

Co-authored-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
craig[bot] and pav-kv committed Sep 13, 2024
2 parents 21d7bcd + 7a58d49 commit b740b44
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type rangeController struct {
leaseholder roachpb.ReplicaID

mu struct {
syncutil.Mutex
syncutil.RWMutex

// State for waiters. When anything in voterSets or nonVoterSets changes,
// waiterSetRefreshCh is closed, and replaced with a new channel. The
Expand Down Expand Up @@ -288,11 +288,11 @@ func (rc *rangeController) WaitForEval(
start := rc.opts.Clock.PhysicalTime()
retry:
// Snapshot the waiter sets and the refresh channel.
rc.mu.Lock()
rc.mu.RLock()
vss := rc.mu.voterSets
nvs := rc.mu.nonVoterSet
refreshCh := rc.mu.waiterSetRefreshCh
rc.mu.Unlock()
rc.mu.RUnlock()

if refreshCh == nil {
// RangeControllerImpl is closed.
Expand Down Expand Up @@ -453,6 +453,7 @@ func (rc *rangeController) CloseRaftMuLocked(ctx context.Context) {
defer rc.mu.Unlock()

rc.mu.voterSets = nil
rc.mu.nonVoterSet = nil
close(rc.mu.waiterSetRefreshCh)
rc.mu.waiterSetRefreshCh = nil
}
Expand Down

0 comments on commit b740b44

Please sign in to comment.