Skip to content

Commit 63b334d

Browse files
committed
PBM-1397: collect all errors from checkLogicalBackupFiles
1 parent 976cdc7 commit 63b334d

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

pbm/backup/storage.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"runtime"
88
"sync"
99

10-
"golang.org/x/sync/errgroup"
11-
1210
"github.com/percona/percona-backup-mongodb/pbm/archive"
1311
"github.com/percona/percona-backup-mongodb/pbm/defs"
1412
"github.com/percona/percona-backup-mongodb/pbm/errors"
1513
"github.com/percona/percona-backup-mongodb/pbm/storage"
1614
sfs "github.com/percona/percona-backup-mongodb/pbm/storage/fs"
15+
"github.com/percona/percona-backup-mongodb/pbm/util"
1716
"github.com/percona/percona-backup-mongodb/pbm/version"
1817
)
1918

@@ -45,7 +44,7 @@ func ReadMetadata(stg storage.Storage, filename string) (*BackupMeta, error) {
4544
func CheckBackupDataFiles(ctx context.Context, stg storage.Storage, bcp *BackupMeta) error {
4645
switch bcp.Type {
4746
case defs.LogicalBackup:
48-
return checkLogicalBackupFiles(ctx, stg, bcp)
47+
return checkLogicalBackupDataFiles(ctx, stg, bcp)
4948
case defs.PhysicalBackup, defs.IncrementalBackup:
5049
return checkPhysicalBackupFiles(ctx, stg, bcp)
5150
case defs.ExternalBackup:
@@ -55,57 +54,61 @@ func CheckBackupDataFiles(ctx context.Context, stg storage.Storage, bcp *BackupM
5554
return errors.Errorf("unknown backup type %s", bcp.Type)
5655
}
5756

58-
func checkLogicalBackupFiles(ctx context.Context, stg storage.Storage, bcp *BackupMeta) error {
57+
func checkLogicalBackupDataFiles(_ context.Context, stg storage.Storage, bcp *BackupMeta) error {
5958
legacy := version.IsLegacyArchive(bcp.PBMVersion)
60-
eg, _ := errgroup.WithContext(ctx)
59+
60+
eg := util.NewErrorGroup(runtime.NumCPU() * 2)
6161
for _, rs := range bcp.Replsets {
62-
rs := rs
62+
eg.Go(func() error {
63+
eg.Go(func() error { return checkFile(stg, rs.DumpName) })
6364

64-
eg.Go(func() error { return checkFile(stg, rs.DumpName) })
65+
eg.Go(func() error {
66+
if version.IsLegacyBackupOplog(bcp.PBMVersion) {
67+
return checkFile(stg, rs.OplogName)
68+
}
6569

66-
eg.Go(func() error {
67-
if version.IsLegacyBackupOplog(bcp.PBMVersion) {
68-
return checkFile(stg, rs.OplogName)
70+
files, err := stg.List(rs.OplogName, "")
71+
if err != nil {
72+
return errors.Wrap(err, "list")
73+
}
74+
if len(files) == 0 {
75+
return errors.Wrap(err, "no oplog files")
76+
}
77+
for i := range files {
78+
if files[i].Size == 0 {
79+
return errors.Errorf("%q is empty", path.Join(rs.OplogName, files[i].Name))
80+
}
81+
}
82+
83+
return nil
84+
})
85+
86+
if legacy {
87+
return nil
6988
}
7089

71-
files, err := stg.List(rs.OplogName, "")
90+
nss, err := ReadArchiveNamespaces(stg, rs.DumpName)
7291
if err != nil {
73-
return errors.Wrap(err, "list")
74-
}
75-
if len(files) == 0 {
76-
return errors.Wrap(err, "no oplog files")
92+
return errors.Wrapf(err, "parse metafile %q", rs.DumpName)
7793
}
78-
for i := range files {
79-
if files[i].Size == 0 {
80-
return errors.Errorf("%q is empty", path.Join(rs.OplogName, files[i].Name))
81-
}
82-
}
83-
84-
return nil
85-
})
8694

87-
if legacy {
88-
continue
89-
}
95+
for _, ns := range nss {
96+
if ns.Size == 0 {
97+
continue
98+
}
9099

91-
nss, err := ReadArchiveNamespaces(stg, rs.DumpName)
92-
if err != nil {
93-
return errors.Wrapf(err, "parse metafile %q", rs.DumpName)
94-
}
100+
ns := archive.NSify(ns.Database, ns.Collection)
101+
f := path.Join(bcp.Name, rs.Name, ns+bcp.Compression.Suffix())
95102

96-
for _, ns := range nss {
97-
if ns.Size == 0 {
98-
continue
103+
eg.Go(func() error { return checkFile(stg, f) })
99104
}
100105

101-
ns := archive.NSify(ns.Database, ns.Collection)
102-
f := path.Join(bcp.Name, rs.Name, ns+bcp.Compression.Suffix())
103-
104-
eg.Go(func() error { return checkFile(stg, f) })
105-
}
106+
return nil
107+
})
106108
}
107109

108-
return eg.Wait()
110+
errs := eg.Wait()
111+
return errors.Join(errs...)
109112
}
110113

111114
func checkPhysicalBackupFiles(ctx context.Context, stg storage.Storage, bcp *BackupMeta) error {

0 commit comments

Comments
 (0)