Skip to content

Commit 92df5b1

Browse files
committed
Improve logging and error messages for fallback
1 parent cfab52c commit 92df5b1

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cmd/pbm/backup.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ type bcpReplDesc struct {
341341
Node string `json:"node" yaml:"node"`
342342
Files []backup.File `json:"files,omitempty" yaml:"-"`
343343
Size int64 `json:"size" yaml:"-"`
344-
HSize string `json:"size_h" yaml:"size_h"`
344+
HSize string `json:"size_h,omitempty" yaml:"size_h,omitempty"`
345345
LastWriteTS int64 `json:"last_write_ts" yaml:"-"`
346346
LastTransitionTS int64 `json:"last_transition_ts" yaml:"-"`
347347
LastWriteTime string `json:"last_write_time" yaml:"last_write_time"`
@@ -445,7 +445,6 @@ func describeBackup(
445445
IsConfigShard: r.IsConfigShard,
446446
Status: r.Status,
447447
Size: r.Size,
448-
HSize: byteCountIEC(r.Size),
449448
LastWriteTS: int64(r.LastWriteTS.T),
450449
LastTransitionTS: r.LastTransitionTS,
451450
LastWriteTime: time.Unix(int64(r.LastWriteTS.T), 0).UTC().Format(time.RFC3339),
@@ -461,6 +460,9 @@ func describeBackup(
461460
if bcp.Type == defs.ExternalBackup {
462461
rv.Replsets[i].Files = r.Files
463462
}
463+
if r.Size > 0 {
464+
rv.Replsets[i].HSize = byteCountIEC(r.Size)
465+
}
464466

465467
if !b.coll || bcp.Type != defs.LogicalBackup {
466468
continue

cmd/pbm/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,12 @@ func (app *pbmApp) buildRestoreCmd() *cobra.Command {
810810
)
811811
restoreCmd.Flags().BoolVar(
812812
&restoreOptions.fallback, "fallback-enabled", true,
813-
"Disables fallback sync feature when doing physical restore. Enabled by default.",
813+
"Enables/disables fallback strategy when doing physical restore.",
814814
)
815815
restoreCmd.Flags().BoolVar(
816816
&restoreOptions.allowPartlyDone, "allow-partly-done", true,
817817
"Allows parly done state of the cluster after physical restore. "+
818-
"If disabled, fallback will be applied when cluster is partly-done. Enabled by default.",
818+
"If disabled, fallback will be applied when cluster is partly-done.",
819819
)
820820

821821
restoreCmd.Flags().StringVar(&restoreOptions.rsMap, RSMappingFlag, "", RSMappingDoc)

pbm/restore/physical.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,11 +2548,12 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
25482548

25492549
setName := mapRevRS(r.nodeInfo.SetName)
25502550

2551+
r.log.Debug("restore opts: --fallback-enabled: %t; --allow-partly-done: %t",
2552+
r.fallback, r.allowPartlyDone)
25512553
if r.fallback && r.bcp.RS(setName) != nil {
25522554
err = r.checkDiskSpace(r.bcp.RS(setName).Size)
25532555
if err != nil {
2554-
return errors.Wrap(err, "not enough disk space for fallback strategy, "+
2555-
"consider using --fallback-enabled=false")
2556+
return errors.Wrap(err, "check disk space")
25562557
}
25572558
}
25582559

@@ -2607,6 +2608,11 @@ func (r *PhysRestore) checkMongod(needVersion string) (version string, err error
26072608
// It returns error in case when backup size is larger than free space on the disk.
26082609
// It also includes min disk space requirement of 10GiB.
26092610
func (r *PhysRestore) checkDiskSpace(bcpSize int64) error {
2611+
if bcpSize == 0 {
2612+
return errors.New("unable to apply fallback strategy for unknown backup size, " +
2613+
"consider using --fallback-enabled=false")
2614+
}
2615+
26102616
var stat syscall.Statfs_t
26112617
err := syscall.Statfs(r.dbpath, &stat)
26122618
if err != nil {
@@ -2615,8 +2621,13 @@ func (r *PhysRestore) checkDiskSpace(bcpSize int64) error {
26152621

26162622
free := int64(stat.Bavail) * int64(stat.Bsize)
26172623
tenGiB := 10 * (1 << 30)
2618-
if bcpSize+int64(tenGiB) >= free {
2619-
return errors.Errorf("not enough disk space, free=%d, backup size=%d", free, bcpSize)
2624+
totalReqSize := bcpSize + int64(tenGiB)
2625+
r.log.Debug("free space on disk: %s; backup size: %s; total requested free size: %s",
2626+
storage.PrettySize(free), storage.PrettySize(bcpSize), storage.PrettySize(totalReqSize))
2627+
2628+
if totalReqSize >= free {
2629+
return errors.New("not enough disk space for fallback strategy, " +
2630+
"consider using --fallback-enabled=false")
26202631
}
26212632

26222633
return nil

0 commit comments

Comments
 (0)