Skip to content

Commit

Permalink
playground: print version when filling binpath (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuSharp authored Jul 15, 2024
1 parent 636d9e0 commit 654b087
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 67 deletions.
7 changes: 1 addition & 6 deletions components/playground/instance/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"path/filepath"
"strings"

tiupexec "github.com/pingcap/tiup/pkg/exec"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -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{
Expand All @@ -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()))
Expand Down
22 changes: 21 additions & 1 deletion components/playground/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"

"github.com/pingcap/errors"
tiupexec "github.com/pingcap/tiup/pkg/exec"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()))
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"
"time"

tiupexec "github.com/pingcap/tiup/pkg/exec"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -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{
Expand All @@ -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()))
Expand Down
9 changes: 2 additions & 7 deletions components/playground/instance/ticdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand All @@ -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))
Expand All @@ -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()))
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strconv"
"strings"

tiupexec "github.com/pingcap/tiup/pkg/exec"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -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,
Expand All @@ -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()))
Expand Down
10 changes: 3 additions & 7 deletions components/playground/instance/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()))
Expand Down
5 changes: 0 additions & 5 deletions components/playground/instance/tiflash_pre7.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()))
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/tikv_cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"path/filepath"
"strings"

tiupexec "github.com/pingcap/tiup/pkg/exec"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -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{
Expand All @@ -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()))
Expand Down
7 changes: 1 addition & 6 deletions components/playground/instance/tiproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()))
Expand Down
12 changes: 7 additions & 5 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 654b087

Please sign in to comment.