Skip to content

Commit

Permalink
better truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR committed Sep 24, 2024
1 parent 7f8a249 commit d1f8f3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions pkg/apis/pingcap/v1alpha1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ func IsBackupCleanFailed(backup *Backup) bool {

// IsCleanCandidate returns true if a Backup should be added to clean candidate according to cleanPolicy
func IsCleanCandidate(backup *Backup) bool {
if backup.Spec.Mode == BackupModeLog {
return true
}
switch backup.Spec.CleanPolicy {
case CleanPolicyTypeDelete, CleanPolicyTypeOnFailure:
return true
Expand All @@ -334,7 +331,7 @@ func ParseLogBackupSubcommand(backup *Backup) LogSubCommandType {

// Compatible with the old version
if backup.Spec.LogStop {
if isSubcommandAlreadySync(backup, LogStopCommand) {
if IsLogSubcommandAlreadySync(backup, LogStopCommand) && backup.Spec.LogTruncateUntil != "" {
return LogTruncateCommand
}
return LogStopCommand
Expand All @@ -358,15 +355,17 @@ func ParseLogBackupSubcommand(backup *Backup) LogSubCommandType {
subCommand = LogStartCommand
}

// If the selected subcommand is already done, switch to LogTruncateCommand
if isSubcommandAlreadySync(backup, subCommand) {
// If the selected subcommand is already sync and logTruncateUntil is set, switch to LogTruncateCommand
if IsLogSubcommandAlreadySync(backup, subCommand) && backup.Spec.LogTruncateUntil != "" {
return LogTruncateCommand
}

return subCommand
}

func isSubcommandAlreadySync(backup *Backup, subCommand LogSubCommandType) bool {
// IsLogSubcommandAlreadySync return whether the log subcommand already sync.
// It only check start/stop/pause subcommand. Truncate subcommand need to check the truncate until seperately.
func IsLogSubcommandAlreadySync(backup *Backup, subCommand LogSubCommandType) bool {
switch subCommand {
case LogStartCommand:
return IsLogBackupAlreadyStart(backup)
Expand Down
8 changes: 4 additions & 4 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,11 @@ func (bm *backupManager) skipLogBackupSync(backup *v1alpha1.Backup) (bool, error
}

command := v1alpha1.ParseLogBackupSubcommand(backup)
if command != v1alpha1.LogTruncateCommand && v1alpha1.IsLogSubcommandAlreadySync(backup, command) {
return true, nil
}

// Handle the special case for LogTruncateCommand where additional actions are needed
// Handle the special case for LogTruncateCommand
var err error
if command == v1alpha1.LogTruncateCommand && v1alpha1.IsLogBackupAlreadyTruncate(backup) {
// If skipping truncate, update status
Expand All @@ -1100,9 +1103,6 @@ func (bm *backupManager) skipLogBackupSync(backup *v1alpha1.Backup) (bool, error
Type: v1alpha1.BackupComplete,
Status: corev1.ConditionTrue,
}, updateStatus)
}

if command == v1alpha1.LogTruncateCommand {
klog.Infof("log backup %s/%s subcommand %s is already done, will skip sync.", backup.Namespace, backup.Name, command)
return true, err
}
Expand Down

0 comments on commit d1f8f3b

Please sign in to comment.