diff --git a/components/playground/instance/drainer.go b/components/playground/instance/drainer.go index 5a102d9f35..f72aa4523f 100644 --- a/components/playground/instance/drainer.go +++ b/components/playground/instance/drainer.go @@ -19,7 +19,6 @@ import ( "path/filepath" "strings" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -70,7 +69,7 @@ func (d *Drainer) NodeID() string { } // Start implements Instance interface. -func (d *Drainer) Start(ctx context.Context, version utils.Version) error { +func (d *Drainer) Start(ctx context.Context) error { endpoints := pdEndpoints(d.pds, true) args := []string{ @@ -84,10 +83,6 @@ func (d *Drainer) Start(ctx context.Context, version utils.Version) error { args = append(args, fmt.Sprintf("--config=%s", d.ConfigPath)) } - var err error - if d.BinPath, err = tiupexec.PrepareBinary("drainer", version, d.BinPath); err != nil { - return err - } d.Process = &process{cmd: PrepareCommand(ctx, d.BinPath, args, nil, d.Dir)} logIfErr(d.Process.SetOutputFile(d.LogFile())) diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index 17a4440de6..9766fd67f2 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -23,6 +23,7 @@ import ( "github.com/BurntSushi/toml" "github.com/pingcap/errors" "github.com/pingcap/tiup/pkg/cluster/spec" + tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -53,6 +54,7 @@ type instance struct { StatusPort int // client port for PD ConfigPath string BinPath string + Version utils.Version } // MetricAddr will be used by prometheus scrape_configs. @@ -66,7 +68,7 @@ type Instance interface { Pid() int // Start the instance process. // Will kill the process once the context is done. - Start(ctx context.Context, version utils.Version) error + Start(ctx context.Context) error // Component Return the component name. Component() string // LogFile return the log file name @@ -78,6 +80,8 @@ type Instance interface { // Wait Should only call this if the instance is started successfully. // The implementation should be safe to call Wait multi times. Wait() error + // PrepareBinary use given binpath or download from tiup mirrors. + PrepareBinary(componentName string, version utils.Version) error } func (inst *instance) MetricAddr() (r MetricAddr) { @@ -87,6 +91,22 @@ func (inst *instance) MetricAddr() (r MetricAddr) { return } +func (inst *instance) PrepareBinary(componentName string, version utils.Version) error { + instanceBinPath, err := tiupexec.PrepareBinary(componentName, version, inst.BinPath) + if err != nil { + return err + } + // distinguish whether the instance is started by specific binary path. + if inst.BinPath == "" { + fmt.Printf("Start %s instance:%s\n", componentName, version) + } else { + fmt.Printf("Start %s instance:%s\n", componentName, instanceBinPath) + } + inst.Version = version + inst.BinPath = instanceBinPath + return nil +} + // CompVersion return the format to run specified version of a component. func CompVersion(comp string, version utils.Version) string { if version.IsEmpty() { diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index 52cb360d28..3c1d6f8636 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -20,7 +20,6 @@ import ( "strings" "github.com/pingcap/errors" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -88,7 +87,7 @@ func (inst *PDInstance) Name() string { } // Start calls set inst.cmd and Start -func (inst *PDInstance) Start(ctx context.Context, version utils.Version) error { +func (inst *PDInstance) Start(ctx context.Context) error { configPath := filepath.Join(inst.Dir, "pd.toml") if err := prepareConfig( configPath, @@ -156,10 +155,6 @@ func (inst *PDInstance) Start(ctx context.Context, version utils.Version) error } } - var err error - if inst.BinPath, err = tiupexec.PrepareBinary("pd", version, inst.BinPath); err != nil { - return err - } inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, nil, inst.Dir)} logIfErr(inst.Process.SetOutputFile(inst.LogFile())) diff --git a/components/playground/instance/pump.go b/components/playground/instance/pump.go index 0918fe3f97..e4ca34b9cd 100644 --- a/components/playground/instance/pump.go +++ b/components/playground/instance/pump.go @@ -21,7 +21,6 @@ import ( "strings" "time" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -89,7 +88,7 @@ func (p *Pump) Addr() string { } // Start implements Instance interface. -func (p *Pump) Start(ctx context.Context, version utils.Version) error { +func (p *Pump) Start(ctx context.Context) error { endpoints := pdEndpoints(p.pds, true) args := []string{ @@ -103,10 +102,6 @@ func (p *Pump) Start(ctx context.Context, version utils.Version) error { args = append(args, fmt.Sprintf("--config=%s", p.ConfigPath)) } - var err error - if p.BinPath, err = tiupexec.PrepareBinary("pump", version, p.BinPath); err != nil { - return err - } p.Process = &process{cmd: PrepareCommand(ctx, p.BinPath, args, nil, p.Dir)} logIfErr(p.Process.SetOutputFile(p.LogFile())) diff --git a/components/playground/instance/ticdc.go b/components/playground/instance/ticdc.go index 5c987b2c5a..b233e8622f 100644 --- a/components/playground/instance/ticdc.go +++ b/components/playground/instance/ticdc.go @@ -19,7 +19,6 @@ import ( "path/filepath" "strings" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" ) @@ -54,7 +53,7 @@ func NewTiCDC(binPath string, dir, host, configPath string, id int, port int, pd } // Start implements Instance interface. -func (c *TiCDC) Start(ctx context.Context, version utils.Version) error { +func (c *TiCDC) Start(ctx context.Context) error { endpoints := pdEndpoints(c.pds, true) args := []string{ @@ -64,7 +63,7 @@ func (c *TiCDC) Start(ctx context.Context, version utils.Version) error { fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), fmt.Sprintf("--log-file=%s", c.LogFile()), } - clusterVersion := string(version) + clusterVersion := string(c.Version) if tidbver.TiCDCSupportConfigFile(clusterVersion) { if c.ConfigPath != "" { args = append(args, fmt.Sprintf("--config=%s", c.ConfigPath)) @@ -76,10 +75,6 @@ func (c *TiCDC) Start(ctx context.Context, version utils.Version) error { } } - var err error - if c.BinPath, err = tiupexec.PrepareBinary("cdc", version, c.BinPath); err != nil { - return err - } c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)} logIfErr(c.Process.SetOutputFile(c.LogFile())) diff --git a/components/playground/instance/tidb.go b/components/playground/instance/tidb.go index 7a075de2ab..20b89e92a2 100644 --- a/components/playground/instance/tidb.go +++ b/components/playground/instance/tidb.go @@ -20,7 +20,6 @@ import ( "strconv" "strings" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -57,7 +56,7 @@ func NewTiDBInstance(binPath string, dir, host, configPath string, id, port int, } // Start calls set inst.cmd and Start -func (inst *TiDBInstance) Start(ctx context.Context, version utils.Version) error { +func (inst *TiDBInstance) Start(ctx context.Context) error { configPath := filepath.Join(inst.Dir, "tidb.toml") if err := prepareConfig( configPath, @@ -82,10 +81,6 @@ func (inst *TiDBInstance) Start(ctx context.Context, version utils.Version) erro args = append(args, "--enable-binlog=true") } - var err error - if inst.BinPath, err = tiupexec.PrepareBinary("tidb", version, inst.BinPath); err != nil { - return err - } inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, nil, inst.Dir)} logIfErr(inst.Process.SetOutputFile(inst.LogFile())) diff --git a/components/playground/instance/tiflash.go b/components/playground/instance/tiflash.go index 2d90be4278..995c7df3b1 100644 --- a/components/playground/instance/tiflash.go +++ b/components/playground/instance/tiflash.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/pingcap/errors" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" ) @@ -97,9 +96,9 @@ func (inst *TiFlashInstance) StatusAddrs() (addrs []string) { } // Start calls set inst.cmd and Start -func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) error { - if !tidbver.TiFlashPlaygroundNewStartMode(version.String()) { - return inst.startOld(ctx, version) +func (inst *TiFlashInstance) Start(ctx context.Context) error { + if !tidbver.TiFlashPlaygroundNewStartMode(inst.Version.String()) { + return inst.startOld(ctx, inst.Version) } proxyConfigPath := filepath.Join(inst.Dir, "tiflash_proxy.toml") @@ -152,9 +151,6 @@ func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) e } } - if inst.BinPath, err = tiupexec.PrepareBinary("tiflash", version, inst.BinPath); err != nil { - return err - } inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, nil, inst.Dir)} logIfErr(inst.Process.SetOutputFile(inst.LogFile())) diff --git a/components/playground/instance/tiflash_pre7.go b/components/playground/instance/tiflash_pre7.go index 02f59747c4..0d57ddf412 100644 --- a/components/playground/instance/tiflash_pre7.go +++ b/components/playground/instance/tiflash_pre7.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tiup/pkg/cluster/api" "github.com/pingcap/tiup/pkg/cluster/spec" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -92,10 +91,6 @@ func (inst *TiFlashInstance) startOld(ctx context.Context, version utils.Version return err } - if inst.BinPath, err = tiupexec.PrepareBinary("tiflash", version, inst.BinPath); err != nil { - return err - } - dirPath := filepath.Dir(inst.BinPath) clusterManagerPath := getFlashClusterPath(dirPath) if err = inst.checkConfigOld(wd, clusterManagerPath, version, tidbStatusAddrs, endpoints); err != nil { diff --git a/components/playground/instance/tikv.go b/components/playground/instance/tikv.go index 08dfe04ebe..f70ec1bd96 100644 --- a/components/playground/instance/tikv.go +++ b/components/playground/instance/tikv.go @@ -21,7 +21,6 @@ import ( "time" "github.com/pingcap/tiup/pkg/cluster/api" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -65,7 +64,7 @@ func (inst *TiKVInstance) Addr() string { } // Start calls set inst.cmd and Start -func (inst *TiKVInstance) Start(ctx context.Context, version utils.Version) error { +func (inst *TiKVInstance) Start(ctx context.Context) error { configPath := filepath.Join(inst.Dir, "tikv.toml") if err := prepareConfig( configPath, @@ -104,10 +103,6 @@ func (inst *TiKVInstance) Start(ctx context.Context, version utils.Version) erro } envs := []string{"MALLOC_CONF=prof:true,prof_active:false"} - var err error - if inst.BinPath, err = tiupexec.PrepareBinary("tikv", version, inst.BinPath); err != nil { - return err - } inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, envs, inst.Dir)} logIfErr(inst.Process.SetOutputFile(inst.LogFile())) diff --git a/components/playground/instance/tikv_cdc.go b/components/playground/instance/tikv_cdc.go index 5441acf5af..cbacb23b2e 100644 --- a/components/playground/instance/tikv_cdc.go +++ b/components/playground/instance/tikv_cdc.go @@ -19,7 +19,6 @@ import ( "path/filepath" "strings" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -50,7 +49,7 @@ func NewTiKVCDC(binPath string, dir, host, configPath string, id int, pds []*PDI } // Start implements Instance interface. -func (c *TiKVCDC) Start(ctx context.Context, version utils.Version) error { +func (c *TiKVCDC) Start(ctx context.Context) error { endpoints := pdEndpoints(c.pds, true) args := []string{ @@ -65,10 +64,6 @@ func (c *TiKVCDC) Start(ctx context.Context, version utils.Version) error { args = append(args, fmt.Sprintf("--config=%s", c.ConfigPath)) } - var err error - if c.BinPath, err = tiupexec.PrepareBinary("tikv-cdc", version, c.BinPath); err != nil { - return err - } c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)} logIfErr(c.Process.SetOutputFile(c.LogFile())) diff --git a/components/playground/instance/tiproxy.go b/components/playground/instance/tiproxy.go index 732670e716..c0ed180c90 100644 --- a/components/playground/instance/tiproxy.go +++ b/components/playground/instance/tiproxy.go @@ -24,7 +24,6 @@ import ( "github.com/BurntSushi/toml" "github.com/pingcap/tiup/pkg/cluster/spec" "github.com/pingcap/tiup/pkg/crypto" - tiupexec "github.com/pingcap/tiup/pkg/exec" "github.com/pingcap/tiup/pkg/utils" ) @@ -98,7 +97,7 @@ func (c *TiProxy) MetricAddr() (r MetricAddr) { } // Start implements Instance interface. -func (c *TiProxy) Start(ctx context.Context, version utils.Version) error { +func (c *TiProxy) Start(ctx context.Context) error { endpoints := pdEndpoints(c.pds, false) configPath := filepath.Join(c.Dir, "config", "proxy.toml") @@ -136,10 +135,6 @@ func (c *TiProxy) Start(ctx context.Context, version utils.Version) error { fmt.Sprintf("--config=%s", configPath), } - if c.BinPath, err = tiupexec.PrepareBinary("tiproxy", version, c.BinPath); err != nil { - return err - } - c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)} logIfErr(c.Process.SetOutputFile(c.LogFile())) diff --git a/components/playground/playground.go b/components/playground/playground.go index 712f34a0d8..9fa18b1cf4 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -454,13 +454,15 @@ func (p *Playground) startInstance(ctx context.Context, inst instance.Instance) if component == "tso" || component == "scheduling" { component = string(instance.PDRoleNormal) } - version, err = environment.GlobalEnv().V1Repository().ResolveComponentVersion(component, boundVersion) - if err != nil { + if version, err = environment.GlobalEnv().V1Repository().ResolveComponentVersion(component, boundVersion); err != nil { return err } - fmt.Printf("Start %s instance:%s\n", inst.Component(), version) - err = inst.Start(ctx, version) - if err != nil { + + if err := inst.PrepareBinary(component, version); err != nil { + return err + } + + if err = inst.Start(ctx); err != nil { return err } p.addWaitInstance(inst)