@@ -7,13 +7,12 @@ import (
7
7
"runtime"
8
8
"sync"
9
9
10
- "golang.org/x/sync/errgroup"
11
-
12
10
"github.com/percona/percona-backup-mongodb/pbm/archive"
13
11
"github.com/percona/percona-backup-mongodb/pbm/defs"
14
12
"github.com/percona/percona-backup-mongodb/pbm/errors"
15
13
"github.com/percona/percona-backup-mongodb/pbm/storage"
16
14
sfs "github.com/percona/percona-backup-mongodb/pbm/storage/fs"
15
+ "github.com/percona/percona-backup-mongodb/pbm/util"
17
16
"github.com/percona/percona-backup-mongodb/pbm/version"
18
17
)
19
18
@@ -45,7 +44,7 @@ func ReadMetadata(stg storage.Storage, filename string) (*BackupMeta, error) {
45
44
func CheckBackupDataFiles (ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
46
45
switch bcp .Type {
47
46
case defs .LogicalBackup :
48
- return checkLogicalBackupFiles (ctx , stg , bcp )
47
+ return checkLogicalBackupDataFiles (ctx , stg , bcp )
49
48
case defs .PhysicalBackup , defs .IncrementalBackup :
50
49
return checkPhysicalBackupFiles (ctx , stg , bcp )
51
50
case defs .ExternalBackup :
@@ -55,57 +54,61 @@ func CheckBackupDataFiles(ctx context.Context, stg storage.Storage, bcp *BackupM
55
54
return errors .Errorf ("unknown backup type %s" , bcp .Type )
56
55
}
57
56
58
- func checkLogicalBackupFiles ( ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
57
+ func checkLogicalBackupDataFiles ( _ context.Context , stg storage.Storage , bcp * BackupMeta ) error {
59
58
legacy := version .IsLegacyArchive (bcp .PBMVersion )
60
- eg , _ := errgroup .WithContext (ctx )
59
+
60
+ eg := util .NewErrorGroup (runtime .NumCPU () * 2 )
61
61
for _ , rs := range bcp .Replsets {
62
- rs := rs
62
+ eg .Go (func () error {
63
+ eg .Go (func () error { return checkFile (stg , rs .DumpName ) })
63
64
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
+ }
65
69
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
69
88
}
70
89
71
- files , err := stg . List ( rs . OplogName , "" )
90
+ nss , err := ReadArchiveNamespaces ( stg , rs . DumpName )
72
91
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 )
77
93
}
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
- })
86
94
87
- if legacy {
88
- continue
89
- }
95
+ for _ , ns := range nss {
96
+ if ns .Size == 0 {
97
+ continue
98
+ }
90
99
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 ())
95
102
96
- for _ , ns := range nss {
97
- if ns .Size == 0 {
98
- continue
103
+ eg .Go (func () error { return checkFile (stg , f ) })
99
104
}
100
105
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
+ })
106
108
}
107
109
108
- return eg .Wait ()
110
+ errs := eg .Wait ()
111
+ return errors .Join (errs ... )
109
112
}
110
113
111
114
func checkPhysicalBackupFiles (ctx context.Context , stg storage.Storage , bcp * BackupMeta ) error {
0 commit comments