@@ -71,6 +71,7 @@ import (
71
71
"github.com/cockroachdb/errors"
72
72
"github.com/cockroachdb/redact"
73
73
"github.com/kr/pretty"
74
+ "github.com/stretchr/testify/assert"
74
75
"github.com/stretchr/testify/require"
75
76
"golang.org/x/exp/slices"
76
77
"golang.org/x/sync/errgroup"
@@ -620,11 +621,7 @@ func TestStoreAddRemoveRanges(t *testing.T) {
620
621
t .Error (err )
621
622
}
622
623
// Remove range 1.
623
- if err := store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
624
- DestroyData : true ,
625
- }); err != nil {
626
- t .Error (err )
627
- }
624
+ assert .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
628
625
// Create a new range (id=2).
629
626
repl2 := createReplica (store , 2 , roachpb .RKey ("a" ), roachpb .RKey ("b" ))
630
627
if err := store .AddReplica (repl2 ); err != nil {
@@ -636,11 +633,7 @@ func TestStoreAddRemoveRanges(t *testing.T) {
636
633
t .Fatal ("expected error re-adding same range" )
637
634
}
638
635
// Try to remove range 1 again.
639
- if err := store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
640
- DestroyData : true ,
641
- }); err != nil {
642
- t .Fatalf ("didn't expect error re-removing same range: %v" , err )
643
- }
636
+ require .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
644
637
// Try to add a range with previously-used (but now removed) ID.
645
638
repl2Dup := createReplica (store , 1 , roachpb .RKey ("a" ), roachpb .RKey ("b" ))
646
639
if err := store .AddReplica (repl2Dup ); err == nil {
@@ -742,26 +735,29 @@ func TestStoreRemoveReplicaDestroy(t *testing.T) {
742
735
t .Fatal (err )
743
736
}
744
737
745
- // Can't remove Replica with DestroyData false because this requires the destroyStatus
746
- // to already have been set by the caller (but we didn't).
747
- require .ErrorContains (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
748
- DestroyData : false ,
749
- }), `replica not marked as destroyed` )
738
+ rmWithoutData := func () error {
739
+ repl1 .raftMu .Lock ()
740
+ defer repl1 .raftMu .Unlock ()
741
+ _ , err := store .removeInitializedReplicaRaftMuLocked (
742
+ ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()),
743
+ RemoveOptions {DestroyData : false },
744
+ )
745
+ return err
746
+ }
747
+ // Can't remove Replica with DestroyData false because this requires the
748
+ // destroyStatus to already have been set by the caller (but we didn't).
749
+ require .ErrorContains (t , rmWithoutData (), `replica not marked as destroyed` )
750
750
751
751
// Remove the Replica twice, as this should be idempotent.
752
752
// NB: we rely on this idempotency today (as @tbg found out when he accidentally
753
753
// removed it).
754
754
for i := 0 ; i < 2 ; i ++ {
755
- require .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
756
- DestroyData : true ,
757
- }), "%d" , i )
755
+ require .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())), "%d" , i )
758
756
}
759
757
760
- // However, if we have DestroyData=false, caller is expected to be the unique first "destroyer"
761
- // of the Replica.
762
- require .ErrorContains (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
763
- DestroyData : false ,
764
- }), `does not exist` )
758
+ // However, if we have DestroyData=false, caller is expected to be the unique
759
+ // first "destroyer" of the Replica.
760
+ require .ErrorContains (t , rmWithoutData (), `does not exist` )
765
761
766
762
// Verify that removal of a replica marks it as destroyed so that future raft
767
763
// commands on the Replica will silently be dropped.
@@ -802,11 +798,7 @@ func TestStoreReplicaVisitor(t *testing.T) {
802
798
if err != nil {
803
799
t .Error (err )
804
800
}
805
- if err := store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
806
- DestroyData : true ,
807
- }); err != nil {
808
- t .Error (err )
809
- }
801
+ assert .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
810
802
811
803
// Add 10 new ranges.
812
804
const newCount = 10
@@ -883,14 +875,8 @@ func TestMarkReplicaInitialized(t *testing.T) {
883
875
884
876
// Clobber the existing range so we can test overlaps that aren't KeyMin or KeyMax.
885
877
repl1 , err := store .GetReplica (1 )
886
- if err != nil {
887
- t .Error (err )
888
- }
889
- if err := store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
890
- DestroyData : true ,
891
- }); err != nil {
892
- t .Error (err )
893
- }
878
+ assert .NoError (t , err )
879
+ assert .NoError (t , store .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
894
880
895
881
repl := createReplica (store , roachpb .RangeID (2 ), roachpb .RKey ("a" ), roachpb .RKey ("c" ))
896
882
if err := store .AddReplica (repl ); err != nil {
@@ -2754,14 +2740,8 @@ func TestMaybeRemove(t *testing.T) {
2754
2740
store .WaitForInit ()
2755
2741
2756
2742
repl , err := store .GetReplica (1 )
2757
- if err != nil {
2758
- t .Error (err )
2759
- }
2760
- if err := store .RemoveReplica (ctx , repl , repl .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
2761
- DestroyData : true ,
2762
- }); err != nil {
2763
- t .Error (err )
2764
- }
2743
+ assert .NoError (t , err )
2744
+ assert .NoError (t , store .RemoveReplica (ctx , repl , repl .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
2765
2745
// MaybeRemove is called.
2766
2746
removedRng := <- fq .maybeRemovedRngs
2767
2747
if removedRng != repl .RangeID {
@@ -2873,14 +2853,8 @@ func TestStoreRangePlaceholders(t *testing.T) {
2873
2853
2874
2854
// Clobber the existing range so we can test non-overlapping placeholders.
2875
2855
repl1 , err := s .GetReplica (1 )
2876
- if err != nil {
2877
- t .Error (err )
2878
- }
2879
- if err := s .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
2880
- DestroyData : true ,
2881
- }); err != nil {
2882
- t .Error (err )
2883
- }
2856
+ assert .NoError (t , err )
2857
+ assert .NoError (t , s .RemoveReplica (ctx , repl1 , repl1 .Desc ().NextReplicaID , redact .SafeString (t .Name ())))
2884
2858
2885
2859
repID := roachpb .RangeID (2 )
2886
2860
rep := createReplica (s , repID , roachpb .RKeyMin , roachpb .RKey ("c" ))
@@ -3012,9 +2986,7 @@ func TestStoreRemovePlaceholderOnRaftIgnored(t *testing.T) {
3012
2986
repl1 , err := s .GetReplica (1 )
3013
2987
desc := repl1 .Desc ()
3014
2988
require .NoError (t , err )
3015
- require .NoError (t , s .RemoveReplica (ctx , repl1 , desc .NextReplicaID , redact .SafeString (t .Name ()), RemoveOptions {
3016
- DestroyData : true ,
3017
- }))
2989
+ require .NoError (t , s .RemoveReplica (ctx , repl1 , desc .NextReplicaID , redact .SafeString (t .Name ())))
3018
2990
3019
2991
// Wrap the snapshot in a minimal header. The request will be dropped because
3020
2992
// replica 2 is not in the ConfState.
0 commit comments