@@ -2645,6 +2645,7 @@ func TestMVCCGarbageCollect(t *testing.T) {
2645
2645
val1 := roachpb .MakeValueFromBytesAndTimestamp (bytes , ts1 )
2646
2646
val2 := roachpb .MakeValueFromBytesAndTimestamp (bytes , ts2 )
2647
2647
val3 := roachpb .MakeValueFromBytesAndTimestamp (bytes , ts3 )
2648
+ valInline := roachpb .MakeValueFromBytesAndTimestamp (bytes , roachpb .ZeroTimestamp )
2648
2649
2649
2650
testData := []struct {
2650
2651
key roachpb.Key
@@ -2655,6 +2656,7 @@ func TestMVCCGarbageCollect(t *testing.T) {
2655
2656
{roachpb .Key ("a-del" ), []roachpb.Value {val1 , val2 }, true },
2656
2657
{roachpb .Key ("b" ), []roachpb.Value {val1 , val2 , val3 }, false },
2657
2658
{roachpb .Key ("b-del" ), []roachpb.Value {val1 , val2 , val3 }, true },
2659
+ {roachpb .Key ("inline" ), []roachpb.Value {valInline }, false },
2658
2660
}
2659
2661
2660
2662
for i := 0 ; i < 3 ; i ++ {
@@ -2677,12 +2679,12 @@ func TestMVCCGarbageCollect(t *testing.T) {
2677
2679
}
2678
2680
}
2679
2681
}
2680
- kvsn , err := Scan ( engine , mvccKey ( keyMin ), mvccKey ( keyMax ), 0 )
2681
- if err != nil {
2682
- t . Fatal ( err )
2683
- }
2684
- for i , kv := range kvsn {
2685
- if log . V ( 1 ) {
2682
+ if log . V ( 1 ) {
2683
+ kvsn , err := Scan ( engine , mvccKey ( keyMin ), mvccKey ( keyMax ), 0 )
2684
+ if err != nil {
2685
+ t . Fatal ( err )
2686
+ }
2687
+ for i , kv := range kvsn {
2686
2688
log .Infof ("%d: %s" , i , kv .Key )
2687
2689
}
2688
2690
}
@@ -2692,6 +2694,10 @@ func TestMVCCGarbageCollect(t *testing.T) {
2692
2694
{Key : roachpb .Key ("a-del" ), Timestamp : ts2 },
2693
2695
{Key : roachpb .Key ("b" ), Timestamp : ts1 },
2694
2696
{Key : roachpb .Key ("b-del" ), Timestamp : ts2 },
2697
+ {Key : roachpb .Key ("inline" ), Timestamp : roachpb .ZeroTimestamp },
2698
+ // Keys that don't exist, which should result in a no-op.
2699
+ {Key : roachpb .Key ("a-bad" ), Timestamp : ts2 },
2700
+ {Key : roachpb .Key ("inline-bad" ), Timestamp : roachpb .ZeroTimestamp },
2695
2701
}
2696
2702
if err := MVCCGarbageCollect (engine , ms , keys , ts3 ); err != nil {
2697
2703
t .Fatal (err )
@@ -2761,21 +2767,40 @@ func TestMVCCGarbageCollectNonDeleted(t *testing.T) {
2761
2767
ts2 := makeTS (2E9 , 0 )
2762
2768
val1 := mkVal (s , ts1 )
2763
2769
val2 := mkVal (s , ts2 )
2764
- key := roachpb .Key ("a" )
2765
- vals := []roachpb.Value {val1 , val2 }
2766
- for _ , val := range vals {
2767
- valCpy := * util .CloneProto (& val ).(* roachpb.Value )
2768
- valCpy .Timestamp = roachpb .ZeroTimestamp
2769
- if err := MVCCPut (engine , nil , key , val .Timestamp , valCpy , nil ); err != nil {
2770
- t .Fatal (err )
2771
- }
2772
- }
2773
- keys := []roachpb.GCRequest_GCKey {
2774
- {Key : roachpb .Key ("a" ), Timestamp : ts2 },
2770
+ valInline := mkVal (s , roachpb .ZeroTimestamp )
2771
+
2772
+ testData := []struct {
2773
+ key roachpb.Key
2774
+ vals []roachpb.Value
2775
+ expError string
2776
+ }{
2777
+ {roachpb .Key ("a" ), []roachpb.Value {val1 , val2 }, `request to GC non-deleted, latest value ok "a"` },
2778
+ {roachpb .Key ("inline" ), []roachpb.Value {valInline }, "" },
2775
2779
}
2776
- if err := MVCCGarbageCollect (engine , nil , keys , ts2 ); err == nil {
2777
- t .Fatal ("expected error garbage collecting a non-deleted live value" )
2780
+
2781
+ for _ , test := range testData {
2782
+ for _ , val := range test .vals {
2783
+ valCpy := * util .CloneProto (& val ).(* roachpb.Value )
2784
+ valCpy .Timestamp = roachpb .ZeroTimestamp
2785
+ if err := MVCCPut (engine , nil , test .key , val .Timestamp , valCpy , nil ); err != nil {
2786
+ t .Fatal (err )
2787
+ }
2788
+ }
2789
+ keys := []roachpb.GCRequest_GCKey {
2790
+ {Key : test .key , Timestamp : ts2 },
2791
+ }
2792
+ err := MVCCGarbageCollect (engine , nil , keys , ts2 )
2793
+ if test .expError == "" {
2794
+ if err != nil {
2795
+ t .Fatalf ("expected no error garbage collecting a non-deleted inline live value, found %v" , err )
2796
+ }
2797
+ } else {
2798
+ if testutils .IsError (err , test .expError ) {
2799
+ t .Fatalf ("expected error %q when garbage collecting a non-deleted live value, found %v" , test .expError , err )
2800
+ }
2801
+ }
2778
2802
}
2803
+
2779
2804
}
2780
2805
2781
2806
// TestMVCCGarbageCollectIntent verifies that an intent cannot be GC'd.
@@ -2800,7 +2825,7 @@ func TestMVCCGarbageCollectIntent(t *testing.T) {
2800
2825
t .Fatal (err )
2801
2826
}
2802
2827
keys := []roachpb.GCRequest_GCKey {
2803
- {Key : roachpb . Key ( "a" ) , Timestamp : ts2 },
2828
+ {Key : key , Timestamp : ts2 },
2804
2829
}
2805
2830
if err := MVCCGarbageCollect (engine , nil , keys , ts2 ); err == nil {
2806
2831
t .Fatal ("expected error garbage collecting an intent" )
0 commit comments