Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR committed Jan 15, 2025
1 parent fa3f39e commit 1f4cad2
Showing 1 changed file with 11 additions and 46 deletions.
57 changes: 11 additions & 46 deletions pkg/backup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (bm *backupScheduleManager) Sync(bs *v1alpha1.BackupSchedule) error {

klog.Infof("backupSchedule %s/%s next scheduled time is %v", bs.GetNamespace(), bs.GetName(), scheduledTime)

if err := bm.canPerformNextCompact(bs); err != nil {
if err := bm.canPerformCompact(bs); err != nil {
klog.Errorf("backupSchedule %s/%s can not perform next compact, err: %v", bs.GetNamespace(), bs.GetName(), err)
} else if err := bm.performCompact(bs, scheduledTime, bm.now); err != nil {
klog.Errorf("backupSchedule %s/%s perform compact failed, err: %v", bs.GetNamespace(), bs.GetName(), err)
Expand Down Expand Up @@ -288,14 +288,18 @@ func (bm *backupScheduleManager) deleteLastcompactJob(bs *v1alpha1.BackupSchedul
return bm.deps.JobControl.DeleteJob(compact, job)
}

// handleLastCompact handles the compact backup processing logic.
// canPerformCompact handles the compact backup processing logic.
// It returns a controller.RequeueError if the backup is still running,
// otherwise it updates the LastCompactTime or returns any encountered error.
func (bm *backupScheduleManager) handleLastCompact(ns, bsName, lastCompact string, bs *v1alpha1.BackupSchedule) error {
if lastCompact == "" {
func (bm *backupScheduleManager) canPerformCompact(bs *v1alpha1.BackupSchedule) error {
if bs.Status.LastCompact == "" {
return nil
}

lastCompact := bs.Status.LastCompact
ns := bs.GetNamespace()
bsName := bs.GetName()

compact, err := bm.deps.CompactBackupLister.CompactBackups(ns).Get(lastCompact)
if err != nil {
if errors.IsNotFound(err) {
Expand All @@ -307,14 +311,14 @@ func (bm *backupScheduleManager) handleLastCompact(ns, bsName, lastCompact strin
var lastCompactTs string
switch compact.Status.State {
case string(v1alpha1.BackupComplete):
timestamp = compact.Spec.EndTs
lastCompactTs = compact.Spec.EndTs
case string(v1alpha1.BackupFailed):
timestamp = compact.Spec.StartTs
lastCompactTs = compact.Spec.StartTs
default:
return controller.RequeueErrorf("backup schedule %s/%s: compact backup %s is still running", ns, bsName, lastCompact)
}

t, err := config.ParseTSStringToGoTime(timestamp)
t, err := config.ParseTSStringToGoTime(lastCompactTs)
if err != nil {
return perrors.AddStack(err)
}
Expand All @@ -333,45 +337,6 @@ func (bm *backupScheduleManager) handleLastCompact(ns, bsName, lastCompact strin
return nil
}

func (bm *backupScheduleManager) canPerformNextCompact(bs *v1alpha1.BackupSchedule) error {
ns := bs.GetNamespace()
bsName := bs.GetName()

if bs.Status.LogBackupStartTs == nil {
return nil
}

// Determine if the backup schedule is part of a group
bsGroupName := bs.GetLabels()[label.BackupScheduleGroupLabelKey]
if bsGroupName == "" {
return bm.handleLastCompact(ns, bsName, bs.Status.LastCompact, bs)
}

backupScheduleGroupLabels := label.NewBackupScheduleGroup(bsGroupName)
selector, err := backupScheduleGroupLabels.Selector()
if err != nil {
return fmt.Errorf("generate backup schedule group %s label selector failed: %w", bsGroupName, err)
}

bss, err := bm.deps.BackupScheduleLister.BackupSchedules(ns).List(selector)
if err != nil {
return fmt.Errorf("backup schedule %s/%s: list backup schedules failed: %w", ns, bsName, err)
}

for _, bsMember := range bss {
if err := bm.handleLastCompact(ns, bsName, bsMember.Status.LastCompact, bsMember); err != nil {
// If it's a requeue error, propagate it
if controller.IsRequeueError(err) {
return err
}
// For other errors, return immediately
return fmt.Errorf("backup schedule %s/%s: processing compact failed: %w", ns, bsName, err)
}
}

return nil
}

func (bm *backupScheduleManager) performLogBackupIfNeeded(bs *v1alpha1.BackupSchedule) error {
ns := bs.GetNamespace()
bsName := bs.GetName()
Expand Down

0 comments on commit 1f4cad2

Please sign in to comment.