diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index e0191cb5a4..179dc564ff 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -88,6 +88,15 @@ func (inst *PDInstance) Name() string { // Start calls set inst.cmd and Start func (inst *PDInstance) Start(ctx context.Context) error { + configPath := filepath.Join(inst.Dir, "pd.toml") + if err := prepareConfig( + configPath, + inst.ConfigPath, + inst.getConfig(), + ); err != nil { + return err + } + uid := inst.Name() var args []string switch inst.Role { @@ -97,6 +106,7 @@ func (inst *PDInstance) Start(ctx context.Context) error { } args = append(args, []string{ "--name=" + uid, + fmt.Sprintf("--config=%s", configPath), fmt.Sprintf("--data-dir=%s", filepath.Join(inst.Dir, "data")), fmt.Sprintf("--peer-urls=http://%s", utils.JoinHostPort(inst.Host, inst.Port)), fmt.Sprintf("--advertise-peer-urls=http://%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.Port)), @@ -104,9 +114,7 @@ func (inst *PDInstance) Start(ctx context.Context) error { fmt.Sprintf("--advertise-client-urls=http://%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.StatusPort)), fmt.Sprintf("--log-file=%s", inst.LogFile()), }...) - if inst.ConfigPath != "" { - args = append(args, fmt.Sprintf("--config=%s", inst.ConfigPath)) - } + switch { case len(inst.initEndpoints) > 0: endpoints := make([]string, 0) diff --git a/components/playground/instance/pd_config.go b/components/playground/instance/pd_config.go new file mode 100644 index 0000000000..3ef80b6f4d --- /dev/null +++ b/components/playground/instance/pd_config.go @@ -0,0 +1,20 @@ +// Copyright 2024 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package instance + +func (inst *PDInstance) getConfig() map[string]any { + config := make(map[string]any) + config["schedule.patrol-region-interval"] = "100ms" + return config +} diff --git a/components/playground/main.go b/components/playground/main.go index 8215362fed..713f6c8e33 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -414,17 +414,17 @@ func populateDefaultOpt(flagSet *pflag.FlagSet) error { defaultInt(&options.PD.Num, "pd", 1) case "ms": defaultInt(&options.PDAPI.Num, "pd.api", 1) - defaultStr(&options.PDAPI.BinPath, "pd.api.binpath", options.PDAPI.BinPath) - defaultStr(&options.PDAPI.ConfigPath, "pd.api.config", options.PDAPI.ConfigPath) + defaultStr(&options.PDAPI.BinPath, "pd.api.binpath", options.PD.BinPath) + defaultStr(&options.PDAPI.ConfigPath, "pd.api.config", options.PD.ConfigPath) defaultInt(&options.PDTSO.Num, "pd.tso", 1) - defaultStr(&options.PDTSO.BinPath, "pd.tso.binpath", options.PDTSO.BinPath) - defaultStr(&options.PDTSO.ConfigPath, "pd.tso.config", options.PDTSO.ConfigPath) + defaultStr(&options.PDTSO.BinPath, "pd.tso.binpath", options.PD.BinPath) + defaultStr(&options.PDTSO.ConfigPath, "pd.tso.config", options.PD.ConfigPath) defaultInt(&options.PDScheduling.Num, "pd.scheduling", 1) - defaultStr(&options.PDScheduling.BinPath, "pd.scheduling.binpath", options.PDScheduling.BinPath) - defaultStr(&options.PDScheduling.ConfigPath, "pd.scheduling.config", options.PDScheduling.ConfigPath) + defaultStr(&options.PDScheduling.BinPath, "pd.scheduling.binpath", options.PD.BinPath) + defaultStr(&options.PDScheduling.ConfigPath, "pd.scheduling.config", options.PD.ConfigPath) defaultInt(&options.PDRM.Num, "pd.rm", 1) - defaultStr(&options.PDRM.BinPath, "pd.rm.binpath", options.PDRM.BinPath) - defaultStr(&options.PDRM.ConfigPath, "pd.rm.config", options.PDRM.ConfigPath) + defaultStr(&options.PDRM.BinPath, "pd.rm.binpath", options.PD.BinPath) + defaultStr(&options.PDRM.ConfigPath, "pd.rm.config", options.PD.ConfigPath) default: return errors.Errorf("Unknown --pd.mode %s", options.PDMode) }