Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ebs br: serial execution of volume backup gc #5452

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 35 additions & 25 deletions pkg/fedvolumebackup/backupschedule/backup_schedule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,25 @@ func (bm *backupScheduleManager) backupGCByMaxReservedTime(vbs *v1alpha1.VolumeB
return
}

for _, backup := range expiredBackups {
// delete the expired backup
if err = bm.deps.FedVolumeBackupControl.DeleteVolumeBackup(backup); err != nil {
klog.Errorf("backup schedule %s/%s gc backup %s failed, err %v", ns, bsName, backup.GetName(), err)
// In order to avoid throttling, we choose to do delete volumebackup one by one.
// Delete the oldest expired backup
if len(expiredBackups) > 0 {
backup := expiredBackups[0]
if backup.DeletionTimestamp != nil {
klog.Infof("Deletion is ongoing for backup schedule %s/%s, backup %s", ns, bsName, backup.GetName())
return
}
klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())
}
} else {
if err = bm.deps.FedVolumeBackupControl.DeleteVolumeBackup(backup); err != nil {
klog.Errorf("backup schedule %s/%s gc backup %s failed, err %v", ns, bsName, backup.GetName(), err)
return
}
klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())

if len(expiredBackups) == len(backupsList) && len(expiredBackups) > 0 {
// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(vbs)
if len(expiredBackups) == 1 {
BornChanger marked this conversation as resolved.
Show resolved Hide resolved
// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(vbs)
}
}
}
}

Expand Down Expand Up @@ -346,23 +353,26 @@ func (bm *backupScheduleManager) backupGCByMaxBackups(vbs *v1alpha1.VolumeBackup
}

sort.Sort(byCreateTimeDesc(backupsList))
var deleteCount int
for i, backup := range backupsList {
if i < int(*vbs.Spec.MaxBackups) {
continue
}
// delete the backup
if err := bm.deps.FedVolumeBackupControl.DeleteVolumeBackup(backup); err != nil {
klog.Errorf("backup schedule %s/%s gc backup %s failed, err %v", ns, bsName, backup.GetName(), err)

// In order to avoid throttling, we choose to do delete volumebackup one by one.
// Delete the oldest expired backup
if len(backupsList) > int(*vbs.Spec.MaxBackups) {
backup := backupsList[int(*vbs.Spec.MaxBackups)]
if backup.DeletionTimestamp != nil {
klog.Infof("Deletion is ongoing for backup schedule %s/%s, backup %s", ns, bsName, backup.GetName())
return
}
deleteCount += 1
klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())
}
} else {
if err = bm.deps.FedVolumeBackupControl.DeleteVolumeBackup(backup); err != nil {
klog.Errorf("backup schedule %s/%s gc backup %s failed, err %v", ns, bsName, backup.GetName(), err)
return
}
klog.Infof("backup schedule %s/%s gc backup %s success", ns, bsName, backup.GetName())

if deleteCount == len(backupsList) && deleteCount > 0 {
// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(vbs)
if len(backupsList) == 1 {
// All backups have been deleted, so the last backup information in the backupSchedule should be reset
bm.resetLastBackup(vbs)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ func TestManager(t *testing.T) {
bs.Spec.MaxBackups = pointer.Int32Ptr(5)
err = m.Sync(bs)
g.Expect(err).Should(BeNil())
helper.checkBacklist(bs.Namespace, 5)
helper.checkBacklist(bs.Namespace, 9)

t.Log("test setting MaxReservedTime")
bs.Spec.MaxBackups = nil
bs.Spec.MaxReservedTime = pointer.StringPtr("71h")
err = m.Sync(bs)
g.Expect(err).Should(BeNil())
helper.checkBacklist(bs.Namespace, 3)
helper.checkBacklist(bs.Namespace, 8)
}

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