Skip to content

Commit a0f6724

Browse files
committed
Enable RS backup size calculation for inc restore
It'll include base + all increments sizes on RS when calculationg available disk space for fallbacksync feature.
1 parent 2c141ea commit a0f6724

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

pbm/restore/physical.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type PhysRestore struct {
9393
bcpStg storage.Storage
9494
bcp *backup.BackupMeta
9595
files []files
96+
bcpSizeRS int64 // total uncompressed size of the backup for RS (including all increments)
9697
restoreTS primitive.Timestamp
9798

9899
confOpts *config.RestoreConf
@@ -2341,6 +2342,9 @@ const bcpDir = "__dir__"
23412342
//
23422343
// The restore should be done in reverse order. Applying files (diffs)
23432344
// starting from the base and moving forward in time up to the target backup.
2345+
//
2346+
// Additionally total uncompressed backup size for RS is callculated
2347+
// in this method.
23442348
func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
23452349
bcp := r.bcp
23462350

@@ -2372,6 +2376,8 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
23722376
targetFiles[f.Name] = false
23732377
}
23742378

2379+
r.bcpSizeRS = rs.SizeUncompressed
2380+
23752381
for {
23762382
data := files{
23772383
BcpName: bcp.Name,
@@ -2397,6 +2403,10 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
23972403
r.files = append(r.files, data)
23982404

23992405
if bcp.SrcBackup == "" {
2406+
// if base backup doesn't have size, we cannot calculate total size
2407+
if rs.SizeUncompressed == 0 {
2408+
r.bcpSizeRS = 0 // zero is used as the flag
2409+
}
24002410
break
24012411
}
24022412

@@ -2407,6 +2417,7 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
24072417
return errors.Wrapf(err, "get source backup")
24082418
}
24092419
rs = getRS(bcp, setName)
2420+
r.bcpSizeRS += rs.SizeUncompressed
24102421

24112422
if version.HasFilelistFile(bcp.PBMVersion) {
24122423
filelistPath := path.Join(bcp.Name, setName, backup.FilelistName)
@@ -2548,6 +2559,15 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
25482559
return errors.Wrap(err, "get data for restore")
25492560
}
25502561

2562+
r.log.Debug("restore opts: fallbackEnabled: %t; allowPartlyDone: %t",
2563+
r.fallback, r.allowPartlyDone)
2564+
if r.fallback {
2565+
err = r.checkDiskSpace(r.bcpSizeRS)
2566+
if err != nil {
2567+
return errors.Wrap(err, "check disk space")
2568+
}
2569+
}
2570+
25512571
s, err := topo.ClusterMembers(ctx, r.leadConn.MongoClient())
25522572
if err != nil {
25532573
return errors.Wrap(err, "get cluster members")
@@ -2572,15 +2592,6 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
25722592

25732593
setName := mapRevRS(r.nodeInfo.SetName)
25742594

2575-
r.log.Debug("restore opts: --fallback-enabled: %t; --allow-partly-done: %t",
2576-
r.fallback, r.allowPartlyDone)
2577-
if r.fallback && r.bcp.RS(setName) != nil {
2578-
err = r.checkDiskSpace(r.bcp.RS(setName).Size)
2579-
if err != nil {
2580-
return errors.Wrap(err, "check disk space")
2581-
}
2582-
}
2583-
25842595
var ok bool
25852596
for _, v := range r.bcp.Replsets {
25862597
if v.Name == setName {
@@ -2663,7 +2674,7 @@ func (r *PhysRestore) checkDiskSpace(bcpSize int64) error {
26632674
// disableFallbackForOldBackup set fallback option to false due to backup incompatibility
26642675
func (r *PhysRestore) disableFallbackForOldBackup() {
26652676
r.fallback = false
2666-
r.log.Debug("restore opts: --fallback-enabled: %t; --allow-partly-done: %t",
2677+
r.log.Debug("restore opts: fallbackEnabled: %t; allowPartlyDone: %t",
26672678
r.fallback, r.allowPartlyDone)
26682679
}
26692680

0 commit comments

Comments
 (0)