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

br: a more straight forward operator interface #5710

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
31 changes: 31 additions & 0 deletions cmd/backup-manager/app/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ func (bo *Options) doStartLogBackup(ctx context.Context, backup *v1alpha1.Backup
return bo.brCommandRun(ctx, fullArgs)
}

// doResumeLogBackup generates br args about log backup resume and runs br binary to do the real backup work.
func (bo *Options) doResumeLogBackup(ctx context.Context, backup *v1alpha1.Backup) error {
specificArgs := []string{
"log",
"resume",
fmt.Sprintf("--task-name=%s", backup.Name),
}
// if bo.CommitTS != "" && bo.CommitTS != "0" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to remove these comment codes. They seem useless.

// specificArgs = append(specificArgs, fmt.Sprintf("--start-ts=%s", bo.CommitTS))
// }
fullArgs, err := bo.backupCommandTemplate(backup, specificArgs, false)
if err != nil {
return err
}
return bo.brCommandRun(ctx, fullArgs)
}

// doStoplogBackup generates br args about log backup stop and runs br binary to do the real backup work.
func (bo *Options) doStopLogBackup(ctx context.Context, backup *v1alpha1.Backup) error {
specificArgs := []string{
Expand All @@ -181,6 +198,20 @@ func (bo *Options) doStopLogBackup(ctx context.Context, backup *v1alpha1.Backup)
return bo.brCommandRun(ctx, fullArgs)
}

// doPauselogBackup generates br args about log backup pause and runs br binary to do the real backup work.
func (bo *Options) doPauseLogBackup(ctx context.Context, backup *v1alpha1.Backup) error {
specificArgs := []string{
"log",
"pause",
fmt.Sprintf("--task-name=%s", backup.Name),
}
fullArgs, err := bo.backupCommandTemplate(backup, specificArgs, false)
if err != nil {
return err
}
return bo.brCommandRun(ctx, fullArgs)
}

// doTruncateLogBackup generates br args about log backup truncate and runs br binary to do the real backup work.
func (bo *Options) doTruncateLogBackup(ctx context.Context, backup *v1alpha1.Backup) error {
specificArgs := []string{
Expand Down
65 changes: 65 additions & 0 deletions cmd/backup-manager/app/backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ func (bm *Manager) performLogBackup(ctx context.Context, backup *v1alpha1.Backup
resultStatus, reason, err = bm.stopLogBackup(ctx, backup)
case string(v1alpha1.LogTruncateCommand):
resultStatus, reason, err = bm.truncateLogBackup(ctx, backup)
case string(v1alpha1.LogResumeCommand):
resultStatus, reason, err = bm.resumeLogBackup(ctx, backup)
case string(v1alpha1.LogPauseCommand):
resultStatus, reason, err = bm.pauseLogBackup(ctx, backup)
default:
return fmt.Errorf("log backup %s unknown log subcommand %s", bm, bm.SubCommand)
}
Expand Down Expand Up @@ -551,6 +555,36 @@ func (bm *Manager) startLogBackup(ctx context.Context, backup *v1alpha1.Backup)
return updateStatus, "", nil
}

// resumeLogBackup resume log backup.
func (bm *Manager) resumeLogBackup(ctx context.Context, backup *v1alpha1.Backup) (*controller.BackupUpdateStatus, string, error) {
started := time.Now()

// change Prepare to Running before real backup process start
if err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Command: v1alpha1.LogResumeCommand,
Type: v1alpha1.BackupRunning,
Status: corev1.ConditionTrue,
}, nil); err != nil {
return nil, "UpdateStatusFailed", err
}

// run br binary to do the real job
backupErr := bm.doResumeLogBackup(ctx, backup)

if backupErr != nil {
klog.Errorf("Resume log backup of cluster %s failed, err: %s", bm, backupErr)
return nil, "ResumeLogBackuFailed", backupErr
}
klog.Infof("Resume log backup of cluster %s success", bm)

finish := time.Now()
updateStatus := &controller.BackupUpdateStatus{
TimeStarted: &metav1.Time{Time: started},
TimeCompleted: &metav1.Time{Time: finish},
}
return updateStatus, "", nil
}

// stopLogBackup stops log backup.
func (bm *Manager) stopLogBackup(ctx context.Context, backup *v1alpha1.Backup) (*controller.BackupUpdateStatus, string, error) {
started := time.Now()
Expand Down Expand Up @@ -582,6 +616,37 @@ func (bm *Manager) stopLogBackup(ctx context.Context, backup *v1alpha1.Backup) (
return updateStatus, "", nil
}

// pauseLogBackup stops log backup.
func (bm *Manager) pauseLogBackup(ctx context.Context, backup *v1alpha1.Backup) (*controller.BackupUpdateStatus, string, error) {
started := time.Now()

// change Prepare to Running before real backup process start
if err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Command: v1alpha1.LogPauseCommand,
Type: v1alpha1.BackupRunning,
Status: corev1.ConditionTrue,
}, nil); err != nil {
return nil, "UpdateStatusFailed", err
}

// run br binary to do the real job
backupErr := bm.doPauseLogBackup(ctx, backup)

if backupErr != nil {
klog.Errorf("Pause log backup of cluster %s failed, err: %s", bm, backupErr)
return nil, "PauseLogBackupFailed", backupErr
}
klog.Infof("Pause log backup of cluster %s success", bm)

finish := time.Now()

updateStatus := &controller.BackupUpdateStatus{
TimeStarted: &metav1.Time{Time: started},
TimeCompleted: &metav1.Time{Time: finish},
}
return updateStatus, "", nil
}

// truncateLogBackup truncates log backup.
func (bm *Manager) truncateLogBackup(ctx context.Context, backup *v1alpha1.Backup) (*controller.BackupUpdateStatus, string, error) {
started := time.Now()
Expand Down
24 changes: 24 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ Default is current timestamp.</p>
</tr>
<tr>
<td>
<code>logSubcommand</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Subcommand is the subcommand for BR, such as start, stop, pause etc.</p>
</td>
</tr>
<tr>
<td>
<code>logTruncateUntil</code></br>
<em>
string
Expand Down Expand Up @@ -4234,6 +4246,18 @@ Default is current timestamp.</p>
</tr>
<tr>
<td>
<code>logSubcommand</code></br>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Subcommand is the subcommand for BR, such as start, stop, pause etc.</p>
</td>
</tr>
<tr>
<td>
<code>logTruncateUntil</code></br>
<em>
string
Expand Down
Loading
Loading