Skip to content

Commit e66f215

Browse files
committed
PBM-1312: set default num-parallal-collection for restore to be (cpu/2)
1 parent d933b42 commit e66f215

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

cmd/pbm-agent/restore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"runtime"
56
"time"
67

78
"github.com/percona/percona-backup-mongodb/pbm/backup"
@@ -114,7 +115,7 @@ func (a *Agent) Restore(ctx context.Context, r *ctrl.RestoreCmd, opid ctrl.OPID,
114115
return
115116
}
116117

117-
var numParallelColls int
118+
numParallelColls := runtime.NumCPU() / 2
118119
if r.NumParallelColls != nil && *r.NumParallelColls > 0 {
119120
numParallelColls = int(*r.NumParallelColls)
120121
}

pbm/restore/logical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ func (r *Restore) snapshot(ctx context.Context, input io.Reader) error {
11931193
return errors.Wrap(err, "unable to get PBM config settings")
11941194
}
11951195

1196-
rf, err := snapshot.NewRestore(r.brief.URI, cfg)
1196+
rf, err := snapshot.NewRestore(r.brief.URI, cfg, r.numParallelColls)
11971197
if err != nil {
11981198
return err
11991199
}

pbm/snapshot/restore.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var ExcludeFromRestore = []string{
4242

4343
type restorer struct{ *mongorestore.MongoRestore }
4444

45-
func NewRestore(uri string, cfg *config.Config) (io.ReaderFrom, error) {
45+
func NewRestore(uri string, cfg *config.Config, numParallelColls int) (io.ReaderFrom, error) {
4646
topts := options.New("mongorestore",
4747
"0.0.1",
4848
"none",
@@ -76,6 +76,9 @@ func NewRestore(uri string, cfg *config.Config) (io.ReaderFrom, error) {
7676
if cfg.Restore.NumInsertionWorkers > 0 {
7777
numInsertionWorkers = cfg.Restore.NumInsertionWorkers
7878
}
79+
if numParallelColls < 1 {
80+
numParallelColls = 1
81+
}
7982

8083
mopts := mongorestore.Options{}
8184
mopts.ToolOptions = topts
@@ -87,6 +90,7 @@ func NewRestore(uri string, cfg *config.Config) (io.ReaderFrom, error) {
8790
BypassDocumentValidation: true,
8891
Drop: true,
8992
NumInsertionWorkers: numInsertionWorkers,
93+
NumParallelCollections: numParallelColls,
9094
PreserveUUID: preserveUUID,
9195
StopOnError: true,
9296
WriteConcern: "majority",

0 commit comments

Comments
 (0)