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

Merged
merged 36 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ac93521
add command
RidRisR Aug 12, 2024
b698c61
add more
RidRisR Aug 13, 2024
5bc9a60
add truncate task
RidRisR Aug 15, 2024
d4d0477
add pause(p1)
RidRisR Aug 15, 2024
66f0c91
task didn't apply
RidRisR Aug 15, 2024
f94c12f
done
RidRisR Aug 15, 2024
e7f8537
handel skip
RidRisR Aug 26, 2024
5be5ee0
before bm
RidRisR Aug 26, 2024
3a5f24c
add resume
RidRisR Aug 27, 2024
a69c409
add pause
RidRisR Aug 27, 2024
cc89346
change states
RidRisR Aug 29, 2024
6ad5981
fix
RidRisR Aug 30, 2024
c58b62c
fix resume failed
RidRisR Aug 30, 2024
bd13740
add test
RidRisR Sep 3, 2024
236b63f
fix comments
RidRisR Sep 23, 2024
62ecb74
make subcommand and logStop conflict
RidRisR Sep 23, 2024
1bea7be
add alreadySync logic
RidRisR Sep 24, 2024
a5be493
better truncate
RidRisR Sep 24, 2024
ea818c4
remove explict truncate
RidRisR Sep 24, 2024
27cd7fb
add tests
RidRisR Sep 25, 2024
43d4010
add validation of unknown sub -commnad
RidRisR Sep 25, 2024
1c68708
lint
RidRisR Sep 25, 2024
292b350
typo
RidRisR Sep 25, 2024
2797bf3
add truncate check
RidRisR Sep 25, 2024
90cf8f2
handle empty subcommand
RidRisR Sep 25, 2024
a31daf1
more restricted subCommand check
RidRisR Sep 25, 2024
04721de
user should be able to truncate after stop
RidRisR Sep 25, 2024
aebc1d5
lint
RidRisR Sep 25, 2024
4fab351
lint
RidRisR Sep 25, 2024
638ca5f
compatible with old version
RidRisR Sep 27, 2024
d74f1e3
Merge branch 'master' into subcommand
ti-chi-bot[bot] Sep 29, 2024
726e5b3
Update backup.go
RidRisR Sep 29, 2024
d9d4673
Merge branch 'master' into subcommand
ti-chi-bot[bot] Oct 8, 2024
79fb586
fix condition
RidRisR Oct 8, 2024
e0b2e0b
fix rerunable command
RidRisR Oct 8, 2024
ab5daea
fix
RidRisR Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 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,20 @@ 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),
}
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 +195,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 pauses 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,
csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
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
29 changes: 29 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ Default is current timestamp.</p>
</tr>
<tr>
<td>
<code>logSubcommand</code></br>
<em>
<a href="#logsubcommandtype">
LogSubCommandType
</a>
</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 +4248,20 @@ Default is current timestamp.</p>
</tr>
<tr>
<td>
<code>logSubcommand</code></br>
<em>
<a href="#logsubcommandtype">
LogSubCommandType
</a>
</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 @@ -8890,6 +8918,7 @@ BackupConditionType
<p>
(<em>Appears on:</em>
<a href="#backupcondition">BackupCondition</a>,
<a href="#backupspec">BackupSpec</a>,
<a href="#logsubcommandstatus">LogSubCommandStatus</a>)
</p>
<p>
Expand Down
4 changes: 0 additions & 4 deletions hack/local-up-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This command runs tidb-operator in Kubernetes.
#

# Default provider is kind
PROVIDER=${PROVIDER:-kind}

Expand Down
Loading
Loading