Skip to content

Commit 4eeaee1

Browse files
Leavrthti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#63090
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 31bc209 commit 4eeaee1

File tree

3 files changed

+153
-3
lines changed

3 files changed

+153
-3
lines changed

br/cmd/br/abort.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2025 PingCAP, Inc. Licensed under Apache-2.0.
2+
3+
package main
4+
5+
import (
6+
"github.com/pingcap/errors"
7+
"github.com/pingcap/log"
8+
"github.com/pingcap/tidb/br/pkg/task"
9+
"github.com/pingcap/tidb/br/pkg/trace"
10+
"github.com/pingcap/tidb/br/pkg/version/build"
11+
"github.com/pingcap/tidb/pkg/session"
12+
"github.com/pingcap/tidb/pkg/util/logutil"
13+
"github.com/spf13/cobra"
14+
"go.uber.org/zap"
15+
"sourcegraph.com/sourcegraph/appdash"
16+
)
17+
18+
// NewAbortCommand returns an abort subcommand
19+
func NewAbortCommand() *cobra.Command {
20+
command := &cobra.Command{
21+
Use: "abort",
22+
Short: "abort restore tasks",
23+
SilenceUsage: true,
24+
PersistentPreRunE: func(c *cobra.Command, args []string) error {
25+
if err := Init(c); err != nil {
26+
return errors.Trace(err)
27+
}
28+
build.LogInfo(build.BR)
29+
logutil.LogEnvVariables()
30+
task.LogArguments(c)
31+
// disable stats otherwise takes too much memory
32+
session.DisableStats4Test()
33+
34+
return nil
35+
},
36+
}
37+
38+
command.AddCommand(
39+
newAbortRestoreCommand(),
40+
// future: newAbortBackupCommand(),
41+
)
42+
task.DefineRestoreFlags(command.PersistentFlags())
43+
44+
return command
45+
}
46+
47+
// newAbortRestoreCommand returns an abort restore subcommand
48+
func newAbortRestoreCommand() *cobra.Command {
49+
command := &cobra.Command{
50+
Use: "restore",
51+
Short: "abort restore tasks",
52+
SilenceUsage: true,
53+
}
54+
55+
command.AddCommand(
56+
newAbortRestoreFullCommand(),
57+
newAbortRestoreDBCommand(),
58+
newAbortRestoreTableCommand(),
59+
newAbortRestorePointCommand(),
60+
)
61+
62+
return command
63+
}
64+
65+
func newAbortRestoreFullCommand() *cobra.Command {
66+
command := &cobra.Command{
67+
Use: "full",
68+
Short: "abort a full restore task",
69+
Args: cobra.NoArgs,
70+
RunE: func(cmd *cobra.Command, _ []string) error {
71+
return runAbortRestoreCommand(cmd, task.FullRestoreCmd)
72+
},
73+
}
74+
// define flags specific to full restore
75+
task.DefineFilterFlags(command, filterOutSysAndMemKeepAuthAndBind, false)
76+
task.DefineRestoreSnapshotFlags(command)
77+
return command
78+
}
79+
80+
func newAbortRestoreDBCommand() *cobra.Command {
81+
command := &cobra.Command{
82+
Use: "db",
83+
Short: "abort a database restore task",
84+
Args: cobra.NoArgs,
85+
RunE: func(cmd *cobra.Command, _ []string) error {
86+
return runAbortRestoreCommand(cmd, task.DBRestoreCmd)
87+
},
88+
}
89+
task.DefineDatabaseFlags(command)
90+
return command
91+
}
92+
93+
func newAbortRestoreTableCommand() *cobra.Command {
94+
command := &cobra.Command{
95+
Use: "table",
96+
Short: "abort a table restore task",
97+
Args: cobra.NoArgs,
98+
RunE: func(cmd *cobra.Command, _ []string) error {
99+
return runAbortRestoreCommand(cmd, task.TableRestoreCmd)
100+
},
101+
}
102+
task.DefineTableFlags(command)
103+
return command
104+
}
105+
106+
func newAbortRestorePointCommand() *cobra.Command {
107+
command := &cobra.Command{
108+
Use: "point",
109+
Short: "abort a point-in-time restore task",
110+
Args: cobra.NoArgs,
111+
RunE: func(cmd *cobra.Command, _ []string) error {
112+
return runAbortRestoreCommand(cmd, task.PointRestoreCmd)
113+
},
114+
}
115+
task.DefineFilterFlags(command, filterOutSysAndMemKeepAuthAndBind, true)
116+
task.DefineStreamRestoreFlags(command)
117+
return command
118+
}
119+
120+
func runAbortRestoreCommand(command *cobra.Command, cmdName string) error {
121+
cfg := task.RestoreConfig{Config: task.Config{LogProgress: HasLogFile()}}
122+
if err := cfg.ParseFromFlags(command.Flags(), false); err != nil {
123+
command.SilenceUsage = false
124+
return errors.Trace(err)
125+
}
126+
127+
if task.IsStreamRestore(cmdName) {
128+
if err := cfg.ParseStreamRestoreFlags(command.Flags()); err != nil {
129+
return errors.Trace(err)
130+
}
131+
}
132+
133+
ctx := GetDefaultContext()
134+
if cfg.EnableOpenTracing {
135+
var store *appdash.MemoryStore
136+
ctx, store = trace.TracerStartSpan(ctx)
137+
defer trace.TracerFinishSpan(ctx, store)
138+
}
139+
140+
if err := task.RunRestoreAbort(ctx, tidbGlue, cmdName, &cfg); err != nil {
141+
log.Error("failed to abort restore task", zap.Error(err))
142+
return errors.Trace(err)
143+
}
144+
return nil
145+
}

br/cmd/br/backup.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ func NewBackupCommand() *cobra.Command {
111111
utils.LogEnvVariables()
112112
task.LogArguments(c)
113113

114-
// Do not run ddl worker in BR.
115-
config.GetGlobalConfig().Instance.TiDBEnableDDL.Store(false)
116-
117114
summary.SetUnit(summary.BackupUnit)
118115
return nil
119116
},

br/cmd/br/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"syscall"
99

1010
"github.com/pingcap/log"
11+
<<<<<<< HEAD
12+
=======
13+
"github.com/pingcap/tidb/br/pkg/utils"
14+
"github.com/pingcap/tidb/pkg/config"
15+
>>>>>>> ec36da2bfc2 (br: prevent br from becoming ddl owner (#63090))
1116
"github.com/spf13/cobra"
1217
"go.uber.org/zap"
1318
)
@@ -44,6 +49,9 @@ func main() {
4449
}
4550
AddFlags(rootCmd)
4651
SetDefaultContext(ctx)
52+
53+
config.GetGlobalConfig().Instance.TiDBEnableDDL.Store(false)
54+
4755
rootCmd.AddCommand(
4856
NewDebugCommand(),
4957
NewBackupCommand(),

0 commit comments

Comments
 (0)