From 5095ad9a84378985dc7789f3f74350e155f1b15a Mon Sep 17 00:00:00 2001 From: nexustar Date: Tue, 7 Mar 2023 18:31:13 +0800 Subject: [PATCH 1/7] scp: create dir before download (#2132) --- components/cluster/command/import.go | 2 +- pkg/cluster/executor/local.go | 4 ++-- pkg/cluster/executor/ssh.go | 6 +++++- pkg/cluster/manager/cacert.go | 3 ++- pkg/cluster/spec/profile.go | 4 +--- pkg/cluster/spec/spec_manager.go | 2 +- pkg/cluster/task/tls.go | 3 ++- pkg/logger/audit.go | 4 ++-- pkg/utils/http_client.go | 2 +- pkg/utils/ioutil.go | 11 ----------- 10 files changed, 17 insertions(+), 24 deletions(-) diff --git a/components/cluster/command/import.go b/components/cluster/command/import.go index f153c20d6e..a7444d5bb5 100644 --- a/components/cluster/command/import.go +++ b/components/cluster/command/import.go @@ -123,7 +123,7 @@ func newImportCmd() *cobra.Command { } // copy SSH key to TiUP profile directory - if err = tiuputils.CreateDir(spec.ClusterPath(clsName, "ssh")); err != nil { + if err = os.MkdirAll(spec.ClusterPath(clsName, "ssh"), 0755); err != nil { return err } srcKeyPathPriv := ansible.SSHKeyPath() diff --git a/pkg/cluster/executor/local.go b/pkg/cluster/executor/local.go index 9a3a13f475..adf20e1cd7 100644 --- a/pkg/cluster/executor/local.go +++ b/pkg/cluster/executor/local.go @@ -17,6 +17,7 @@ import ( "bytes" "context" "fmt" + "os" "os/exec" "os/user" "path/filepath" @@ -26,7 +27,6 @@ import ( "github.com/fatih/color" "github.com/pingcap/tiup/pkg/cluster/ctxt" "github.com/pingcap/tiup/pkg/tui" - "github.com/pingcap/tiup/pkg/utils" "go.uber.org/zap" ) @@ -110,7 +110,7 @@ func (l *Local) Execute(ctx context.Context, cmd string, sudo bool, timeout ...t // Transfer implements Executer interface. func (l *Local) Transfer(ctx context.Context, src, dst string, download bool, limit int, _ bool) error { targetPath := filepath.Dir(dst) - if err := utils.CreateDir(targetPath); err != nil { + if err := os.MkdirAll(targetPath, 0755); err != nil { return err } diff --git a/pkg/cluster/executor/ssh.go b/pkg/cluster/executor/ssh.go index 2e6b8f88e3..ac4774725f 100644 --- a/pkg/cluster/executor/ssh.go +++ b/pkg/cluster/executor/ssh.go @@ -217,6 +217,10 @@ func (e *EasySSHExecutor) Transfer(ctx context.Context, src, dst string, downloa defer client.Close() defer session.Close() + err = os.MkdirAll(filepath.Dir(dst), 0755) + if err != nil { + return nil + } return ScpDownload(session, client, src, dst, limit, compress) } @@ -379,7 +383,7 @@ func (e *NativeSSHExecutor) Transfer(ctx context.Context, src, dst string, downl if download { targetPath := filepath.Dir(dst) - if err := utils.CreateDir(targetPath); err != nil { + if err := os.MkdirAll(targetPath, 0755); err != nil { return err } args = append(args, fmt.Sprintf("%s@%s:%s", e.Config.User, e.Config.Host, src), dst) diff --git a/pkg/cluster/manager/cacert.go b/pkg/cluster/manager/cacert.go index 48cdfe751a..725d42585f 100644 --- a/pkg/cluster/manager/cacert.go +++ b/pkg/cluster/manager/cacert.go @@ -17,6 +17,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" + "os" "path/filepath" perrs "github.com/pingcap/errors" @@ -108,7 +109,7 @@ func (m *Manager) genAndSaveCertificate(clusterName string, globalOptions *spec. if globalOptions.TLSEnabled { // generate CA tlsPath := m.specManager.Path(clusterName, spec.TLSCertKeyDir) - if err := utils.CreateDir(tlsPath); err != nil { + if err := os.MkdirAll(tlsPath, 0755); err != nil { return nil, err } ca, err := genAndSaveClusterCA(clusterName, tlsPath) diff --git a/pkg/cluster/spec/profile.go b/pkg/cluster/spec/profile.go index 7ad4ba7c5d..5adf72c455 100644 --- a/pkg/cluster/spec/profile.go +++ b/pkg/cluster/spec/profile.go @@ -19,8 +19,6 @@ import ( "path" "path/filepath" - utils2 "github.com/pingcap/tiup/pkg/utils" - "github.com/pingcap/errors" tiuplocaldata "github.com/pingcap/tiup/pkg/localdata" ) @@ -82,7 +80,7 @@ func Initialize(base string) error { }) initialized = true // make sure the dir exist - return utils2.CreateDir(profileDir) + return os.MkdirAll(profileDir, 0755) } // ProfileDir returns the full profile directory path of TiUP. diff --git a/pkg/cluster/spec/spec_manager.go b/pkg/cluster/spec/spec_manager.go index 79771effd5..e79e83a0d1 100644 --- a/pkg/cluster/spec/spec_manager.go +++ b/pkg/cluster/spec/spec_manager.go @@ -199,7 +199,7 @@ func (s *SpecManager) GetAllClusters() (map[string]Metadata, error) { // ensureDir ensures that the cluster directory exists. func (s *SpecManager) ensureDir(clusterName string) error { - if err := utils.CreateDir(s.Path(clusterName)); err != nil { + if err := os.MkdirAll(s.Path(clusterName), 0755); err != nil { return ErrCreateDirFailed. Wrap(err, "Failed to create cluster metadata directory '%s'", s.Path(clusterName)). WithProperty(tui.SuggestionFromString("Please check file system permissions and try again.")) diff --git a/pkg/cluster/task/tls.go b/pkg/cluster/task/tls.go index 956148e34c..34d410da80 100644 --- a/pkg/cluster/task/tls.go +++ b/pkg/cluster/task/tls.go @@ -18,6 +18,7 @@ import ( "encoding/pem" "fmt" "net" + "os" "path/filepath" "github.com/pingcap/errors" @@ -64,7 +65,7 @@ func (c *TLSCert) Execute(ctx context.Context) error { } // make sure the cache dir exist - if err := utils.CreateDir(c.paths.Cache); err != nil { + if err := os.MkdirAll(c.paths.Cache, 0755); err != nil { return err } diff --git a/pkg/logger/audit.go b/pkg/logger/audit.go index 887c195a9c..52cf6e065b 100644 --- a/pkg/logger/audit.go +++ b/pkg/logger/audit.go @@ -15,9 +15,9 @@ package logger import ( "bytes" + "os" "github.com/pingcap/tiup/pkg/cluster/audit" - "github.com/pingcap/tiup/pkg/utils" "go.uber.org/atomic" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -50,7 +50,7 @@ func OutputAuditLogToFileIfEnabled(dir, fileSuffix string) error { return nil } - if err := utils.CreateDir(dir); err != nil { + if err := os.MkdirAll(dir, 0755); err != nil { return err } diff --git a/pkg/utils/http_client.go b/pkg/utils/http_client.go index ed48f60ea1..b9077d49af 100644 --- a/pkg/utils/http_client.go +++ b/pkg/utils/http_client.go @@ -103,7 +103,7 @@ func (c *HTTPClient) Download(ctx context.Context, url, filePath string) error { return fmt.Errorf("target file %s already exists", filePath) } - if err := CreateDir(filepath.Dir(filePath)); err != nil { + if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil { return err } diff --git a/pkg/utils/ioutil.go b/pkg/utils/ioutil.go index 7e6431d346..45d19a734b 100644 --- a/pkg/utils/ioutil.go +++ b/pkg/utils/ioutil.go @@ -242,17 +242,6 @@ func Move(src, dst string) error { return errors.Trace(os.RemoveAll(src)) } -// CreateDir creates the directory if it not exists. -func CreateDir(path string) error { - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - return os.MkdirAll(path, 0755) - } - return err - } - return nil -} - // Checksum returns the sha1 sum of target file func Checksum(file string) (string, error) { tarball, err := os.OpenFile(file, os.O_RDONLY, 0) From 320d0b1c1b94752233c4144c26b7daa82aac1623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qi=CE=BC=24hi=D0=AFu=C3=AD?= <39378935+srstack@users.noreply.github.com> Date: Wed, 8 Mar 2023 18:35:12 +0800 Subject: [PATCH 2/7] cluster: check upgrade offline (#2116) --- pkg/cluster/manager/upgrade.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/pkg/cluster/manager/upgrade.go b/pkg/cluster/manager/upgrade.go index 6346498885..2aaf62638b 100644 --- a/pkg/cluster/manager/upgrade.go +++ b/pkg/cluster/manager/upgrade.go @@ -17,6 +17,8 @@ import ( "context" "fmt" "os" + "strings" + "time" "github.com/fatih/color" "github.com/joomcode/errorx" @@ -194,11 +196,33 @@ Do you want to continue? [y/N]:`, return err } } - + ctx := ctxt.New( + context.Background(), + opt.Concurrency, + m.logger, + ) tlsCfg, err := topo.TLSConfig(m.specManager.Path(name, spec.TLSCertKeyDir)) if err != nil { return err } + + // make sure the cluster is stopped + if offline && !opt.Force { + running := false + topo.IterInstance(func(ins spec.Instance) { + if !running { + status := ins.Status(ctx, time.Duration(opt.APITimeout), tlsCfg, topo.BaseTopo().MasterList...) + if strings.HasPrefix(status, "Up") || strings.HasPrefix(status, "Healthy") { + running = true + } + } + }, opt.Concurrency) + + if running { + return perrs.Errorf("cluster is running and cannot be upgraded offline") + } + } + b, err := m.sshTaskBuilder(name, topo, base.User, opt) if err != nil { return err @@ -214,11 +238,6 @@ Do you want to continue? [y/N]:`, }). Build() - ctx := ctxt.New( - context.Background(), - opt.Concurrency, - m.logger, - ) if err := t.Execute(ctx); err != nil { if errorx.Cast(err) != nil { // FIXME: Map possible task errors and give suggestions. From b270aafc1ff869ac2a2f0eda3ad2cd7071114b63 Mon Sep 17 00:00:00 2001 From: Jianyuan Jiang Date: Thu, 9 Mar 2023 11:41:12 +0800 Subject: [PATCH 3/7] add ticdc port prob config (#2124) --- embed/templates/config/prometheus.yml.tpl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embed/templates/config/prometheus.yml.tpl b/embed/templates/config/prometheus.yml.tpl index 52ecb35cec..fba0a26e87 100644 --- a/embed/templates/config/prometheus.yml.tpl +++ b/embed/templates/config/prometheus.yml.tpl @@ -320,6 +320,14 @@ scrape_configs: {{- end}} labels: group: 'tiflash' +{{- end}} +{{- if .CDCAddrs}} + - targets: + {{- range .CDCAddrs}} + - '{{.}}' + {{- end}} + labels: + group: 'ticdc' {{- end}} relabel_configs: - source_labels: [__address__] From 7fcde36f3d402ad5be2737ee8428e5f7dbae1ce4 Mon Sep 17 00:00:00 2001 From: Kimi WANG Date: Thu, 9 Mar 2023 17:31:13 +0800 Subject: [PATCH 4/7] =?UTF-8?q?Allow=20users=20to=20run=20custom=20shell?= =?UTF-8?q?=20commands=20during=20the=20cluster=20rolling=20u=E2=80=A6=20(?= =?UTF-8?q?#2130)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/cluster/command/reload.go | 2 ++ components/cluster/command/upgrade.go | 2 ++ pkg/cluster/operation/action.go | 18 ++++++++++++++++++ pkg/cluster/operation/operation.go | 22 ++++++++++++++++++++++ pkg/cluster/operation/upgrade.go | 10 ++++++++++ 5 files changed, 54 insertions(+) diff --git a/components/cluster/command/reload.go b/components/cluster/command/reload.go index 9fb48aaac1..ab2c388037 100644 --- a/components/cluster/command/reload.go +++ b/components/cluster/command/reload.go @@ -55,6 +55,8 @@ func newReloadCmd() *cobra.Command { cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture") cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result") cmd.Flags().BoolVar(&skipRestart, "skip-restart", false, "Only refresh configuration to remote and do not restart services") + cmd.Flags().StringVar(&gOpt.SSHCustomScripts.BeforeRestartInstance.Raw, "pre-restart-script", "", "(EXPERIMENTAL) Custom script to be executed on each server before the service is restarted, does not take effect when --skip-restart is set to true") + cmd.Flags().StringVar(&gOpt.SSHCustomScripts.AfterRestartInstance.Raw, "post-restart-script", "", "(EXPERIMENTAL) Custom script to be executed on each server after the service is restarted, does not take effect when --skip-restart is set to true") return cmd } diff --git a/components/cluster/command/upgrade.go b/components/cluster/command/upgrade.go index 592cef0c4b..2afe973a07 100644 --- a/components/cluster/command/upgrade.go +++ b/components/cluster/command/upgrade.go @@ -53,6 +53,8 @@ func newUpgradeCmd() *cobra.Command { cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture") cmd.Flags().BoolVarP(&gOpt.IgnoreConfigCheck, "ignore-config-check", "", false, "Ignore the config check result") cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster") + cmd.Flags().StringVar(&gOpt.SSHCustomScripts.BeforeRestartInstance.Raw, "pre-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server before the server is upgraded") + cmd.Flags().StringVar(&gOpt.SSHCustomScripts.AfterRestartInstance.Raw, "post-upgrade-script", "", "(EXPERIMENTAL) Custom script to be executed on each server after the server is upgraded") return cmd } diff --git a/pkg/cluster/operation/action.go b/pkg/cluster/operation/action.go index 4015e0260e..a2738023ab 100644 --- a/pkg/cluster/operation/action.go +++ b/pkg/cluster/operation/action.go @@ -653,3 +653,21 @@ func monitorPortMap(options *spec.MonitoredOptions) map[string]int { spec.ComponentBlackboxExporter: options.BlackboxExporterPort, } } + +func executeSSHCommand(ctx context.Context, action, host, command string) error { + if command == "" { + return nil + } + e, found := ctxt.GetInner(ctx).GetExecutor(host) + if !found { + return fmt.Errorf("no executor") + } + logger := ctx.Value(logprinter.ContextKeyLogger).(*logprinter.Logger) + logger.Infof("\t%s on %s", action, host) + stdout, stderr, err := e.Execute(ctx, command, false) + if err != nil { + return errors.Annotatef(err, "stderr: %s", string(stderr)) + } + logger.Infof("\t%s", stdout) + return nil +} diff --git a/pkg/cluster/operation/operation.go b/pkg/cluster/operation/operation.go index 6c97324b85..0f50b20377 100644 --- a/pkg/cluster/operation/operation.go +++ b/pkg/cluster/operation/operation.go @@ -15,6 +15,7 @@ package operator import ( "fmt" + "os" "github.com/pingcap/tiup/pkg/cluster/executor" "github.com/pingcap/tiup/pkg/cluster/spec" @@ -45,6 +46,7 @@ type Options struct { SSHProxyIdentity string // the ssh proxy identity file SSHProxyUsePassword bool // use password instead of identity file for ssh proxy connection SSHProxyTimeout uint64 // timeout in seconds when connecting the proxy host + SSHCustomScripts SSHCustomScripts // custom scripts to be executed during the operation // What type of things should we cleanup in clean command CleanupData bool // should we cleanup data @@ -59,6 +61,26 @@ type Options struct { Operation Operation } +// SSHCustomScripts represents the custom ssh script set to be executed during cluster operations +type SSHCustomScripts struct { + BeforeRestartInstance SSHCustomScript + AfterRestartInstance SSHCustomScript +} + +// SSHCustomScript represents a custom ssh script to be executed during cluster operations +type SSHCustomScript struct { + Raw string +} + +// Command returns the ssh command in string format +func (s SSHCustomScript) Command() string { + b, err := os.ReadFile(s.Raw) + if err != nil { + return s.Raw + } + return string(b) +} + // Operation represents the type of cluster operation type Operation byte diff --git a/pkg/cluster/operation/upgrade.go b/pkg/cluster/operation/upgrade.go index e1d77b0e25..38f10f453f 100644 --- a/pkg/cluster/operation/upgrade.go +++ b/pkg/cluster/operation/upgrade.go @@ -211,6 +211,11 @@ func upgradeInstance( rollingInstance, isRollingInstance = instance.(spec.RollingUpdateInstance) } + err = executeSSHCommand(ctx, "Executing pre-upgrade command", instance.GetHost(), options.SSHCustomScripts.BeforeRestartInstance.Command()) + if err != nil { + return err + } + if isRollingInstance { err := rollingInstance.PreRestart(ctx, topo, int(options.APITimeout), tlsCfg) if err != nil && !options.Force { @@ -229,6 +234,11 @@ func upgradeInstance( } } + err = executeSSHCommand(ctx, "Executing post-upgrade command", instance.GetHost(), options.SSHCustomScripts.AfterRestartInstance.Command()) + if err != nil { + return err + } + return nil } From 72cbdf490a21c5827fa6ae7f8801a6e29b1b8575 Mon Sep 17 00:00:00 2001 From: nexustar Date: Mon, 13 Mar 2023 16:50:40 +0800 Subject: [PATCH 5/7] cluster: delete !#$%&= from init password (#2136) --- pkg/crypto/rand/passwd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/crypto/rand/passwd.go b/pkg/crypto/rand/passwd.go index 132cd3d2d4..924c683091 100644 --- a/pkg/crypto/rand/passwd.go +++ b/pkg/crypto/rand/passwd.go @@ -22,7 +22,7 @@ const ( lowerLetters = "abcdefghijkmnpqrstuvwxyz" upperLetters = "ABCDEFGHJKLMNPQRSTUVWXYZ" digits = "0123456789" - symbols = "!@#$%^&*+-=_" + symbols = "@^*+-_" ) // Password generates a random password From cb852ef6bf374c63a586671d2e6448c9f463ba51 Mon Sep 17 00:00:00 2001 From: hongyunyan <649330952@qq.com> Date: Tue, 14 Mar 2023 12:22:42 +0800 Subject: [PATCH 6/7] Remove mark_cache_size default value of tiflash.toml after v5.4.0 (#2138) --- components/playground/instance/tiflash_config.go | 8 +++++--- pkg/cluster/ansible/service_test.go | 1 - pkg/cluster/spec/tiflash.go | 8 ++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/playground/instance/tiflash_config.go b/components/playground/instance/tiflash_config.go index 28ee942d01..a990cc8a5a 100644 --- a/components/playground/instance/tiflash_config.go +++ b/components/playground/instance/tiflash_config.go @@ -29,15 +29,17 @@ runAsDaemon = true ` +const tiflashMarkCacheSize = `mark_cache_size = 5368709120` + const tiflashConfig = ` default_profile = "default" display_name = "TiFlash" http_port = %[2]d listen_host = "0.0.0.0" -mark_cache_size = 5368709120 path = "%[5]s" tcp_port = %[3]d tmp_path = "%[6]s" +%[14]s %[13]s [flash] service_addr = "%[10]s:%[8]d" @@ -107,11 +109,11 @@ func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, s if tidbver.TiFlashNotNeedSomeConfig(version.String()) { conf = fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, deployDir, dataDir, tmpDir, logDir, servicePort, metricsPort, - ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath, "") + ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath, "", "") } else { conf = fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, deployDir, dataDir, tmpDir, logDir, servicePort, metricsPort, - ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath, tiflashDaemonConfig) + ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath, tiflashDaemonConfig, tiflashMarkCacheSize) } _, err := w.Write([]byte(conf)) return err diff --git a/pkg/cluster/ansible/service_test.go b/pkg/cluster/ansible/service_test.go index ffadc99877..f44aa73bf7 100644 --- a/pkg/cluster/ansible/service_test.go +++ b/pkg/cluster/ansible/service_test.go @@ -23,7 +23,6 @@ default_profile = "default" display_name = "TiFlash" http_port = 11316 listen_host = "0.0.0.0" -mark_cache_size = 5368709120 path = "/data1/test-cluster/leiysky-ansible-test-deploy/tiflash/data/db" tcp_port = 11315 tmp_path = "/data1/test-cluster/leiysky-ansible-test-deploy/tiflash/data/db/tmp" diff --git a/pkg/cluster/spec/tiflash.go b/pkg/cluster/spec/tiflash.go index 18cd5459e6..fc0d53dddd 100644 --- a/pkg/cluster/spec/tiflash.go +++ b/pkg/cluster/spec/tiflash.go @@ -377,6 +377,7 @@ func (i *TiFlashInstance) initTiFlashConfig(ctx context.Context, clusterVersion isStorageDirsDefined bool deprecatedUsersConfig string daemonConfig string + markCacheSize string err error ) if isStorageDirsDefined, err = checkTiFlashStorageConfigWithVersion(clusterVersion, src); err != nil { @@ -436,10 +437,12 @@ func (i *TiFlashInstance) initTiFlashConfig(ctx context.Context, clusterVersion topo := Specification{} if tidbver.TiFlashNotNeedSomeConfig(clusterVersion) { - // For 5.4.0 or later, TiFlash can ignore application.runAsDaemon setting + // For 5.4.0 or later, TiFlash can ignore application.runAsDaemon and mark_cache_size setting daemonConfig = "#" + markCacheSize = "#" } else { daemonConfig = `application.runAsDaemon: true` + markCacheSize = `mark_cache_size: 5368709120` } err = yaml.Unmarshal([]byte(fmt.Sprintf(` server_configs: @@ -447,7 +450,6 @@ server_configs: default_profile: "default" display_name: "TiFlash" listen_host: "%[7]s" - mark_cache_size: 5368709120 tmp_path: "%[11]s" %[1]s tcp_port: %[3]d @@ -470,6 +472,7 @@ server_configs: raft.pd_addr: "%[9]s" profiles.default.max_memory_usage: 0 %[12]s + %[14]s `, pathConfig, paths.Log, @@ -484,6 +487,7 @@ server_configs: fmt.Sprintf("%s/tmp", paths.Data[0]), deprecatedUsersConfig, daemonConfig, + markCacheSize, )), &topo) if err != nil { From c3c127f49e6d1e0cdbb89da51a43a2e045442e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 14 Mar 2023 06:32:38 +0100 Subject: [PATCH 7/7] playground: Allow setting the TiCDC port (#2140) --- components/playground/instance/ticdc.go | 7 +++++-- components/playground/main.go | 11 +++++++++++ components/playground/playground.go | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/components/playground/instance/ticdc.go b/components/playground/instance/ticdc.go index 36a4ab6c55..5c987b2c5a 100644 --- a/components/playground/instance/ticdc.go +++ b/components/playground/instance/ticdc.go @@ -34,14 +34,17 @@ type TiCDC struct { var _ Instance = &TiCDC{} // NewTiCDC create a TiCDC instance. -func NewTiCDC(binPath string, dir, host, configPath string, id int, pds []*PDInstance) *TiCDC { +func NewTiCDC(binPath string, dir, host, configPath string, id int, port int, pds []*PDInstance) *TiCDC { + if port <= 0 { + port = 8300 + } ticdc := &TiCDC{ instance: instance{ BinPath: binPath, ID: id, Dir: dir, Host: host, - Port: utils.MustGetFreePort(host, 8300), + Port: utils.MustGetFreePort(host, port), ConfigPath: configPath, }, pds: pds, diff --git a/components/playground/main.go b/components/playground/main.go index 6a8dec4897..1715dcace0 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -104,6 +104,8 @@ const ( dbPort = "db.port" pdHost = "pd.host" pdPort = "pd.port" + ticdcHost = "ticdc.host" + ticdcPort = "ticdc.port" // config paths dbConfig = "db.config" @@ -338,6 +340,8 @@ If you'd like to use a TiDB version other than %s, cancel and retry with the fol rootCmd.Flags().Int(dbPort, defaultOptions.TiDB.Port, "Playground TiDB port. If not provided, TiDB will use 4000 as its port") rootCmd.Flags().String(pdHost, defaultOptions.PD.Host, "Playground PD host. If not provided, PD will still use `host` flag as its host") rootCmd.Flags().Int(pdPort, defaultOptions.PD.Port, "Playground PD port. If not provided, PD will use 2379 as its port") + rootCmd.Flags().String(ticdcHost, defaultOptions.TiCDC.Host, "Playground TiCDC host. If not provided, TiDB will still use `host` flag as its host") + rootCmd.Flags().Int(ticdcPort, defaultOptions.TiCDC.Port, "Playground TiCDC port. If not provided, TiCDC will use 8300 as its port") rootCmd.Flags().String(dbConfig, defaultOptions.TiDB.ConfigPath, "TiDB instance configuration file") rootCmd.Flags().String(kvConfig, defaultOptions.TiKV.ConfigPath, "TiKV instance configuration file") @@ -500,6 +504,13 @@ func populateOpt(flagSet *pflag.FlagSet) (err error) { if err != nil { return } + case ticdcHost: + options.TiCDC.Host = flag.Value.String() + case ticdcPort: + options.TiCDC.Port, err = strconv.Atoi(flag.Value.String()) + if err != nil { + return + } case pdHost: options.PD.Host = flag.Value.String() case pdPort: diff --git a/components/playground/playground.go b/components/playground/playground.go index 9a721d5a92..320485a1a5 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -684,7 +684,7 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i ins = inst p.tiflashs = append(p.tiflashs, inst) case spec.ComponentCDC: - inst := instance.NewTiCDC(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) + inst := instance.NewTiCDC(cfg.BinPath, dir, host, cfg.ConfigPath, id, cfg.Port, p.pds) ins = inst p.ticdcs = append(p.ticdcs, inst) case spec.ComponentTiKVCDC: