From 35231065e315832ea6b8df80511e69b705821c08 Mon Sep 17 00:00:00 2001 From: hehechen Date: Wed, 15 Dec 2021 12:28:36 +0800 Subject: [PATCH] Remove the config 'runAsDaemon' from tiflash.toml (#1673) --- components/playground/instance/tiflash.go | 2 +- .../playground/instance/tiflash_config.go | 30 ++++++++++++++----- pkg/cluster/ansible/service_test.go | 3 -- pkg/cluster/spec/tiflash.go | 12 ++++++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/components/playground/instance/tiflash.go b/components/playground/instance/tiflash.go index 7691da4245..88a9ee13fb 100644 --- a/components/playground/instance/tiflash.go +++ b/components/playground/instance/tiflash.go @@ -240,7 +240,7 @@ func (inst *TiFlashInstance) checkConfig(deployDir, clusterManagerPath string, v return errors.Trace(err) } defer cf2.Close() - if err := writeTiFlashConfig(cf, inst.TCPPort, inst.Port, inst.ServicePort, inst.StatusPort, + if err := writeTiFlashConfig(cf, version, inst.TCPPort, inst.Port, inst.ServicePort, inst.StatusPort, inst.Host, deployDir, clusterManagerPath, tidbStatusAddrs, endpoints); err != nil { return errors.Trace(err) } diff --git a/components/playground/instance/tiflash_config.go b/components/playground/instance/tiflash_config.go index 0051a650a2..368feaed91 100644 --- a/components/playground/instance/tiflash_config.go +++ b/components/playground/instance/tiflash_config.go @@ -17,8 +17,18 @@ import ( "fmt" "io" "strings" + + "github.com/pingcap/tiup/pkg/utils" + "golang.org/x/mod/semver" ) +const tiflashDaemonConfig = ` + +[application] +runAsDaemon = true + +` + const tiflashConfig = ` default_profile = "default" display_name = "TiFlash" @@ -28,10 +38,7 @@ mark_cache_size = 5368709120 path = "%[5]s" tcp_port = %[3]d tmp_path = "%[6]s" - -[application] -runAsDaemon = true - +%[13]s [flash] service_addr = "%[10]s:%[8]d" tidb_status_addr = "%[11]s" @@ -90,14 +97,21 @@ quota = "default" ip = "::/0" ` -func writeTiFlashConfig(w io.Writer, tcpPort, httpPort, servicePort, metricsPort int, ip, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error { +func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, servicePort, metricsPort int, ip, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error { pdAddrs := strings.Join(endpoints, ",") dataDir := fmt.Sprintf("%s/data", deployDir) tmpDir := fmt.Sprintf("%s/tmp", deployDir) logDir := fmt.Sprintf("%s/log", deployDir) - conf := fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, - deployDir, dataDir, tmpDir, logDir, servicePort, metricsPort, - ip, strings.Join(tidbStatusAddrs, ","), clusterManagerPath) + var conf string + if semver.Compare(version.String(), "v5.4.0") >= 0 || version.IsNightly() { + conf = fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, + deployDir, dataDir, tmpDir, logDir, servicePort, metricsPort, + 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) + } _, err := w.Write([]byte(conf)) return err } diff --git a/pkg/cluster/ansible/service_test.go b/pkg/cluster/ansible/service_test.go index 39ea7a5f62..ffadc99877 100644 --- a/pkg/cluster/ansible/service_test.go +++ b/pkg/cluster/ansible/service_test.go @@ -28,9 +28,6 @@ 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" -[application] -runAsDaemon = true - [flash] service_addr = "172.16.5.85:11317" tidb_status_addr = "172.16.5.85:11310" diff --git a/pkg/cluster/spec/tiflash.go b/pkg/cluster/spec/tiflash.go index b61cc69a8b..7a2081c34a 100644 --- a/pkg/cluster/spec/tiflash.go +++ b/pkg/cluster/spec/tiflash.go @@ -375,6 +375,7 @@ func (i *TiFlashInstance) initTiFlashConfig(cfg *scripts.TiFlashScript, clusterV pathConfig string isStorageDirsDefined bool deprecatedUsersConfig string + daemonConfig string err error ) if isStorageDirsDefined, err = checkTiFlashStorageConfigWithVersion(clusterVersion, src); err != nil { @@ -438,6 +439,13 @@ func (i *TiFlashInstance) initTiFlashConfig(cfg *scripts.TiFlashScript, clusterV } topo := Specification{} + + if semver.Compare(clusterVersion, "v5.4.0") >= 0 || utils.Version(clusterVersion).IsNightly() { + // For 5.4.0 or later, TiFlash can ignore application.runAsDaemon setting + daemonConfig = "#" + } else { + daemonConfig = `application.runAsDaemon: true` + } err = yaml.Unmarshal([]byte(fmt.Sprintf(` server_configs: tiflash: @@ -463,12 +471,12 @@ server_configs: logger.count: 20 logger.level: "debug" logger.size: "1000M" - application.runAsDaemon: true + %[13]s raft.pd_addr: "%[9]s" profiles.default.max_memory_usage: 0 %[12]s `, pathConfig, cfg.LogDir, cfg.TCPPort, cfg.HTTPPort, cfg.TiDBStatusAddrs, cfg.IP, cfg.FlashServicePort, - cfg.StatusPort, cfg.PDAddrs, cfg.DeployDir, cfg.TmpDir, deprecatedUsersConfig)), &topo) + cfg.StatusPort, cfg.PDAddrs, cfg.DeployDir, cfg.TmpDir, deprecatedUsersConfig, daemonConfig)), &topo) if err != nil { return nil, err