Skip to content

Commit d404a3f

Browse files
committed
storage: extract replica unlinking into store method
Extract some code that was duplicated in three places into a dedicated helper method. Release note: None
1 parent 33c6fac commit d404a3f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

pkg/storage/replica.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,12 +5165,7 @@ func (r *Replica) acquireSplitLock(
51655165
rightRng.mu.destroyStatus.Set(errors.Errorf("%s: failed to initialize", rightRng), destroyReasonRemoved)
51665166
rightRng.mu.Unlock()
51675167
r.store.mu.Lock()
5168-
r.store.unquiescedReplicas.Lock()
5169-
delete(r.store.unquiescedReplicas.m, rightRng.RangeID)
5170-
r.store.unquiescedReplicas.Unlock()
5171-
r.store.mu.replicas.Delete(int64(rightRng.RangeID))
5172-
delete(r.store.mu.uninitReplicas, rightRng.RangeID)
5173-
r.store.replicaQueues.Delete(int64(rightRng.RangeID))
5168+
r.store.unlinkReplicaByRangeIDLocked(rightRng.RangeID)
51745169
r.store.mu.Unlock()
51755170
}
51765171
rightRng.raftMu.Unlock()

pkg/storage/store.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)