Skip to content

Commit

Permalink
ebs br: make sure backup can be resumed even after being paused for a…
Browse files Browse the repository at this point in the history
… long time

Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger committed Dec 14, 2023
1 parent 3863d3e commit 6adf8d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
14 changes: 6 additions & 8 deletions pkg/backup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,24 @@ func getLastScheduledTime(bs *v1alpha1.BackupSchedule, nowFn nowFn) (*time.Time,
}

var scheduledTimes []time.Time
var warningPrinted = false
for t := sched.Next(earliestTime); !t.After(now); t = sched.Next(t) {
scheduledTimes = append(scheduledTimes, t)
// If there is a bug somewhere, or incorrect clock
// on controller's server or apiservers (for setting creationTimestamp)
// then there could be so many missed start times (it could be off
// by decades or more), that it would eat up all the CPU and memory
// of this controller. In that case, we want to not try to list
// all the missed start times.
//
// I've somewhat arbitrarily picked 100, as more than 80,
// but less than "lots".
// by decades or more).
if len(scheduledTimes) > 100 {
// We can't get the last backup schedule time
if bs.Status.LastBackupTime == nil && bs.Status.AllBackupCleanTime != nil {
// Recovery backup schedule from pause status, should refresh AllBackupCleanTime to avoid unschedulable problem
bs.Status.AllBackupCleanTime = &metav1.Time{Time: nowFn()}
return nil, controller.RequeueErrorf("recovery backup schedule %s/%s from pause status, refresh AllBackupCleanTime.", ns, bsName)
}
klog.Error("Too many missed start backup schedule time (> 100). Check the clock.")
return nil, nil
if !warningPrinted {
klog.Warning("Too many missed start backup schedule time (> 100). Check the clock.")
warningPrinted = true
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/backupschedule/backup_schedule_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ func TestGetLastScheduledTime(t *testing.T) {
}

// test too many miss
bs.Status.LastBackupTime.Time = now.AddDate(-1000, 0, 0)
bs.Status.LastBackupTime.Time = now.AddDate(0, -12, 0)
getTime, err = getLastScheduledTime(bs, time.Now)
g.Expect(err).Should(BeNil())
g.Expect(getTime).Should(BeNil())
g.Expect(getTime).ShouldNot(BeNil())
}

func TestBuildBackup(t *testing.T) {
Expand Down
14 changes: 6 additions & 8 deletions pkg/fedvolumebackup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,24 @@ func getLastScheduledTime(vbs *v1alpha1.VolumeBackupSchedule, nowFn nowFn) (*tim
}

var scheduledTimes []time.Time
var warningPrinted = false
for t := sched.Next(earliestTime); !t.After(now); t = sched.Next(t) {
scheduledTimes = append(scheduledTimes, t)
// If there is a bug somewhere, or incorrect clock
// on controller's server or apiservers (for setting creationTimestamp)
// then there could be so many missed start times (it could be off
// by decades or more), that it would eat up all the CPU and memory
// of this controller. In that case, we want to not try to list
// all the missed start times.
//
// I've somewhat arbitrarily picked 100, as more than 80,
// but less than "lots".
// by decades or more).
if len(scheduledTimes) > 100 {
// We can't get the last backup schedule time
if vbs.Status.LastBackupTime == nil && vbs.Status.AllBackupCleanTime != nil {
// Recovery backup schedule from pause status, should refresh AllBackupCleanTime to avoid unschedulable problem
vbs.Status.AllBackupCleanTime = &metav1.Time{Time: nowFn()}
return nil, controller.RequeueErrorf("recovery backup schedule %s/%s from pause status, refresh AllBackupCleanTime.", ns, bsName)
}
klog.Error("Too many missed start backup schedule time (> 100). Check the clock.")
return nil, nil
if !warningPrinted {
klog.Warning("Too many missed start backup schedule time (> 100). Check the clock.")
warningPrinted = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ func TestGetLastScheduledTime(t *testing.T) {
}

// test too many miss
bs.Status.LastBackupTime.Time = now.AddDate(-1000, 0, 0)
bs.Status.LastBackupTime.Time = now.AddDate(0, -12, 0)
getTime, err = getLastScheduledTime(bs, time.Now)
g.Expect(err).Should(BeNil())
g.Expect(getTime).Should(BeNil())
g.Expect(getTime).ShouldNot(BeNil())
}

func TestBuildBackup(t *testing.T) {
Expand Down

0 comments on commit 6adf8d3

Please sign in to comment.