Skip to content

Commit

Permalink
kvserver: add Replica.GetMutexForTesting()
Browse files Browse the repository at this point in the history
This allows testing replica stalls and deadlocks from outside of the
kvserver package.

Epic: none
Release note: None
  • Loading branch information
erikgrinaker committed Feb 18, 2024
1 parent e39dafe commit 8f405f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/kv/kvserver/kvserverbase/stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Store interface {

// GetReplicaMutexForTesting returns the mutex of the replica with the given
// range ID, or nil if no replica was found. This is used for testing.
// Returns a syncutil.RWMutex rather than ReplicaMutex to avoid import cycles.
GetReplicaMutexForTesting(rangeID roachpb.RangeID) *syncutil.RWMutex
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/kv/kvserver/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -2464,3 +2464,8 @@ func (r *Replica) ReadProtectedTimestampsForTesting(ctx context.Context) (err er
ts, err = r.readProtectedTimestampsRLocked(ctx)
return err
}

// GetMutexForTesting returns the replica's mutex, for use in tests.
func (r *Replica) GetMutexForTesting() *ReplicaMutex {
return &r.mu.ReplicaMutex
}
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/stores_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *baseStore) SetQueueActive(active bool, queue string) error {
func (s *baseStore) GetReplicaMutexForTesting(rangeID roachpb.RangeID) *syncutil.RWMutex {
store := (*Store)(s)
if repl := store.GetReplicaIfExists(rangeID); repl != nil {
return (*syncutil.RWMutex)(&repl.mu.ReplicaMutex)
return (*syncutil.RWMutex)(repl.GetMutexForTesting())
}
return nil
}

0 comments on commit 8f405f3

Please sign in to comment.