@@ -8,6 +8,7 @@ package kvserver
88import (
99 "context"
1010 "encoding/binary"
11+ "fmt"
1112 "io"
1213 "path/filepath"
1314 "strconv"
@@ -21,6 +22,9 @@ import (
2122 "github.com/cockroachdb/cockroach/pkg/storage/fs"
2223 "github.com/cockroachdb/cockroach/pkg/storage/mvccencoding"
2324 "github.com/cockroachdb/cockroach/pkg/testutils"
25+ "github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
26+ "github.com/cockroachdb/cockroach/pkg/testutils/echotest"
27+ "github.com/cockroachdb/cockroach/pkg/testutils/storageutils"
2428 "github.com/cockroachdb/cockroach/pkg/util/hlc"
2529 "github.com/cockroachdb/cockroach/pkg/util/leaktest"
2630 "github.com/cockroachdb/cockroach/pkg/util/log"
@@ -30,6 +34,7 @@ import (
3034 "github.com/cockroachdb/errors/oserror"
3135 "github.com/cockroachdb/pebble/sstable"
3236 "github.com/cockroachdb/pebble/vfs"
37+ "github.com/cockroachdb/redact"
3338 "github.com/stretchr/testify/require"
3439 "golang.org/x/time/rate"
3540)
@@ -252,9 +257,10 @@ func TestSSTSnapshotStorageContextCancellation(t *testing.T) {
252257 require .ErrorIs (t , err , context .Canceled )
253258}
254259
255- // TestMultiSSTWriterInitSST tests that multiSSTWriter initializes each of the
256- // SST files associated with the replicated key ranges by writing a range
257- // deletion tombstone that spans the entire range of each respectively.
260+ // TestMultiSSTWriterInitSST tests the SSTS that multiSSTWriter generates.
261+ // In particular, certain SST files must contain range key deletes as well
262+ // as range deletes to make sure that ingesting the SST clears any existing
263+ // data.
258264func TestMultiSSTWriterInitSST (t * testing.T ) {
259265 defer leaktest .AfterTest (t )()
260266 defer log .Scope (t ).Close (t )
@@ -294,26 +300,13 @@ func TestMultiSSTWriterInitSST(t *testing.T) {
294300 actualSSTs = append (actualSSTs , sst )
295301 }
296302
297- // Construct an SST file for each of the key ranges and write a rangedel
298- // tombstone that spans from Start to End.
299- var expectedSSTs [][]byte
300- for _ , s := range keySpans {
301- func () {
302- sstFile := & storage.MemObject {}
303- sst := storage .MakeIngestionSSTWriter (ctx , cluster .MakeTestingClusterSettings (), sstFile )
304- defer sst .Close ()
305- err := sst .ClearRawRange (s .Key , s .EndKey , true , true )
306- require .NoError (t , err )
307- err = sst .Finish ()
308- require .NoError (t , err )
309- expectedSSTs = append (expectedSSTs , sstFile .Data ())
310- }()
311- }
303+ var buf redact.StringBuilder
312304
313- require .Equal (t , len (actualSSTs ), len (expectedSSTs ))
314305 for i := range fileNames {
315- require .Equal (t , actualSSTs [i ], expectedSSTs [i ])
306+ name := fmt .Sprintf ("sst%d" , i )
307+ require .NoError (t , storageutils .ReportSSTEntries (& buf , name , actualSSTs [i ]))
316308 }
309+ echotest .Require (t , buf .String (), filepath .Join (datapathutils .TestDataPath (t , "echotest" , t .Name ())))
317310}
318311
319312func buildIterForScratch (
0 commit comments