@@ -2236,12 +2236,7 @@ func (s *Store) SplitRange(ctx context.Context, origRng, newRng *Replica) error
22362236 if exRng != newRng {
22372237 log .Fatalf (ctx , "found unexpected uninitialized replica: %s vs %s" , exRng , newRng )
22382238 }
2239- delete (s .mu .uninitReplicas , newDesc .RangeID )
2240- s .unquiescedReplicas .Lock ()
2241- delete (s .unquiescedReplicas .m , newDesc .RangeID )
2242- s .unquiescedReplicas .Unlock ()
2243- s .mu .replicas .Delete (int64 (newDesc .RangeID ))
2244- s .replicaQueues .Delete (int64 (newDesc .RangeID ))
2239+ s .unlinkReplicaByRangeIDLocked (newDesc .RangeID )
22452240 }
22462241
22472242 // Replace the end key of the original range with the start key of
@@ -2533,12 +2528,7 @@ func (s *Store) removeReplicaImpl(
25332528
25342529 s .mu .Lock ()
25352530 defer s .mu .Unlock ()
2536- s .unquiescedReplicas .Lock ()
2537- delete (s .unquiescedReplicas .m , rep .RangeID )
2538- s .unquiescedReplicas .Unlock ()
2539- s .mu .replicas .Delete (int64 (rep .RangeID ))
2540- delete (s .mu .uninitReplicas , rep .RangeID )
2541- s .replicaQueues .Delete (int64 (rep .RangeID ))
2531+ s .unlinkReplicaByRangeIDLocked (rep .RangeID )
25422532 if ! opts .AllowPlaceholders {
25432533 if placeholder := s .mu .replicasByKey .Delete (rep ); placeholder != rep {
25442534 // We already checked that our replica was present in replicasByKey
@@ -2554,6 +2544,21 @@ func (s *Store) removeReplicaImpl(
25542544 return nil
25552545}
25562546
2547+ // unlinkReplicaByRangeIDLocked removes all of the store's references to the
2548+ // provided replica that are keyed by its range ID. The replica may also need
2549+ // to be removed from the replicasByKey map.
2550+ //
2551+ // store.mu must be held.
2552+ func (s * Store ) unlinkReplicaByRangeIDLocked (rangeID roachpb.RangeID ) {
2553+ s .mu .AssertHeld ()
2554+ s .unquiescedReplicas .Lock ()
2555+ delete (s .unquiescedReplicas .m , rangeID )
2556+ s .unquiescedReplicas .Unlock ()
2557+ delete (s .mu .uninitReplicas , rangeID )
2558+ s .replicaQueues .Delete (int64 (rangeID ))
2559+ s .mu .replicas .Delete (int64 (rangeID ))
2560+ }
2561+
25572562// processRangeDescriptorUpdate should be called whenever a replica's range
25582563// descriptor is updated, to update the store's maps of its ranges to match
25592564// the updated descriptor. Since the latter update requires acquiring the store
0 commit comments