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

Add advertise-status-addr for tiflash proxy #676

Merged
merged 6 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/playground/instance/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (inst *TiFlashInstance) Start(ctx context.Context, version v0manifest.Versi

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

Expand Down Expand Up @@ -210,7 +210,7 @@ func (inst *TiFlashInstance) StoreAddr() string {
return fmt.Sprintf("%s:%d", advertiseHost(inst.Host), inst.ServicePort)
}

func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error {
func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string, version v0manifest.Version, tidbStatusAddrs, endpoints []string) error {
if inst.ConfigPath == "" {
inst.ConfigPath = path.Join(inst.Dir, "tiflash.toml")
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string, t
inst.Host, deployDir, clusterManagerPath, tidbStatusAddrs, endpoints); err != nil {
return errors.Trace(err)
}
if err := writeTiFlashProxyConfig(cf2, inst.Host, deployDir, inst.ServicePort, inst.ProxyPort, inst.ProxyStatusPort); err != nil {
if err := writeTiFlashProxyConfig(cf2, version, inst.Host, deployDir, inst.ServicePort, inst.ProxyPort, inst.ProxyStatusPort); err != nil {
return errors.Trace(err)
}

Expand Down
38 changes: 36 additions & 2 deletions components/playground/instance/tiflash_proxy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package instance
import (
"fmt"
"io"

"github.com/pingcap/tiup/pkg/repository/v0manifest"
"golang.org/x/mod/semver"
)

const tiflashProxyConfig = `
Expand Down Expand Up @@ -43,11 +46,42 @@ data-dir = "%[6]s"
max-open-files = 256
`

func writeTiFlashProxyConfig(w io.Writer, ip, deployDir string, servicePort, proxyPort, proxyStatusPort int) error {
const tiflashProxyConfigV405 = `
log-file = "%[1]s/tiflash_tikv.log"

[rocksdb]
wal-dir = ""
max-open-files = 256

[security]
ca-path = ""
cert-path = ""
key-path = ""

[server]
addr = "0.0.0.0:%[4]d"
advertise-addr = "%[2]s:%[4]d"
engine-addr = "%[2]s:%[3]d"
status-addr = "0.0.0.0:%[5]d"
birdstorm marked this conversation as resolved.
Show resolved Hide resolved
advertise-status-addr = "%[2]s:%[5]d"

[storage]
data-dir = "%[6]s"

[raftdb]
max-open-files = 256
`

func writeTiFlashProxyConfig(w io.Writer, version v0manifest.Version, ip, deployDir string, servicePort, proxyPort, proxyStatusPort int) error {
// TODO: support multi-dir
dataDir := fmt.Sprintf("%s/flash", deployDir)
logDir := fmt.Sprintf("%s/log", deployDir)
conf := fmt.Sprintf(tiflashProxyConfig, logDir, ip, servicePort, proxyPort, proxyStatusPort, dataDir)
var conf string
if semver.Compare("v4.0.5", version.String()) <= 0 {
conf = fmt.Sprintf(tiflashProxyConfigV405, logDir, ip, servicePort, proxyPort, proxyStatusPort, dataDir)
} else {
conf = fmt.Sprintf(tiflashProxyConfig, logDir, ip, servicePort, proxyPort, proxyStatusPort, dataDir)
}
_, err := w.Write([]byte(conf))
return err
}
29 changes: 26 additions & 3 deletions pkg/cluster/spec/tiflash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -241,12 +242,33 @@ server_configs:
}

// InitTiFlashLearnerConfig initializes TiFlash learner config file
func (i *TiFlashInstance) InitTiFlashLearnerConfig(cfg *scripts.TiFlashScript, src map[string]interface{}) (map[string]interface{}, error) {
func (i *TiFlashInstance) InitTiFlashLearnerConfig(cfg *scripts.TiFlashScript, clusterVersion string, src map[string]interface{}) (map[string]interface{}, error) {
topo := Specification{}
var err error

firstDataDir := strings.Split(cfg.DataDir, ",")[0]

err := yaml.Unmarshal([]byte(fmt.Sprintf(`
if semver.Compare("v4.0.5", clusterVersion) <= 0 {
birdstorm marked this conversation as resolved.
Show resolved Hide resolved
err = yaml.Unmarshal([]byte(fmt.Sprintf(`
server_configs:
tiflash-learner:
log-file: "%[1]s/tiflash_tikv.log"
server.engine-addr: "%[2]s:%[3]d"
server.addr: "0.0.0.0:%[4]d"
server.advertise-addr: "%[2]s:%[4]d"
server.status-addr: "0.0.0.0:%[5]d"
server.advertise-status-addr: "%[2]s:%[5]d"
storage.data-dir: "%[6]s/flash"
rocksdb.wal-dir: ""
security.ca-path: ""
security.cert-path: ""
security.key-path: ""
# Normally the number of TiFlash nodes is smaller than TiKV nodes, and we need more raft threads to match the write speed of TiKV.
raftstore.apply-pool-size: 4
raftstore.store-pool-size: 4
`, cfg.LogDir, cfg.IP, cfg.FlashServicePort, cfg.FlashProxyPort, cfg.FlashProxyStatusPort, firstDataDir)), &topo)
} else {
err = yaml.Unmarshal([]byte(fmt.Sprintf(`
server_configs:
tiflash-learner:
log-file: "%[1]s/tiflash_tikv.log"
Expand All @@ -263,6 +285,7 @@ server_configs:
raftstore.apply-pool-size: 4
raftstore.store-pool-size: 4
`, cfg.LogDir, cfg.IP, cfg.FlashServicePort, cfg.FlashProxyPort, cfg.FlashProxyStatusPort, firstDataDir)), &topo)
}

if err != nil {
return nil, err
Expand Down Expand Up @@ -323,7 +346,7 @@ func (i *TiFlashInstance) InitConfig(e executor.Executor, clusterName, clusterVe
return err
}

conf, err := i.InitTiFlashLearnerConfig(cfg, i.topo.ServerConfigs.TiFlashLearner)
conf, err := i.InitTiFlashLearnerConfig(cfg, clusterVersion, i.topo.ServerConfigs.TiFlashLearner)
if err != nil {
return err
}
Expand Down