@@ -81,6 +81,12 @@ import (
8181//
8282// Executes the split trigger for the specified range on n1.
8383//
84+ // destroy-replica range-id=<int>
85+ // ----
86+ //
87+ // Destroys the replica on n1 for the specified range. The replica's state
88+ // must have already been created via create-replica.
89+ //
8490// print-range-state [sort-keys=<bool>]
8591// ----
8692//
@@ -149,7 +155,7 @@ func TestReplicaLifecycleDataDriven(t *testing.T) {
149155 if rs .replica != nil {
150156 return errors .New ("initialized replica already exists on n1/s1" ).Error ()
151157 }
152- repl := rs .getReplicaDescriptor (t , roachpb .NodeID (1 ))
158+ repl := rs .mustGetReplicaDescriptor (t , roachpb .NodeID (1 ))
153159
154160 batch := tc .storage .NewBatch ()
155161 defer batch .Close ()
@@ -210,7 +216,8 @@ func TestReplicaLifecycleDataDriven(t *testing.T) {
210216 replicaNodeID := dd .ScanArg [roachpb.NodeID ](t , d , "replica" )
211217 leaseType := dd .ScanArgOr (t , d , "lease-type" , "leader-lease" )
212218 rs := tc .mustGetRangeState (t , rangeID )
213- targetReplica := rs .getReplicaDescriptor (t , replicaNodeID )
219+ targetReplica := rs .mustGetReplicaDescriptor (t , replicaNodeID )
220+
214221 // NB: The details of the lease are not important to the test;
215222 // only the type is.
216223 var lease roachpb.Lease
@@ -283,6 +290,33 @@ func TestReplicaLifecycleDataDriven(t *testing.T) {
283290 // we manually split things out here.
284291 return strings .ReplaceAll (output , "\n \n " , "\n " )
285292
293+ case "destroy-replica" :
294+ rangeID := dd .ScanArg [roachpb.RangeID ](t , d , "range-id" )
295+ rs := tc .mustGetRangeState (t , rangeID )
296+ rs .mustGetReplicaDescriptor (t , roachpb .NodeID (1 )) // ensure replica exists
297+
298+ batch := tc .storage .NewBatch ()
299+ defer batch .Close ()
300+
301+ err := kvstorage .DestroyReplica (
302+ ctx ,
303+ kvstorage .TODOReadWriter (batch ),
304+ kvstorage.DestroyReplicaInfo {
305+ FullReplicaID : rs .replica .FullReplicaID ,
306+ Keys : roachpb.RSpan {Key : rs .desc .StartKey , EndKey : rs .desc .EndKey },
307+ },
308+ rs .desc .NextReplicaID ,
309+ )
310+ require .NoError (t , err )
311+ output , err := print .DecodeWriteBatch (batch .Repr ())
312+ require .NoError (t , err )
313+ err = batch .Commit (true )
314+ require .NoError (t , err )
315+
316+ // Clear the replica from the range state.
317+ rs .replica = nil
318+ return output
319+
286320 case "print-range-state" :
287321 var sb strings.Builder
288322 if len (tc .ranges ) == 0 {
@@ -440,7 +474,7 @@ func (tc *testCtx) updatePostSplitRangeState(
440474 tc .ranges [split .RightDesc .RangeID ] = rhsRangeState
441475}
442476
443- func (rs * rangeState ) getReplicaDescriptor (
477+ func (rs * rangeState ) mustGetReplicaDescriptor (
444478 t * testing.T , nodeID roachpb.NodeID ,
445479) * roachpb.ReplicaDescriptor {
446480 for i , repl := range rs .desc .InternalReplicas {
0 commit comments