diff --git a/br/cmd/br/BUILD.bazel b/br/cmd/br/BUILD.bazel index 1c20553569792..a95909dc84f03 100644 --- a/br/cmd/br/BUILD.bazel +++ b/br/cmd/br/BUILD.bazel @@ -7,7 +7,6 @@ go_library( "cmd.go", "debug.go", "main.go", - "operator.go", "restore.go", "stream.go", ], @@ -27,7 +26,6 @@ go_library( "//br/pkg/streamhelper/config", "//br/pkg/summary", "//br/pkg/task", - "//br/pkg/task/operator", "//br/pkg/trace", "//br/pkg/utils", "//br/pkg/version/build", diff --git a/br/cmd/br/main.go b/br/cmd/br/main.go index d70d9425e0653..29944fa9e2691 100644 --- a/br/cmd/br/main.go +++ b/br/cmd/br/main.go @@ -49,7 +49,6 @@ func main() { NewBackupCommand(), NewRestoreCommand(), NewStreamCommand(), - newOpeartorCommand(), ) // Outputs cmd.Print to stdout. rootCmd.SetOut(os.Stdout) diff --git a/br/cmd/br/operator.go b/br/cmd/br/operator.go deleted file mode 100644 index cfd48d85ae393..0000000000000 --- a/br/cmd/br/operator.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2023 PingCAP, Inc. Licensed under Apache-2.0. - -package main - -import ( - "github.com/pingcap/errors" - "github.com/pingcap/tidb/br/pkg/task" - "github.com/pingcap/tidb/br/pkg/task/operator" - "github.com/pingcap/tidb/br/pkg/utils" - "github.com/pingcap/tidb/br/pkg/version/build" - "github.com/spf13/cobra" -) - -func newOpeartorCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "operator ", - Short: "utilities for operators like tidb-operator.", - PersistentPreRunE: func(c *cobra.Command, args []string) error { - if err := Init(c); err != nil { - return errors.Trace(err) - } - build.LogInfo(build.BR) - utils.LogEnvVariables() - task.LogArguments(c) - return nil - }, - Hidden: true, - } - cmd.AddCommand(newPauseGcCommand()) - return cmd -} - -func newPauseGcCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "pause-gc", - Short: "pause gc to the ts until the program exits.", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - cfg := operator.PauseGcConfig{} - if err := cfg.ParseFromFlags(cmd.Flags()); err != nil { - return err - } - ctx := GetDefaultContext() - return operator.PauseGC(ctx, &cfg) - }, - } - operator.DefineFlagsForPauseGcConfig(cmd.Flags()) - return cmd -} diff --git a/br/pkg/pdutil/pd.go b/br/pkg/pdutil/pd.go index 14dac11b19e79..c0546a1801843 100644 --- a/br/pkg/pdutil/pd.go +++ b/br/pkg/pdutil/pd.go @@ -277,7 +277,7 @@ func NewPdController( } if failure != nil { return nil, errors.Annotatef(berrors.ErrPDUpdateFailed, - "pd address (%s) not available, error is %s, please check network", pdAddrs, failure) + "pd address (%s) not available, please check network", pdAddrs) } version := parseVersion(versionBytes) diff --git a/br/pkg/task/common.go b/br/pkg/task/common.go index 98b0810e8261e..3e1fa25d72840 100644 --- a/br/pkg/task/common.go +++ b/br/pkg/task/common.go @@ -138,15 +138,6 @@ func (tls *TLSConfig) ToTLSConfig() (*tls.Config, error) { return tlsConfig, nil } -// Convert the TLS config to the PD security option. -func (tls *TLSConfig) ToPDSecurityOption() pd.SecurityOption { - securityOption := pd.SecurityOption{} - securityOption.CAPath = tls.CA - securityOption.CertPath = tls.Cert - securityOption.KeyPath = tls.Key - return securityOption -} - // ParseFromFlags parses the TLS config from the flag set. func (tls *TLSConfig) ParseFromFlags(flags *pflag.FlagSet) (err error) { tls.CA, tls.Cert, tls.Key, err = ParseTLSTripleFromFlags(flags) diff --git a/br/pkg/task/operator/BUILD.bazel b/br/pkg/task/operator/BUILD.bazel deleted file mode 100644 index c2f1575403aec..0000000000000 --- a/br/pkg/task/operator/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "operator", - srcs = [ - "cmd.go", - "config.go", - ], - importpath = "github.com/pingcap/tidb/br/pkg/task/operator", - visibility = ["//visibility:public"], - deps = [ - "//br/pkg/pdutil", - "//br/pkg/task", - "//br/pkg/utils", - "@com_github_pingcap_log//:log", - "@com_github_spf13_pflag//:pflag", - "@org_uber_go_zap//:zap", - ], -) diff --git a/br/pkg/task/operator/cmd.go b/br/pkg/task/operator/cmd.go deleted file mode 100644 index 961b919073c9a..0000000000000 --- a/br/pkg/task/operator/cmd.go +++ /dev/null @@ -1,57 +0,0 @@ -package operator - -import ( - "context" - "crypto/tls" - "strings" - - "github.com/pingcap/log" - "github.com/pingcap/tidb/br/pkg/pdutil" - "github.com/pingcap/tidb/br/pkg/task" - "github.com/pingcap/tidb/br/pkg/utils" - "go.uber.org/zap" -) - -func dialPD(ctx context.Context, cfg *task.Config) (*pdutil.PdController, error) { - pdAddrs := strings.Join(cfg.PD, ",") - var tc *tls.Config - if cfg.TLS.IsEnabled() { - var err error - tc, err = cfg.TLS.ToTLSConfig() - if err != nil { - return nil, err - } - } - mgr, err := pdutil.NewPdController(ctx, pdAddrs, tc, cfg.TLS.ToPDSecurityOption()) - if err != nil { - return nil, err - } - return mgr, nil -} - -// PauseGC blocks the current goroutine and pause the GC safepoint by the config. -func PauseGC(ctx context.Context, cfg *PauseGcConfig) error { - mgr, err := dialPD(ctx, &cfg.Config) - if err != nil { - return err - } - sp := utils.BRServiceSafePoint{ - ID: utils.MakeSafePointID(), - TTL: int64(cfg.TTL.Seconds()), - BackupTS: cfg.SafePoint, - } - if sp.BackupTS == 0 { - rts, err := mgr.GetMinResolvedTS(ctx) - if err != nil { - return err - } - log.Info("No service safepoint provided, using the minimal resolved TS.", zap.Uint64("min-resolved-ts", rts)) - sp.BackupTS = rts - } - err = utils.StartServiceSafePointKeeper(ctx, mgr.GetPDClient(), sp) - if err != nil { - return err - } - <-ctx.Done() - return nil -} diff --git a/br/pkg/task/operator/config.go b/br/pkg/task/operator/config.go deleted file mode 100644 index eb7e12a49af56..0000000000000 --- a/br/pkg/task/operator/config.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2023 PingCAP, Inc. Licensed under Apache-2.0. - -package operator - -import ( - "time" - - "github.com/pingcap/tidb/br/pkg/task" - "github.com/spf13/pflag" -) - -type PauseGcConfig struct { - task.Config - - SafePoint uint64 `json:"safepoint" yaml:"safepoint"` - TTL time.Duration `json:"ttl" yaml:"ttl"` -} - -func DefineFlagsForPauseGcConfig(f *pflag.FlagSet) { - _ = f.DurationP("ttl", "i", 5*time.Minute, "The time-to-live of the safepoint.") - _ = f.Uint64P("safepoint", "t", 0, "The GC safepoint to be kept.") -} - -// ParseFromFlags fills the config via the flags. -func (cfg *PauseGcConfig) ParseFromFlags(flags *pflag.FlagSet) error { - if err := cfg.Config.ParseFromFlags(flags); err != nil { - return err - } - - var err error - cfg.SafePoint, err = flags.GetUint64("safepoint") - if err != nil { - return err - } - cfg.TTL, err = flags.GetDuration("ttl") - if err != nil { - return err - } - - return nil -}