Skip to content

Commit

Permalink
Fix non-recurring backups (apache#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoustonPutman authored Dec 23, 2022
1 parent 4be1a1d commit c3cda10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 10 additions & 11 deletions controllers/solrbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ func (r *SolrBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request)

requeueOrNot := reconcile.Result{}

var backupNeedsToWait bool
// Backup work needs to be done by default if the current backup is not finished
doBackupWork := !backup.Status.IndividualSolrBackupStatus.Finished

// Check if we should start the next backup
if backup.Status.NextScheduledTime != nil {
// If the backup no longer enabled, remove the next scheduled time
// Do not check if already doing a backup
if !doBackupWork && backup.Status.NextScheduledTime != nil {
if !backup.Spec.Recurrence.IsEnabled() {
backup.Status.NextScheduledTime = nil
backupNeedsToWait = false
doBackupWork = false
} else if backup.Status.NextScheduledTime.UTC().Before(time.Now().UTC()) {
// We have hit the next scheduled restart time.
backupNeedsToWait = false
doBackupWork = true
backup.Status.NextScheduledTime = nil

// Add the current backup to the front of the history.
Expand All @@ -119,14 +120,12 @@ func (r *SolrBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request)
} else {
// If we have not hit the next scheduled restart, wait to requeue until that is true.
updateRequeueAfter(&requeueOrNot, backup.Status.NextScheduledTime.UTC().Sub(time.Now().UTC()))
backupNeedsToWait = true
doBackupWork = false
}
} else {
backupNeedsToWait = false
}

// Do backup work if we are not waiting and the current backup is not finished
if !backupNeedsToWait && !backup.Status.IndividualSolrBackupStatus.Finished {
// Do backup work if a backup is in-progress or needs to be started
if doBackupWork {
solrCloud, _, err1 := r.reconcileSolrCloudBackup(ctx, backup, &backup.Status.IndividualSolrBackupStatus, logger)
if err1 != nil {
// TODO Should we be failing the backup for some sub-set of errors here?
Expand All @@ -146,7 +145,7 @@ func (r *SolrBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

// Schedule the next backupTime, if it doesn't have a next scheduled time, it has recurrence and the current backup is finished
if backup.Status.IndividualSolrBackupStatus.Finished {
if backup.Status.IndividualSolrBackupStatus.Finished && backup.Spec.Recurrence.IsEnabled() {
if nextBackupTime, err1 := util.ScheduleNextBackup(backup.Spec.Recurrence.Schedule, backup.Status.IndividualSolrBackupStatus.StartTime.Time); err1 != nil {
logger.Error(err1, "Could not update backup scheduling due to bad cron schedule", "cron", backup.Spec.Recurrence.Schedule)
} else {
Expand Down
5 changes: 5 additions & 0 deletions helm/solr-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ annotations:
links:
- name: GitHub PR
url: https://github.com/apache/solr-operator/pull/512/files
- kind: fixed
description: Fix bug in non-recurring SolrBackups
links:
- name: GitHub PR
url: https://github.com/apache/solr-operator/pull/509
artifacthub.io/images: |
- name: solr-operator
image: apache/solr-operator:v0.7.0-prerelease
Expand Down

0 comments on commit c3cda10

Please sign in to comment.