-
Notifications
You must be signed in to change notification settings - Fork 4
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
APPS-1417 Respect scheduled full backup timing #291
Changes from 8 commits
c5f9529
79bf8f3
30e7972
37cdf36
72424e2
69ee08a
6d9e503
e1b26fb
ce1f834
bf22cba
afc186c
611c884
26d1482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. last_backup_run.go |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
// LastBackupRun stores the last run times for both full and incremental backups. | ||
type LastBackupRun struct { | ||
// Last time the Full backup was performed. | ||
Full *time.Time | ||
// Last time the Incremental backup was performed. | ||
Incremental *time.Time | ||
} | ||
|
||
func NewLastRun(lastFullBackup *time.Time, lastIncrBackup *time.Time) LastBackupRun { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming to |
||
return LastBackupRun{ | ||
Full: lastFullBackup, | ||
Incremental: lastIncrBackup, | ||
} | ||
} | ||
|
||
func (r *LastBackupRun) NoFullBackup() bool { | ||
return r.Full == nil | ||
} | ||
|
||
func (r *LastBackupRun) LastAnyRun() *time.Time { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming to |
||
if r.Incremental != nil && r.Full != nil && r.Incremental.After(*r.Full) { | ||
return r.Incremental | ||
} | ||
|
||
return r.Full | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ type BackupRoutineHandler struct { | |
namespaces []string | ||
storage model.Storage | ||
secretAgent *model.SecretAgent | ||
lastRun lastBackupRun | ||
lastRun model.LastBackupRun | ||
retry executor | ||
clientManager aerospike.ClientManager | ||
logger *slog.Logger | ||
|
@@ -78,8 +78,22 @@ type ClusterConfigWriter interface { | |
Write(ctx context.Context, client backup.AerospikeClient, timestamp time.Time) | ||
} | ||
|
||
// BackupHandlerHolder stores backupHandlers by routine name | ||
type BackupHandlerHolder map[string]*BackupRoutineHandler | ||
// backupRunner runs backup operations. | ||
type backupRunner interface { | ||
// runFullBackup starts full backup. | ||
runFullBackup(context.Context, time.Time) | ||
// runIncrementalBackup starts incremental backup. | ||
runIncrementalBackup(context.Context, time.Time) | ||
// Cancel cancels all running backup jobs. | ||
Cancel() | ||
// CurrentStat returns current status of backup routines. | ||
CurrentStat() *model.CurrentBackups | ||
} | ||
|
||
var _ backupRunner = (*BackupRoutineHandler)(nil) | ||
|
||
// BackupHandlerHolder stores backupRunners by routine name | ||
type BackupHandlerHolder map[string]backupRunner | ||
|
||
// newBackupRoutineHandler returns a new BackupRoutineHandler instance. | ||
func newBackupRoutineHandler( | ||
|
@@ -88,7 +102,7 @@ func newBackupRoutineHandler( | |
backupService Backup, | ||
routineName string, | ||
backupBackend *BackupBackend, | ||
lastRun lastBackupRun, | ||
lastRun model.LastBackupRun, | ||
) *BackupRoutineHandler { | ||
backupRoutine := config.BackupRoutines[routineName] | ||
backupPolicy := backupRoutine.BackupPolicy | ||
|
@@ -158,7 +172,7 @@ func (h *BackupRoutineHandler) runFullBackupInternal(ctx context.Context, now ti | |
return err | ||
} | ||
|
||
h.lastRun.full = now | ||
h.lastRun.Full = &now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not a new thing, but it is better to synchronize writes and reads to prevent data races. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No backup of the same type for the same routine will run simultaneously, no need for lock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two jobs scheduled for the full and incremental backup that may concurrently access those variables. |
||
|
||
h.clusterConfigWriter.Write(ctx, client.AerospikeClient(), now) | ||
|
||
|
@@ -225,8 +239,8 @@ func (h *BackupRoutineHandler) createTimebounds(fullBackup bool, now time.Time) | |
) | ||
|
||
if !fullBackup { | ||
lastRun := h.lastRun.lastAnyRun() | ||
fromTime = &lastRun | ||
lastRun := h.lastRun.LastAnyRun() | ||
fromTime = lastRun | ||
} | ||
|
||
if h.backupFullPolicy.IsSealedOrDefault() { | ||
|
@@ -292,7 +306,7 @@ func (h *BackupRoutineHandler) runIncrementalBackup(ctx context.Context, now tim | |
} | ||
|
||
func (h *BackupRoutineHandler) skipIncrementalBackup() bool { | ||
if h.lastRun.noFullBackup() { | ||
if h.lastRun.NoFullBackup() { | ||
h.logger.Debug("Skip incremental backup until initial full backup is done") | ||
return true | ||
} | ||
|
@@ -328,7 +342,7 @@ func (h *BackupRoutineHandler) runIncrementalBackupInternal(ctx context.Context, | |
return err | ||
} | ||
|
||
h.lastRun.incremental = now | ||
h.lastRun.Incremental = &now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider synchronizing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No backup of the same type for the same routine will run simultaneously, no need for lock |
||
return nil | ||
} | ||
|
||
|
@@ -372,10 +386,11 @@ func (h *BackupRoutineHandler) waitForIncrementalBackups(ctx context.Context) er | |
return aggregatedErr | ||
} | ||
|
||
func (h *BackupRoutineHandler) GetCurrentStat() *model.CurrentBackups { | ||
func (h *BackupRoutineHandler) CurrentStat() *model.CurrentBackups { | ||
return &model.CurrentBackups{ | ||
Full: currentBackupStatus(h.fullBackupHandlers), | ||
Incremental: currentBackupStatus(h.incrBackupHandlers), | ||
LastRunTime: h.lastRun, | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.