Skip to content

Commit

Permalink
*: fast move forward when too many advance
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger committed Dec 18, 2023
1 parent 6adf8d3 commit 3c638e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions pkg/backup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +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).
if len(scheduledTimes) > 100 {
// by decades or more). So, we need to set LastBackupTime to now() in order to let
// next reconcile succeed.
if len(scheduledTimes) > 1000 {
// 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)
}
if !warningPrinted {
klog.Warning("Too many missed start backup schedule time (> 100). Check the clock.")
warningPrinted = true
}
klog.Warning("Too many missed start backup schedule time (> 1000). Fail current one.")
offset := sched.Next(t).Sub(t)
bs.Status.LastBackupTime = &metav1.Time{Time: time.Now().Add(-offset)}
return nil, nil
}
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/backup/backupschedule/backup_schedule_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ func TestGetLastScheduledTime(t *testing.T) {
}

// test too many miss
bs.Status.LastBackupTime.Time = now.AddDate(0, -12, 0)
bs.Status.LastBackupTime.Time = now.AddDate(-10, 0, 0)
getTime, err = getLastScheduledTime(bs, time.Now)
g.Expect(err).Should(BeNil())
g.Expect(getTime).Should(BeNil())
// next reconcile should succeed
getTime, err = getLastScheduledTime(bs, time.Now)
g.Expect(err).Should(BeNil())
g.Expect(getTime).ShouldNot(BeNil())
Expand Down
15 changes: 8 additions & 7 deletions pkg/fedvolumebackup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,25 @@ 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).
if len(scheduledTimes) > 100 {
// by decades or more). So, we need to set LastBackupTime to now() in order to let
// next reconcile succeed.
if len(scheduledTimes) > 1000 {
// 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)
}
if !warningPrinted {
klog.Warning("Too many missed start backup schedule time (> 100). Check the clock.")
warningPrinted = true
}

klog.Warning("Too many missed start backup schedule time (> 1000). Fail current one.")
offset := sched.Next(t).Sub(t)
vbs.Status.LastBackupTime = &metav1.Time{Time: time.Now().Add(-offset)}
return nil, nil
}
}

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

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

Expand Down

0 comments on commit 3c638e3

Please sign in to comment.