@@ -343,6 +343,7 @@ func restore(
343343 spanCh ,
344344 )
345345 }
346+
346347 // Count number of import spans.
347348 var numImportSpans int
348349 var countTasks []func (ctx context.Context ) error
@@ -3177,8 +3178,46 @@ func sendAddRemoteSSTs(
31773178 return genSpan (ctx , restoreSpanEntriesCh )
31783179 })
31793180 remainingBytesInTargetRange := int64 (512 << 20 )
3181+
3182+ // We lost the string URIs for the backup storage locations very early in the
3183+ // process of planning the restore, when the backups were resolved, and the
3184+ // parsed proto versions -- which we usually prefer -- were attached to the
3185+ // backup manifests and the individual files during span generation. However
3186+ // for telling pebble the locations of the files we need those raw string URIs
3187+ // again. We could plumb them side-by-side with the proto versions, but for
3188+ // now we'll just reverse engineer them: we'll make a map that has the proto
3189+ // version of every URI we might have parsed -- all the default backup URIs
3190+ // and any locality bucket URIs -- to the raw URI that produces that proto.
3191+ // We can then look in this map using the proto attached to each file to find
3192+ // the URI for that file.
3193+ // TODO(dt/butler): should we plumb the original string instead?
3194+ urisForDirs := make (map [cloudpb.ExternalStorage ]string )
3195+ for _ , u := range uris {
3196+ dir , err := cloud .ExternalStorageConfFromURI (u , username.SQLUsername {})
3197+ if err != nil {
3198+ return err
3199+ }
3200+ urisForDirs [dir ] = u
3201+ }
3202+ for _ , loc := range backupLocalityInfo {
3203+ for _ , u := range loc .URIsByOriginalLocalityKV {
3204+ dir , err := cloud .ExternalStorageConfFromURI (u , username.SQLUsername {})
3205+ if err != nil {
3206+ return err
3207+ }
3208+ urisForDirs [dir ] = u
3209+ }
3210+ }
3211+
3212+ openedStorages := make (map [cloudpb.ExternalStorage ]cloud.ExternalStorage )
3213+ defer func () {
3214+ for _ , es := range openedStorages {
3215+ es .Close ()
3216+ }
3217+ }()
3218+
31803219 for entry := range restoreSpanEntriesCh {
3181- for i , file := range entry .Files {
3220+ for _ , file := range entry .Files {
31823221
31833222 log .Infof (ctx , "Experimental restore: sending span %s of file %s" ,
31843223 file .BackupFileEntrySpan , file .Path )
@@ -3202,8 +3241,28 @@ func sendAddRemoteSSTs(
32023241 }
32033242 }
32043243
3244+ if file .BackingFileSize == 0 {
3245+ if _ , ok := openedStorages [file .Dir ]; ! ok {
3246+ es , err := execCtx .ExecCfg ().DistSQLSrv .ExternalStorage (ctx , file .Dir )
3247+ if err != nil {
3248+ return err
3249+ }
3250+ openedStorages [file .Dir ] = es
3251+ }
3252+
3253+ sz , err := openedStorages [file .Dir ].Size (ctx , file .Path )
3254+ if err != nil {
3255+ return err
3256+ }
3257+ file .BackingFileSize = uint64 (sz )
3258+ }
3259+ uri , ok := urisForDirs [file .Dir ]
3260+ if ! ok {
3261+ return errors .AssertionFailedf ("URI not found for %s" , file .Dir .String ())
3262+ }
3263+
32053264 loc := kvpb.AddSSTableRequest_RemoteFile {
3206- Locator : uris [ i ] ,
3265+ Locator : uri ,
32073266 Path : file .Path ,
32083267 BackingFileSize : file .BackingFileSize ,
32093268 }
0 commit comments