@@ -37,6 +37,8 @@ import (
3737 "github.com/cockroachdb/cockroach/pkg/util/timeutil"
3838 "github.com/cockroachdb/cockroach/pkg/util/tracing"
3939 "github.com/cockroachdb/errors"
40+ "github.com/cockroachdb/pebble"
41+ "github.com/cockroachdb/pebble/objstorage/remote"
4042 "github.com/cockroachdb/redact"
4143 "github.com/kr/pretty"
4244 "golang.org/x/time/rate"
@@ -628,19 +630,32 @@ func addSSTablePreApply(
628630 sst .Span ,
629631 sst .RemoteFileLoc ,
630632 )
631- // TODO(bilal): replace this with the real ingest.
632- /*
633- start := storage.EngineKey{Key: sst.Span.Key}
634- end := storage.EngineKey{Key: sst.Span.EndKey}
635-
636- externalFile := pebble.ExternalFile{
637- Locator: shared.Locator(sst.RemoteFileLoc),
638- ObjName: sst.RemoteFilePath,
639- Size: sst.BackingFileSize,
640- SmallestUserKey: start.Encode(),
641- LargestUserKey: end.Encode(),
642- }*/
643- log .Fatalf (ctx , "Unsupported IngestRemoteFile" )
633+ start := storage.EngineKey {Key : sst .Span .Key }
634+ end := storage.EngineKey {Key : sst .Span .EndKey }
635+ externalFile := pebble.ExternalFile {
636+ Locator : remote .Locator (sst .RemoteFileLoc ),
637+ ObjName : sst .RemoteFilePath ,
638+ Size : sst .BackingFileSize ,
639+ SmallestUserKey : start .Encode (),
640+ LargestUserKey : end .Encode (),
641+ }
642+ tBegin := timeutil .Now ()
643+ defer func () {
644+ if dur := timeutil .Since (tBegin ); dur > addSSTPreApplyWarn .threshold && addSSTPreApplyWarn .ShouldLog () {
645+ log .Infof (ctx ,
646+ "ingesting SST of size %s at index %d took %.2fs" ,
647+ humanizeutil .IBytes (int64 (len (sst .Data ))), index , dur .Seconds (),
648+ )
649+ }
650+ }()
651+
652+ _ , ingestErr := env .eng .IngestExternalFiles (ctx , []pebble.ExternalFile {externalFile })
653+ if ingestErr != nil {
654+ log .Fatalf (ctx , "while ingesting %s: %v" , sst .RemoteFilePath , ingestErr )
655+ }
656+ // Adding without modification succeeded, no copy necessary.
657+ log .Eventf (ctx , "ingested SSTable at index %d, term %d: external %s" , index , term , sst .RemoteFilePath )
658+ return false
644659 }
645660 checksum := util .CRC32 (sst .Data )
646661
@@ -685,7 +700,7 @@ func addSSTablePreApply(
685700 }
686701
687702 // Regular path - we made a hard link, so we can ingest the hard link now.
688- ingestErr := env .eng .IngestExternalFiles (ctx , []string {ingestPath })
703+ ingestErr := env .eng .IngestLocalFiles (ctx , []string {ingestPath })
689704 if ingestErr != nil {
690705 log .Fatalf (ctx , "while ingesting %s: %v" , ingestPath , ingestErr )
691706 }
@@ -726,7 +741,7 @@ func ingestViaCopy(
726741 if err := kvserverbase .WriteFileSyncing (ctx , ingestPath , sst .Data , eng , 0600 , st , limiter ); err != nil {
727742 return errors .Wrapf (err , "while ingesting %s" , ingestPath )
728743 }
729- if err := eng .IngestExternalFiles (ctx , []string {ingestPath }); err != nil {
744+ if err := eng .IngestLocalFiles (ctx , []string {ingestPath }); err != nil {
730745 return errors .Wrapf (err , "while ingesting %s" , ingestPath )
731746 }
732747 log .Eventf (ctx , "ingested SSTable at index %d, term %d: %s" , index , term , ingestPath )
0 commit comments