@@ -1727,6 +1727,7 @@ func TestStoreRangeMergeReadoptedBothFollowers(t *testing.T) {
1727
1727
mtc .Start (t , 3 )
1728
1728
defer mtc .Stop ()
1729
1729
store0 , store2 := mtc .Store (0 ), mtc .Store (2 )
1730
+ distSender := mtc .distSenders [0 ]
1730
1731
1731
1732
// Create two ranges on all nodes.
1732
1733
mtc .replicateRange (roachpb .RangeID (1 ), 1 , 2 )
@@ -1735,16 +1736,26 @@ func TestStoreRangeMergeReadoptedBothFollowers(t *testing.T) {
1735
1736
t .Fatal (err )
1736
1737
}
1737
1738
1738
- // Wait for store2 to hear about the split.
1739
- var lhsRepl2 , rhsRepl2 * storage.Replica
1740
- testutils .SucceedsSoon (t , func () error {
1741
- lhsRepl2 , err = store2 .GetReplica (lhsDesc .RangeID )
1742
- if err != nil {
1743
- return err
1739
+ // Wait for all stores to have fully processed the split.
1740
+ for _ , key := range []roachpb.Key {roachpb .Key ("a" ), roachpb .Key ("b" )} {
1741
+ if _ , pErr := client .SendWrapped (ctx , distSender , incrementArgs (key , 1 )); pErr != nil {
1742
+ t .Fatal (pErr )
1744
1743
}
1745
- rhsRepl2 , err = store2 .GetReplica (rhsDesc .RangeID )
1746
- return err
1747
- })
1744
+ mtc .waitForValues (key , []int64 {1 , 1 , 1 })
1745
+ }
1746
+
1747
+ lhsRepl0 , err := store0 .GetReplica (lhsDesc .RangeID )
1748
+ if err != nil {
1749
+ t .Fatal (err )
1750
+ }
1751
+ lhsRepl2 , err := store2 .GetReplica (lhsDesc .RangeID )
1752
+ if err != nil {
1753
+ t .Fatal (err )
1754
+ }
1755
+ rhsRepl2 , err := store2 .GetReplica (rhsDesc .RangeID )
1756
+ if err != nil {
1757
+ t .Fatal (err )
1758
+ }
1748
1759
1749
1760
// Abandon the two ranges on store2, but do not GC them.
1750
1761
mtc .unreplicateRange (lhsDesc .RangeID , 2 )
@@ -1757,13 +1768,6 @@ func TestStoreRangeMergeReadoptedBothFollowers(t *testing.T) {
1757
1768
t .Fatal (pErr )
1758
1769
}
1759
1770
1760
- // Attempt to re-add the merged range to store2. The operation should fail
1761
- // because store2's LHS and RHS replicas intersect the merged range.
1762
- lhsRepl0 , err := store0 .GetReplica (lhsDesc .RangeID )
1763
- if err != nil {
1764
- t .Fatal (err )
1765
- }
1766
-
1767
1771
addLHSRepl2 := func () error {
1768
1772
for r := retry .StartWithCtx (ctx , retry.Options {}); r .Next (); {
1769
1773
err := lhsRepl0 .ChangeReplicas (ctx , roachpb .ADD_REPLICA , roachpb.ReplicationTarget {
@@ -1778,6 +1782,8 @@ func TestStoreRangeMergeReadoptedBothFollowers(t *testing.T) {
1778
1782
return nil
1779
1783
}
1780
1784
1785
+ // Attempt to re-add the merged range to store2. The operation should fail
1786
+ // because store2's LHS and RHS replicas intersect the merged range.
1781
1787
err = addLHSRepl2 ()
1782
1788
if exp := "cannot apply snapshot: snapshot intersects existing range" ; ! testutils .IsError (err , exp ) {
1783
1789
t .Fatalf ("expected %q error, but got %v" , exp , err )
@@ -1903,22 +1909,25 @@ func TestStoreRangeMergeRaftSnapshot(t *testing.T) {
1903
1909
1904
1910
// Create three fully-caught-up, adjacent ranges on all three stores.
1905
1911
mtc .replicateRange (roachpb .RangeID (1 ), 1 , 2 )
1906
- splitKeys := []roachpb.Key {roachpb .Key ("a" ), roachpb .Key ("b" ), roachpb .Key ("c" )}
1907
- for _ , key := range splitKeys {
1908
- if _ , pErr := client .SendWrapped (ctx , distSender , adminSplitArgs (key )); pErr != nil {
1909
- t .Fatal (pErr )
1912
+ splitKeys := []roachpb.Key {roachpb .Key ("a" ), roachpb .Key ("b" ), roachpb .Key ("c" ), roachpb .Key ("d" )}
1913
+ for i , key := range splitKeys {
1914
+ if i != len (splitKeys )- 1 {
1915
+ // We'll split the last range off later.
1916
+ if _ , pErr := client .SendWrapped (ctx , distSender , adminSplitArgs (key )); pErr != nil {
1917
+ t .Fatal (pErr )
1918
+ }
1910
1919
}
1911
1920
if _ , pErr := client .SendWrapped (ctx , distSender , incrementArgs (key , 1 )); pErr != nil {
1912
1921
t .Fatal (pErr )
1913
1922
}
1914
1923
mtc .waitForValues (key , []int64 {1 , 1 , 1 })
1915
1924
}
1916
1925
1917
- lhsRepl0 := store0 .LookupReplica (roachpb .RKey ("a" ))
1926
+ aRepl0 := store0 .LookupReplica (roachpb .RKey ("a" ))
1918
1927
1919
1928
// Start dropping all Raft traffic to the first range on store1.
1920
1929
mtc .transport .Listen (store2 .Ident .StoreID , & unreliableRaftHandler {
1921
- rangeID : lhsRepl0 .RangeID ,
1930
+ rangeID : aRepl0 .RangeID ,
1922
1931
RaftMessageHandler : store2 ,
1923
1932
})
1924
1933
@@ -1929,6 +1938,13 @@ func TestStoreRangeMergeRaftSnapshot(t *testing.T) {
1929
1938
}
1930
1939
}
1931
1940
1941
+ // Split [a, /Max) into [a, d) and [d, /Max). This means the Raft snapshot
1942
+ // will span both a merge and a split.
1943
+ lastSplitKey := splitKeys [len (splitKeys )- 1 ]
1944
+ if _ , pErr := client .SendWrapped (ctx , distSender , adminSplitArgs (lastSplitKey )); pErr != nil {
1945
+ t .Fatal (pErr )
1946
+ }
1947
+
1932
1948
// Truncate the logs of the LHS.
1933
1949
{
1934
1950
repl := store0 .LookupReplica (roachpb .RKey ("a" ))
@@ -1970,10 +1986,15 @@ func TestStoreRangeMergeRaftSnapshot(t *testing.T) {
1970
1986
// Verify that the sets of keys in store0 and store2 are identical.
1971
1987
storeKeys0 := getEngineKeySet (t , store0 .Engine ())
1972
1988
storeKeys2 := getEngineKeySet (t , store2 .Engine ())
1989
+ dRepl0 := store0 .LookupReplica (roachpb .RKey ("d" ))
1973
1990
ignoreKey := func (k string ) bool {
1974
- // Unreplicated keys for the two remaining ranges are allowed to differ.
1975
- return strings .HasPrefix (k , string (keys .MakeRangeIDUnreplicatedPrefix (roachpb .RangeID (1 )))) ||
1976
- strings .HasPrefix (k , string (keys .MakeRangeIDUnreplicatedPrefix (lhsRepl0 .RangeID )))
1991
+ // Unreplicated keys for the remaining ranges are allowed to differ.
1992
+ for _ , id := range []roachpb.RangeID {1 , aRepl0 .RangeID , dRepl0 .RangeID } {
1993
+ if strings .HasPrefix (k , string (keys .MakeRangeIDUnreplicatedPrefix (id ))) {
1994
+ return true
1995
+ }
1996
+ }
1997
+ return false
1977
1998
}
1978
1999
for k := range storeKeys0 {
1979
2000
if ignoreKey (k ) {
0 commit comments