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

kvserver: fix locking before addToReplicasByKey* #96946

Merged
merged 1 commit into from
Feb 10, 2023
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
4 changes: 4 additions & 0 deletions pkg/kv/kvserver/replica_consistency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func TestStoreCheckpointSpans(t *testing.T) {
addReplica := func(rangeID roachpb.RangeID, start, end string) {
desc := makeDesc(rangeID, start, end)
r := &Replica{RangeID: rangeID, startKey: desc.StartKey}
// NB: locking is unnecessary during Replica creation, but this is to work
// around the mutex hold asserts in "Locked" methods below.
r.mu.Lock()
defer r.mu.Unlock()
r.mu.state.Desc = &desc
r.isInitialized.Set(desc.IsInitialized())
require.NoError(t, s.addToReplicasByRangeIDLocked(r))
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ func (s *Store) Start(ctx context.Context, stopper *stop.Stopper) error {
err = s.addToReplicasByRangeIDLocked(rep)
if err == nil {
// NB: no locking of the Replica is needed since it's being created, but
// just in case.
// it is asserted on in "Locked" methods.
rep.mu.RLock()
err = s.addToReplicasByKeyLockedReplicaRLocked(rep)
rep.mu.RUnlock()
Expand Down