Skip to content

Commit 9d8cfdd

Browse files
committed
kvstorage: simplify DestroyReplica
Now that the replica subsumption is factored out into its own call, all the remaining uses of DestroyReplica remove the entirety of the replica. We thus don't need to pass the ClearRangeDataOptions to DestroyReplica any longer. The options become an internal implementation detail of the kvstorage package. Epic: none Release note: none
1 parent 6458da5 commit 9d8cfdd

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

pkg/kv/kvserver/kvstorage/destroy.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,29 @@ type DestroyReplicaInfo struct {
129129
Keys roachpb.RSpan
130130
}
131131

132-
// DestroyReplica destroys all or a part of the Replica's state, installing a
133-
// RangeTombstone in its place. Due to merges, splits, etc, there is a need to
134-
// control which part of the state this method actually gets to remove, which is
135-
// done via the provided options[^1]; the caller is always responsible for
136-
// managing the remaining disk state accordingly.
137-
//
138-
// [^1] e.g., on a merge, the user data moves to the subsuming replica and must
139-
// not be cleared.
132+
// DestroyReplica destroys the entirety of the replica's state in storage, and
133+
// installs a RangeTombstone in its place. It handles both uninitialized and
134+
// initialized replicas uniformly.
140135
func DestroyReplica(
141136
ctx context.Context,
142137
reader storage.Reader,
143138
writer storage.Writer,
144139
info DestroyReplicaInfo,
145140
next roachpb.ReplicaID,
141+
) error {
142+
return destroyReplicaImpl(ctx, reader, writer, info, next, ClearRangeDataOptions{
143+
ClearReplicatedByRangeID: true,
144+
ClearUnreplicatedByRangeID: true,
145+
ClearReplicatedBySpan: info.Keys,
146+
})
147+
}
148+
149+
func destroyReplicaImpl(
150+
ctx context.Context,
151+
reader storage.Reader,
152+
writer storage.Writer,
153+
info DestroyReplicaInfo,
154+
next roachpb.ReplicaID,
146155
opts ClearRangeDataOptions,
147156
) error {
148157
if next <= info.ReplicaID {
@@ -205,5 +214,5 @@ func SubsumeReplica(
205214
return rditer.SelectOpts{
206215
ReplicatedByRangeID: opts.ClearReplicatedByRangeID,
207216
UnreplicatedByRangeID: opts.ClearUnreplicatedByRangeID,
208-
}, DestroyReplica(ctx, reader, writer, info, MergedTombstoneReplicaID, opts)
217+
}, destroyReplicaImpl(ctx, reader, writer, info, MergedTombstoneReplicaID, opts)
209218
}

pkg/kv/kvserver/kvstorage/destroy_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ func TestDestroyReplica(t *testing.T) {
6969
})
7070
mutate("destroy", func(rw storage.ReadWriter) {
7171
require.NoError(t, DestroyReplica(
72-
ctx, rw, rw,
73-
DestroyReplicaInfo{FullReplicaID: r.id, Keys: r.keys}, r.id.ReplicaID+1,
74-
ClearRangeDataOptions{
75-
ClearUnreplicatedByRangeID: true,
76-
ClearReplicatedByRangeID: true,
77-
ClearReplicatedBySpan: r.keys,
78-
},
72+
ctx, rw, rw, DestroyReplicaInfo{FullReplicaID: r.id, Keys: r.keys}, r.id.ReplicaID+1,
7973
))
8074
})
8175

pkg/kv/kvserver/replica_app_batch.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ func (b *replicaAppBatch) runPostAddTriggersReplicaOnly(
440440
b.r.shMu.destroyStatus.Set(
441441
kvpb.NewRangeNotFoundError(b.r.RangeID, b.r.store.StoreID()),
442442
destroyReasonRemoved)
443-
span := b.r.descRLocked().RSpan()
444443
b.r.mu.Unlock()
445444
b.r.readOnlyCmdMu.Unlock()
446445
b.changeRemovesReplica = true
@@ -450,14 +449,7 @@ func (b *replicaAppBatch) runPostAddTriggersReplicaOnly(
450449
// above, and DestroyReplica will also add a range tombstone to the
451450
// batch, so that when we commit it, the removal is finalized.
452451
if err := kvstorage.DestroyReplica(
453-
ctx, b.batch, b.batch,
454-
b.r.destroyInfoRaftMuLocked(),
455-
change.NextReplicaID(),
456-
kvstorage.ClearRangeDataOptions{
457-
ClearReplicatedBySpan: span,
458-
ClearReplicatedByRangeID: true,
459-
ClearUnreplicatedByRangeID: true,
460-
},
452+
ctx, b.batch, b.batch, b.r.destroyInfoRaftMuLocked(), change.NextReplicaID(),
461453
); err != nil {
462454
return errors.Wrapf(err, "unable to destroy replica before removal")
463455
}

pkg/kv/kvserver/replica_destroy.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,10 @@ func (r *Replica) destroyRaftMuLocked(ctx context.Context, nextReplicaID roachpb
8888
ms := r.GetMVCCStats()
8989
batch := r.store.TODOEngine().NewWriteBatch()
9090
defer batch.Close()
91-
desc := r.Desc()
92-
inited := desc.IsInitialized()
93-
94-
opts := kvstorage.ClearRangeDataOptions{
95-
ClearReplicatedBySpan: desc.RSpan(), // zero if !inited
96-
// TODO(tbg): if it's uninitialized, we might as well clear
97-
// the replicated state because there isn't any. This seems
98-
// like it would be simpler, but needs a code audit to ensure
99-
// callers don't call this in in-between states where the above
100-
// assumption doesn't hold.
101-
ClearReplicatedByRangeID: inited,
102-
ClearUnreplicatedByRangeID: true,
103-
}
91+
10492
// TODO(sep-raft-log): need both engines separately here.
10593
if err := kvstorage.DestroyReplica(
106-
ctx, r.store.TODOEngine(), batch,
107-
r.destroyInfoRaftMuLocked(), nextReplicaID, opts,
94+
ctx, r.store.TODOEngine(), batch, r.destroyInfoRaftMuLocked(), nextReplicaID,
10895
); err != nil {
10996
return err
11097
}

0 commit comments

Comments
 (0)