Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
145 changes: 145 additions & 0 deletions br/cmd/br/abort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright 2025 PingCAP, Inc. Licensed under Apache-2.0.

package main

import (
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/tidb/br/pkg/task"
"github.com/pingcap/tidb/br/pkg/trace"
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/spf13/cobra"
"go.uber.org/zap"
"sourcegraph.com/sourcegraph/appdash"
)

// NewAbortCommand returns an abort subcommand
func NewAbortCommand() *cobra.Command {
command := &cobra.Command{
Use: "abort",
Short: "abort restore tasks",
SilenceUsage: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
if err := Init(c); err != nil {
return errors.Trace(err)
}
build.LogInfo(build.BR)
logutil.LogEnvVariables()

Check failure on line 29 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

undefined: logutil.LogEnvVariables

Check failure on line 29 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

undefined: logutil.LogEnvVariables

Check failure on line 29 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

undefined: logutil.LogEnvVariables
task.LogArguments(c)
// disable stats otherwise takes too much memory
session.DisableStats4Test()

return nil
},
}

command.AddCommand(
newAbortRestoreCommand(),
// future: newAbortBackupCommand(),
)
task.DefineRestoreFlags(command.PersistentFlags())

return command
}

// newAbortRestoreCommand returns an abort restore subcommand
func newAbortRestoreCommand() *cobra.Command {
command := &cobra.Command{
Use: "restore",
Short: "abort restore tasks",
SilenceUsage: true,
}

command.AddCommand(
newAbortRestoreFullCommand(),
newAbortRestoreDBCommand(),
newAbortRestoreTableCommand(),
newAbortRestorePointCommand(),
)

return command
}

func newAbortRestoreFullCommand() *cobra.Command {
command := &cobra.Command{
Use: "full",
Short: "abort a full restore task",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runAbortRestoreCommand(cmd, task.FullRestoreCmd)
},
}
// define flags specific to full restore
task.DefineFilterFlags(command, filterOutSysAndMemKeepAuthAndBind, false)

Check failure on line 75 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

undefined: filterOutSysAndMemKeepAuthAndBind

Check failure on line 75 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

undefined: filterOutSysAndMemKeepAuthAndBind

Check failure on line 75 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

undefined: filterOutSysAndMemKeepAuthAndBind
task.DefineRestoreSnapshotFlags(command)
return command
}

func newAbortRestoreDBCommand() *cobra.Command {
command := &cobra.Command{
Use: "db",
Short: "abort a database restore task",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runAbortRestoreCommand(cmd, task.DBRestoreCmd)
},
}
task.DefineDatabaseFlags(command)
return command
}

func newAbortRestoreTableCommand() *cobra.Command {
command := &cobra.Command{
Use: "table",
Short: "abort a table restore task",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runAbortRestoreCommand(cmd, task.TableRestoreCmd)
},
}
task.DefineTableFlags(command)
return command
}

func newAbortRestorePointCommand() *cobra.Command {
command := &cobra.Command{
Use: "point",
Short: "abort a point-in-time restore task",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return runAbortRestoreCommand(cmd, task.PointRestoreCmd)
},
}
task.DefineFilterFlags(command, filterOutSysAndMemKeepAuthAndBind, true)

Check failure on line 115 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

undefined: filterOutSysAndMemKeepAuthAndBind

Check failure on line 115 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

undefined: filterOutSysAndMemKeepAuthAndBind

Check failure on line 115 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

undefined: filterOutSysAndMemKeepAuthAndBind
task.DefineStreamRestoreFlags(command)
return command
}

func runAbortRestoreCommand(command *cobra.Command, cmdName string) error {
cfg := task.RestoreConfig{Config: task.Config{LogProgress: HasLogFile()}}
if err := cfg.ParseFromFlags(command.Flags(), false); err != nil {
command.SilenceUsage = false
return errors.Trace(err)
}

if task.IsStreamRestore(cmdName) {
if err := cfg.ParseStreamRestoreFlags(command.Flags()); err != nil {
return errors.Trace(err)
}
}

ctx := GetDefaultContext()
if cfg.EnableOpenTracing {
var store *appdash.MemoryStore
ctx, store = trace.TracerStartSpan(ctx)
defer trace.TracerFinishSpan(ctx, store)
}

if err := task.RunRestoreAbort(ctx, tidbGlue, cmdName, &cfg); err != nil {

Check failure on line 140 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

undefined: task.RunRestoreAbort

Check failure on line 140 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

undefined: task.RunRestoreAbort

Check failure on line 140 in br/cmd/br/abort.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

undefined: task.RunRestoreAbort
log.Error("failed to abort restore task", zap.Error(err))
return errors.Trace(err)
}
return nil
}
3 changes: 0 additions & 3 deletions br/cmd/br/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"github.com/pingcap/tidb/br/pkg/trace"
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/pkg/config"

Check failure on line 14 in br/cmd/br/backup.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

"github.com/pingcap/tidb/pkg/config" imported and not used

Check failure on line 14 in br/cmd/br/backup.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

"github.com/pingcap/tidb/pkg/config" imported and not used

Check failure on line 14 in br/cmd/br/backup.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

"github.com/pingcap/tidb/pkg/config" imported and not used
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/util/metricsutil"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -112,9 +112,6 @@
utils.LogEnvVariables()
task.LogArguments(c)

// Do not run ddl worker in BR.
config.GetGlobalConfig().Instance.TiDBEnableDDL.Store(false)

summary.SetUnit(summary.BackupUnit)
return nil
},
Expand Down
4 changes: 4 additions & 0 deletions br/cmd/br/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/pingcap/log"
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/pkg/config"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
Expand All @@ -22,6 +23,9 @@ func main() {
}
DefineCommonFlags(rootCmd)
SetDefaultContext(ctx)

config.GetGlobalConfig().Instance.TiDBEnableDDL.Store(false)

rootCmd.AddCommand(
NewDebugCommand(),
NewBackupCommand(),
Expand Down
Loading