Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playground: Run TiFlash via args #2162

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 51 additions & 4 deletions components/playground/instance/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"os/exec"
"path"
"path/filepath"
"strings"
"time"

"github.com/BurntSushi/toml"
"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/tidbver"
"github.com/pingcap/tiup/pkg/utils"
)

Expand Down Expand Up @@ -95,6 +97,51 @@ 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.TiFlashSupportRunWithoutConfig(version.String()) {
return inst.startViaArgs(ctx, version)
}
return inst.startViaConfig(ctx, version)
}

func (inst *TiFlashInstance) startViaArgs(ctx context.Context, version utils.Version) error {
endpoints := pdEndpoints(inst.pds, false)

args := []string{
"server",
}
if inst.ConfigPath != "" {
args = append(args, fmt.Sprintf("--config-file=%s", inst.ConfigPath))
}
args = append(args,
"--",
fmt.Sprintf("--tmp_path=%s", filepath.Join(inst.Dir, "tmp")),
fmt.Sprintf("--path=%s", filepath.Join(inst.Dir, "data")),
fmt.Sprintf("--http_port=%d", inst.Port),
fmt.Sprintf("--listen_host=%s", inst.Host),
fmt.Sprintf("--tcp_port=%d", inst.TCPPort),
fmt.Sprintf("--logger.log=%s", inst.LogFile()),
fmt.Sprintf("--logger.errorlog=%s", filepath.Join(inst.Dir, "tiflash_error.log")),
fmt.Sprintf("--status.metrics_port=%d", inst.StatusPort),
fmt.Sprintf("--flash.service_addr=%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ServicePort)),
fmt.Sprintf("--raft.pd_addr=%s", strings.Join(endpoints, ",")),
fmt.Sprintf("--flash.proxy.addr=%s", utils.JoinHostPort(inst.Host, inst.ProxyPort)),
fmt.Sprintf("--flash.proxy.advertise-addr=%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ProxyPort)),
fmt.Sprintf("--flash.proxy.status-addr=%s", utils.JoinHostPort(inst.Host, inst.ProxyStatusPort)),
fmt.Sprintf("--flash.proxy.data-dir=%s", filepath.Join(inst.Dir, "proxy_data")),
fmt.Sprintf("--flash.proxy.log-file=%s", filepath.Join(inst.Dir, "tiflash_tikv.log")),
)

var err error
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()))
return inst.Process.Start()
}

func (inst *TiFlashInstance) startViaConfig(ctx context.Context, version utils.Version) error {
endpoints := pdEndpoints(inst.pds, false)

tidbStatusAddrs := make([]string, 0, len(inst.dbs))
Expand Down Expand Up @@ -145,7 +192,7 @@ func (inst *TiFlashInstance) Start(ctx context.Context, version utils.Version) e

dirPath := filepath.Dir(inst.BinPath)
clusterManagerPath := getFlashClusterPath(dirPath)
if err = inst.checkConfig(wd, clusterManagerPath, version, tidbStatusAddrs, endpoints); err != nil {
if err = inst.checkConfigForStartViaConfig(wd, clusterManagerPath, version, tidbStatusAddrs, endpoints); err != nil {
return err
}

Expand Down Expand Up @@ -182,7 +229,7 @@ func (inst *TiFlashInstance) StoreAddr() string {
return utils.JoinHostPort(AdvertiseHost(inst.Host), inst.ServicePort)
}

func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string,
func (inst *TiFlashInstance) checkConfigForStartViaConfig(deployDir, clusterManagerPath string,
version utils.Version, tidbStatusAddrs, endpoints []string) (err error) {
if err := utils.MkdirAll(inst.Dir, 0755); err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -212,11 +259,11 @@ func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string,
}()

// Write default config to buffer
if err := writeTiFlashConfig(flashBuf, version, inst.TCPPort, inst.Port, inst.ServicePort, inst.StatusPort,
if err := writeTiFlashConfigForStartViaConfig(flashBuf, version, inst.TCPPort, inst.Port, inst.ServicePort, inst.StatusPort,
inst.Host, deployDir, clusterManagerPath, tidbStatusAddrs, endpoints); err != nil {
return errors.Trace(err)
}
if err := writeTiFlashProxyConfig(proxyBuf, version, inst.Host, deployDir,
if err := writeTiFlashProxyConfigForStartViaConfig(proxyBuf, version, inst.Host, deployDir,
inst.ServicePort, inst.ProxyPort, inst.ProxyStatusPort); err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion components/playground/instance/tiflash_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ quota = "default"
ip = "::/0"
`

func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, servicePort, metricsPort int, host, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error {
func writeTiFlashConfigForStartViaConfig(w io.Writer, version utils.Version, tcpPort, httpPort, servicePort, metricsPort int, host, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error {
pdAddrs := strings.Join(endpoints, ",")
dataDir := fmt.Sprintf("%s/data", deployDir)
tmpDir := fmt.Sprintf("%s/tmp", deployDir)
Expand Down
2 changes: 1 addition & 1 deletion components/playground/instance/tiflash_proxy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data-dir = "%[6]s"
max-open-files = 256
`

func writeTiFlashProxyConfig(w io.Writer, version utils.Version, host, deployDir string, servicePort, proxyPort, proxyStatusPort int) error {
func writeTiFlashProxyConfigForStartViaConfig(w io.Writer, version utils.Version, host, deployDir string, servicePort, proxyPort, proxyStatusPort int) error {
// TODO: support multi-dir
dataDir := fmt.Sprintf("%s/flash", deployDir)
logDir := fmt.Sprintf("%s/log", deployDir)
Expand Down
2 changes: 1 addition & 1 deletion components/playground/instance/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (inst *TiKVInstance) Start(ctx context.Context, version utils.Version) erro
fmt.Sprintf("--addr=%s", utils.JoinHostPort(inst.Host, inst.Port)),
fmt.Sprintf("--advertise-addr=%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.Port)),
fmt.Sprintf("--status-addr=%s", utils.JoinHostPort(inst.Host, inst.StatusPort)),
fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")),
fmt.Sprintf("--pd-endpoints=%s", strings.Join(endpoints, ",")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it compatible with older version of tikv

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I've checked with at least TiKV v4.0 and it is fine.

fmt.Sprintf("--config=%s", inst.ConfigPath),
fmt.Sprintf("--data-dir=%s", filepath.Join(inst.Dir, "data")),
fmt.Sprintf("--log-file=%s", inst.LogFile()),
Expand Down
6 changes: 6 additions & 0 deletions pkg/tidbver/tidbver.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func TiFlashNotNeedSomeConfig(version string) bool {
return semver.Compare(version, "v5.4.0") >= 0 || strings.Contains(version, "nightly")
}

// TiFlashSupportRunWithoutConfig return true if the given version of TiFlash could be started without
// a config file.
func TiFlashSupportRunWithoutConfig(version string) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! Do you plan to add this function to to tiup-cluster?

Copy link
Member Author

@breezewish breezewish Apr 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I don't have plans, because there seems to be no functional difference to users. Additionally, TiFlash's support to pure cli args is not battle-tested yet. If there are benefits then I think its worth to do, in future versions!

return semver.Compare(version, "v7.1.0") >= 0 || strings.Contains(version, "nightly")
}

// TiCDCSupportConfigFile return if given version of TiCDC support config file
func TiCDCSupportConfigFile(version string) bool {
// config support since v4.0.13, ignore v5.0.0-rc
Expand Down