@@ -21,12 +21,9 @@ import (
21
21
"github.com/cockroachdb/pebble/internal/cache"
22
22
"github.com/cockroachdb/pebble/internal/humanize"
23
23
"github.com/cockroachdb/pebble/internal/keyspan"
24
- "github.com/cockroachdb/pebble/internal/manifest"
25
24
"github.com/cockroachdb/pebble/internal/rangedel"
26
25
"github.com/cockroachdb/pebble/internal/sstableinternal"
27
- "github.com/cockroachdb/pebble/record"
28
26
"github.com/cockroachdb/pebble/sstable"
29
- "github.com/cockroachdb/pebble/sstable/blob"
30
27
"github.com/cockroachdb/pebble/vfs"
31
28
"github.com/spf13/cobra"
32
29
)
@@ -346,7 +343,7 @@ func (s *sstableT) runScan(cmd *cobra.Command, args []string) {
346
343
// containing the manifest(s) and blob file(s).
347
344
blobMode := ConvertToBlobRefMode (s .blobMode )
348
345
var blobDir string
349
- var blobRefsMap map [base. FileNum ] * manifest. BlobReferences
346
+ var blobMappings * blobFileMappings
350
347
if blobMode == BlobRefModeLoad {
351
348
if len (args ) < 2 {
352
349
fmt .Fprintf (stderr , "when --blob-mode=load is specified, the path to a " +
@@ -355,12 +352,17 @@ func (s *sstableT) runScan(cmd *cobra.Command, args []string) {
355
352
}
356
353
blobDir = args [len (args )- 1 ]
357
354
args = args [:len (args )- 1 ]
358
- var err error
359
- blobRefsMap , err = findAndReadManifests (stderr , s .opts .FS , blobDir )
355
+ manifests , err := findManifests (stderr , s .opts .FS , blobDir )
360
356
if err != nil {
361
357
fmt .Fprintf (stderr , "%s\n " , err )
362
358
return
363
359
}
360
+ blobMappings , err = newBlobFileMappings (stderr , s .opts .FS , blobDir , manifests )
361
+ if err != nil {
362
+ fmt .Fprintf (stderr , "%s\n " , err )
363
+ return
364
+ }
365
+ defer func () { _ = blobMappings .Close () }()
364
366
}
365
367
366
368
s .foreachSstable (stderr , args , func (path string , r * sstable.Reader , props sstable.Properties ) {
@@ -389,15 +391,8 @@ func (s *sstableT) runScan(cmd *cobra.Command, args []string) {
389
391
fmt .Fprintf (stderr , "unset file in path %s\n " , path )
390
392
return
391
393
}
392
- provider := debugReaderProvider {
393
- fs : s .opts .FS ,
394
- dir : blobDir ,
395
- }
396
394
s .fmtValue .mustSet ("[%s]" )
397
- var vf * blob.ValueFetcher
398
- blobRefs := blobRefsMap [base .PhysicalTableFileNum (r .BlockReader ().FileNum ())]
399
- vf , blobContext = sstable .LoadValBlobContext (& provider , blobRefs )
400
- defer func () { _ = vf .Close () }()
395
+ blobContext = blobMappings .LoadValueBlobContext (base .PhysicalTableFileNum (r .BlockReader ().FileNum ()))
401
396
default :
402
397
blobContext = sstable .AssertNoBlobHandles
403
398
}
@@ -622,57 +617,3 @@ func (s *sstableT) foreachSstable(
622
617
})
623
618
}
624
619
}
625
-
626
- // findAndReadManifests finds and reads all manifests in the specified
627
- // directory to gather blob references for each sstable.
628
- func findAndReadManifests (
629
- stderr io.Writer , fs vfs.FS , dir string ,
630
- ) (map [base.FileNum ]* manifest.BlobReferences , error ) {
631
- blobRefsMap := make (map [base.FileNum ]* manifest.BlobReferences )
632
- var manifests []fileLoc
633
- walk (stderr , fs , dir , func (path string ) {
634
- ft , fileNum , ok := base .ParseFilename (fs , path )
635
- if ! ok {
636
- return
637
- }
638
- fl := fileLoc {DiskFileNum : fileNum , path : path }
639
- switch ft {
640
- case base .FileTypeManifest :
641
- manifests = append (manifests , fl )
642
- }
643
- })
644
- if len (manifests ) == 0 {
645
- return nil , errors .New ("no MANIFEST files found in the given path" )
646
- }
647
- slices .SortFunc (manifests , cmpFileLoc )
648
- for _ , fl := range manifests {
649
- func () {
650
- mf , err := fs .Open (fl .path )
651
- if err != nil {
652
- fmt .Fprintf (stderr , "%s\n " , err )
653
- return
654
- }
655
- defer mf .Close ()
656
-
657
- rr := record .NewReader (mf , 0 /* logNum */ )
658
- for {
659
- r , err := rr .Next ()
660
- if err != nil {
661
- if err != io .EOF {
662
- fmt .Fprintf (stderr , "%s: %s\n " , fl .path , err )
663
- }
664
- break
665
- }
666
- var ve manifest.VersionEdit
667
- if err = ve .Decode (r ); err != nil {
668
- fmt .Fprintf (stderr , "%s: %s\n " , fl .path , err )
669
- break
670
- }
671
- for _ , nf := range ve .NewTables {
672
- blobRefsMap [nf .Meta .TableNum ] = & nf .Meta .BlobReferences
673
- }
674
- }
675
- }()
676
- }
677
- return blobRefsMap , nil
678
- }
0 commit comments