Skip to content

Commit c87fa68

Browse files
committed
backup: use WriteBackupMetadata in backup
Epic: none Release note: none
1 parent bfd2b20 commit c87fa68

File tree

2 files changed

+6
-82
lines changed

2 files changed

+6
-82
lines changed

pkg/backup/backup_job.go

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"strings"
1616
"time"
1717

18-
"github.com/cockroachdb/cockroach/pkg/backup/backupbase"
1918
"github.com/cockroachdb/cockroach/pkg/backup/backupdest"
2019
"github.com/cockroachdb/cockroach/pkg/backup/backupencryption"
2120
"github.com/cockroachdb/cockroach/pkg/backup/backupinfo"
@@ -24,7 +23,6 @@ import (
2423
"github.com/cockroachdb/cockroach/pkg/build"
2524
"github.com/cockroachdb/cockroach/pkg/ccl/kvccl/kvfollowerreadsccl"
2625
"github.com/cockroachdb/cockroach/pkg/cloud"
27-
"github.com/cockroachdb/cockroach/pkg/cloud/cloudpb"
2826
"github.com/cockroachdb/cockroach/pkg/clusterversion"
2927
"github.com/cockroachdb/cockroach/pkg/jobs"
3028
"github.com/cockroachdb/cockroach/pkg/jobs/joberror"
@@ -124,10 +122,8 @@ func backup(
124122
details jobspb.BackupDetails,
125123
settings *cluster.Settings,
126124
defaultStore cloud.ExternalStorage,
127-
storageByLocalityKV map[string]*cloudpb.ExternalStorage,
128125
resumer *backupResumer,
129126
backupManifest *backuppb.BackupManifest,
130-
makeExternalStorage cloud.ExternalStorageFactory,
131127
) (_ roachpb.RowCount, numBackupInstances int, _ error) {
132128
resumerSpan := tracing.SpanFromContext(ctx)
133129
var lastCheckpoint time.Time
@@ -384,77 +380,11 @@ func backup(
384380
}
385381
}
386382

387-
backupID := uuid.MakeV4()
388-
backupManifest.ID = backupID
389-
// Write additional partial descriptors to each node for partitioned backups.
390-
if len(storageByLocalityKV) > 0 {
391-
resumerSpan.RecordStructured(&types.StringValue{Value: "writing partition descriptors for partitioned backup"})
392-
filesByLocalityKV := make(map[string][]backuppb.BackupManifest_File)
393-
for _, file := range backupManifest.Files {
394-
filesByLocalityKV[file.LocalityKV] = append(filesByLocalityKV[file.LocalityKV], file)
395-
}
396-
397-
nextPartitionedDescFilenameID := 1
398-
for kv, conf := range storageByLocalityKV {
399-
backupManifest.LocalityKVs = append(backupManifest.LocalityKVs, kv)
400-
// Set a unique filename for each partition backup descriptor. The ID
401-
// ensures uniqueness, and the kv string appended to the end is for
402-
// readability.
403-
filename := fmt.Sprintf("%s_%d_%s", backupbase.BackupPartitionDescriptorPrefix,
404-
nextPartitionedDescFilenameID, backupinfo.SanitizeLocalityKV(kv))
405-
nextPartitionedDescFilenameID++
406-
backupManifest.PartitionDescriptorFilenames = append(backupManifest.PartitionDescriptorFilenames, filename)
407-
desc := backuppb.BackupPartitionDescriptor{
408-
LocalityKV: kv,
409-
Files: filesByLocalityKV[kv],
410-
BackupID: backupID,
411-
}
412-
413-
if err := func() error {
414-
store, err := makeExternalStorage(ctx, *conf)
415-
if err != nil {
416-
return err
417-
}
418-
defer store.Close()
419-
return backupinfo.WriteBackupPartitionDescriptor(ctx, store, filename,
420-
encryption, &kmsEnv, &desc)
421-
}(); err != nil {
422-
return roachpb.RowCount{}, 0, err
423-
}
424-
}
425-
}
426-
427-
// TODO(msbutler): version gate writing the old manifest once we can guarantee
428-
// a cluster version that will not read the old manifest. This will occur when we delete
429-
// LegacyFindPriorBackups and the fallback path in
430-
// ListFullBackupsInCollection, which can occur when we completely rely on the
431-
// backup index.
432-
if err := backupinfo.WriteBackupManifest(ctx, defaultStore, backupbase.DeprecatedBackupManifestName,
433-
encryption, &kmsEnv, backupManifest); err != nil {
434-
return roachpb.RowCount{}, 0, err
435-
}
436-
437-
if err := backupinfo.WriteMetadataWithExternalSSTs(ctx, defaultStore, encryption,
438-
&kmsEnv, backupManifest); err != nil {
439-
return roachpb.RowCount{}, 0, err
440-
}
441-
442383
statsTable := getTableStatsForBackup(ctx, execCtx.ExecCfg().InternalDB.Executor(), backupManifest.Descriptors)
443-
if err := backupinfo.WriteTableStatistics(ctx, defaultStore, encryption, &kmsEnv, &statsTable); err != nil {
384+
if err := backupinfo.WriteBackupMetadata(ctx, execCtx, defaultStore, details, &kmsEnv, backupManifest, statsTable); err != nil {
444385
return roachpb.RowCount{}, 0, err
445386
}
446387

447-
if err := backupinfo.WriteBackupIndexMetadata(
448-
ctx,
449-
execCtx.ExecCfg(),
450-
execCtx.User(),
451-
execCtx.ExecCfg().DistSQLSrv.ExternalStorageFromURI,
452-
details,
453-
backupManifest.RevisionStartTime,
454-
); err != nil {
455-
return roachpb.RowCount{}, 0, errors.Wrapf(err, "writing backup index metadata")
456-
}
457-
458388
return backupManifest.EntryCounts, numBackupInstances, nil
459389
}
460390

@@ -692,15 +622,6 @@ func (b *backupResumer) Resume(ctx context.Context, execCtx interface{}) error {
692622
}
693623
}
694624

695-
storageByLocalityKV := make(map[string]*cloudpb.ExternalStorage)
696-
for kv, uri := range details.URIsByLocalityKV {
697-
conf, err := cloud.ExternalStorageConfFromURI(uri, p.User())
698-
if err != nil {
699-
return err
700-
}
701-
storageByLocalityKV[kv] = &conf
702-
}
703-
704625
mem := p.ExecCfg().RootMemoryMonitor.MakeBoundAccount()
705626
defer mem.Close(ctx)
706627
var memSize int64
@@ -742,10 +663,8 @@ func (b *backupResumer) Resume(ctx context.Context, execCtx interface{}) error {
742663
details,
743664
p.ExecCfg().Settings,
744665
defaultStore,
745-
storageByLocalityKV,
746666
b,
747667
backupManifest,
748-
p.ExecCfg().DistSQLSrv.ExternalStorage,
749668
)
750669
if err == nil {
751670
break

pkg/backup/backupinfo/manifest_handling.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,11 @@ func WriteBackupMetadata(
18411841
}
18421842
}
18431843

1844+
// TODO(msbutler): version gate writing the old manifest once we can guarantee
1845+
// a cluster version that will not read the old manifest. This will occur when we delete
1846+
// LegacyFindPriorBackups and the fallback path in
1847+
// ListFullBackupsInCollection, which can occur when we completely rely on the
1848+
// backup index.
18441849
if err := WriteBackupManifest(ctx, store, backupbase.DeprecatedBackupManifestName,
18451850
details.EncryptionOptions, kmsEnv, backupManifest); err != nil {
18461851
return err

0 commit comments

Comments
 (0)