From 61c9724efc10e598a874ae2afd5fe150eed2afef Mon Sep 17 00:00:00 2001 From: kaaaaaaang Date: Tue, 30 Jul 2024 16:09:50 +0800 Subject: [PATCH] Revert "pdms(playground, cluster): add name to start pdms (#2438)" (#2446) This reverts commit 9c5ad9aaaaec76e6abd896cd175df862ef964ccc. --- components/playground/instance/pd.go | 16 +--- embed/templates/scripts/run_scheduling.sh.tpl | 3 - embed/templates/scripts/run_tso.sh.tpl | 3 - pkg/cluster/manager/manager_test.go | 15 ---- pkg/cluster/manager/transfer_test.go | 28 ------- pkg/cluster/spec/scheduling.go | 38 ++++----- pkg/cluster/spec/spec.go | 10 --- pkg/cluster/spec/tso.go | 38 ++++----- pkg/cluster/spec/validate.go | 34 -------- pkg/cluster/template/scripts/pdms_test.go | 80 ------------------- pkg/cluster/template/scripts/scheduling.go | 1 - pkg/cluster/template/scripts/tso.go | 1 - pkg/tidbver/tidbver.go | 5 -- 13 files changed, 33 insertions(+), 239 deletions(-) delete mode 100644 pkg/cluster/template/scripts/pdms_test.go diff --git a/components/playground/instance/pd.go b/components/playground/instance/pd.go index 67b2e53ed2..3c1d6f8636 100644 --- a/components/playground/instance/pd.go +++ b/components/playground/instance/pd.go @@ -20,7 +20,6 @@ import ( "strings" "github.com/pingcap/errors" - "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" ) @@ -84,14 +83,7 @@ func (inst *PDInstance) InitCluster(pds []*PDInstance) *PDInstance { // Name return the name of pd. func (inst *PDInstance) Name() string { - switch inst.Role { - case PDRoleTSO: - return fmt.Sprintf("tso-%d", inst.ID) - case PDRoleScheduling: - return fmt.Sprintf("scheduling-%d", inst.ID) - default: - return fmt.Sprintf("pd-%d", inst.ID) - } + return fmt.Sprintf("pd-%d", inst.ID) } // Start calls set inst.cmd and Start @@ -150,9 +142,6 @@ func (inst *PDInstance) Start(ctx context.Context) error { fmt.Sprintf("--log-file=%s", inst.LogFile()), fmt.Sprintf("--config=%s", configPath), } - if tidbver.PDSupportMicroServicesWithName(inst.Version.String()) { - args = append(args, fmt.Sprintf("--name=%s", uid)) - } case PDRoleScheduling: endpoints := pdEndpoints(inst.pds, true) args = []string{ @@ -164,9 +153,6 @@ func (inst *PDInstance) Start(ctx context.Context) error { fmt.Sprintf("--log-file=%s", inst.LogFile()), fmt.Sprintf("--config=%s", configPath), } - if tidbver.PDSupportMicroServicesWithName(inst.Version.String()) { - args = append(args, fmt.Sprintf("--name=%s", uid)) - } } inst.Process = &process{cmd: PrepareCommand(ctx, inst.BinPath, args, nil, inst.Dir)} diff --git a/embed/templates/scripts/run_scheduling.sh.tpl b/embed/templates/scripts/run_scheduling.sh.tpl index 2ba72fed0f..a15b1ba4f7 100644 --- a/embed/templates/scripts/run_scheduling.sh.tpl +++ b/embed/templates/scripts/run_scheduling.sh.tpl @@ -11,9 +11,6 @@ cd "${DEPLOY_DIR}" || exit 1 exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=madvdontneed=1 bin/pd-server services scheduling\ {{- else}} exec env GODEBUG=madvdontneed=1 bin/pd-server services scheduling \ -{{- end}} -{{- if .Name}} - --name="{{.Name}}" \ {{- end}} --backend-endpoints="{{.BackendEndpoints}}" \ --listen-addr="{{.ListenURL}}" \ diff --git a/embed/templates/scripts/run_tso.sh.tpl b/embed/templates/scripts/run_tso.sh.tpl index 177b676aff..0d6486d73e 100644 --- a/embed/templates/scripts/run_tso.sh.tpl +++ b/embed/templates/scripts/run_tso.sh.tpl @@ -11,9 +11,6 @@ cd "${DEPLOY_DIR}" || exit 1 exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=madvdontneed=1 bin/pd-server services tso\ {{- else}} exec env GODEBUG=madvdontneed=1 bin/pd-server services tso \ -{{- end}} -{{- if .Name}} - --name="{{.Name}}" \ {{- end}} --backend-endpoints="{{.BackendEndpoints}}" \ --listen-addr="{{.ListenURL}}" \ diff --git a/pkg/cluster/manager/manager_test.go b/pkg/cluster/manager/manager_test.go index b82b6eb785..e80d1d1c64 100644 --- a/pkg/cluster/manager/manager_test.go +++ b/pkg/cluster/manager/manager_test.go @@ -85,21 +85,6 @@ pd_servers: assert.Nil(err) err = validateNewTopo(&topo) assert.NotNil(err) - - topo = spec.Specification{} - err = yaml.Unmarshal([]byte(` -global: - user: "test4" - deploy_dir: "test-deploy" - data_dir: "test-data" -tso_servers: - - host: 172.16.5.53 -scheduling_servers: - - host: 172.16.5.54 -`), &topo) - assert.Nil(err) - err = validateNewTopo(&topo) - assert.Nil(err) } func TestDeduplicateCheckResult(t *testing.T) { diff --git a/pkg/cluster/manager/transfer_test.go b/pkg/cluster/manager/transfer_test.go index d4b4581f6a..bef179dd0b 100644 --- a/pkg/cluster/manager/transfer_test.go +++ b/pkg/cluster/manager/transfer_test.go @@ -53,32 +53,4 @@ func TestRenderSpec(t *testing.T) { dir, err = renderSpec("{{.DataDir}}", s, "test-pd") assert.Nil(t, err) assert.NotEmpty(t, dir) - - s = &spec.TSOInstance{BaseInstance: spec.BaseInstance{ - InstanceSpec: &spec.TSOSpec{ - Host: "172.16.5.140", - SSHPort: 22, - Name: "tso-1", - DeployDir: "/home/test/deploy/tso-3379", - DataDir: "/home/test/deploy/tso-3379/data", - }, - }} - // s.BaseInstance.InstanceSpec - dir, err = renderSpec("{{.DataDir}}", s, "test-tso") - assert.Nil(t, err) - assert.NotEmpty(t, dir) - - s = &spec.SchedulingInstance{BaseInstance: spec.BaseInstance{ - InstanceSpec: &spec.SchedulingSpec{ - Host: "172.16.5.140", - SSHPort: 22, - Name: "scheduling-1", - DeployDir: "/home/test/deploy/scheduling-3379", - DataDir: "/home/test/deploy/scheduling-3379/data", - }, - }} - // s.BaseInstance.InstanceSpec - dir, err = renderSpec("{{.DataDir}}", s, "test-scheduling") - assert.Nil(t, err) - assert.NotEmpty(t, dir) } diff --git a/pkg/cluster/spec/scheduling.go b/pkg/cluster/spec/scheduling.go index 3da3975f2d..efbe7def00 100644 --- a/pkg/cluster/spec/scheduling.go +++ b/pkg/cluster/spec/scheduling.go @@ -25,29 +25,26 @@ import ( "github.com/pingcap/tiup/pkg/cluster/ctxt" "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" - "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" ) // SchedulingSpec represents the scheduling topology specification in topology.yaml type SchedulingSpec struct { - Host string `yaml:"host"` - ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"` - ListenHost string `yaml:"listen_host,omitempty"` - AdvertiseListenAddr string `yaml:"advertise_listen_addr,omitempty"` - SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` - IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` - // Use Name to get the name with a default value if it's empty. - Name string `yaml:"name,omitempty"` - Port int `yaml:"port" default:"3379"` - DeployDir string `yaml:"deploy_dir,omitempty"` - DataDir string `yaml:"data_dir,omitempty"` - LogDir string `yaml:"log_dir,omitempty"` - Source string `yaml:"source,omitempty" validate:"source:editable"` - NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` - Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"` - Arch string `yaml:"arch,omitempty"` - OS string `yaml:"os,omitempty"` + Host string `yaml:"host"` + ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"` + ListenHost string `yaml:"listen_host,omitempty"` + AdvertiseListenAddr string `yaml:"advertise_listen_addr,omitempty"` + SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` + IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` + Port int `yaml:"port" default:"3379"` + DeployDir string `yaml:"deploy_dir,omitempty"` + DataDir string `yaml:"data_dir,omitempty"` + LogDir string `yaml:"log_dir,omitempty"` + Source string `yaml:"source,omitempty" validate:"source:editable"` + NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` + Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"` + Arch string `yaml:"arch,omitempty"` + OS string `yaml:"os,omitempty"` } // Status queries current status of the instance @@ -203,6 +200,7 @@ func (c *SchedulingComponent) Instances() []Instance { // SchedulingInstance represent the scheduling instance type SchedulingInstance struct { + Name string BaseInstance topo Topology } @@ -231,7 +229,6 @@ func (i *SchedulingInstance) InitConfig( pds = append(pds, pdspec.GetAdvertiseClientURL(enableTLS)) } cfg := &scripts.SchedulingScript{ - Name: spec.Name, ListenURL: fmt.Sprintf("%s://%s", scheme, utils.JoinHostPort(i.GetListenHost(), spec.Port)), AdvertiseListenURL: spec.GetAdvertiseListenURL(enableTLS), BackendEndpoints: strings.Join(pds, ","), @@ -240,9 +237,6 @@ func (i *SchedulingInstance) InitConfig( LogDir: paths.Log, NumaNode: spec.NumaNode, } - if !tidbver.PDSupportMicroServicesWithName(version) { - cfg.Name = "" - } fp := filepath.Join(paths.Cache, fmt.Sprintf("run_scheduling_%s_%d.sh", i.GetHost(), i.GetPort())) if err := cfg.ConfigToFile(fp); err != nil { diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 99bd0e87dd..ffef492dda 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -679,20 +679,10 @@ func setCustomDefaults(globalOptions *GlobalOptions, field reflect.Value) error } field.Field(j).Set(reflect.ValueOf(globalOptions.SSHPort)) case "Name": - // Only PD related components have `Name` field, if field.Field(j).String() != "" { continue } host := reflect.Indirect(field).FieldByName("Host").String() - // `TSO` and `Scheduling` components use `Port` filed - if reflect.Indirect(field).FieldByName("Port").IsValid() { - port := reflect.Indirect(field).FieldByName("Port").Int() - // field.String() is - role := strings.Split(strings.Split(field.Type().String(), ".")[1], "Spec")[0] - component := strings.ToLower(role) - field.Field(j).Set(reflect.ValueOf(fmt.Sprintf("%s-%s-%d", component, host, port))) - continue - } clientPort := reflect.Indirect(field).FieldByName("ClientPort").Int() field.Field(j).Set(reflect.ValueOf(fmt.Sprintf("pd-%s-%d", host, clientPort))) case "DataDir": diff --git a/pkg/cluster/spec/tso.go b/pkg/cluster/spec/tso.go index e309f1d652..a84069f6ee 100644 --- a/pkg/cluster/spec/tso.go +++ b/pkg/cluster/spec/tso.go @@ -25,29 +25,26 @@ import ( "github.com/pingcap/tiup/pkg/cluster/ctxt" "github.com/pingcap/tiup/pkg/cluster/template/scripts" "github.com/pingcap/tiup/pkg/meta" - "github.com/pingcap/tiup/pkg/tidbver" "github.com/pingcap/tiup/pkg/utils" ) // TSOSpec represents the TSO topology specification in topology.yaml type TSOSpec struct { - Host string `yaml:"host"` - ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"` - ListenHost string `yaml:"listen_host,omitempty"` - AdvertiseListenAddr string `yaml:"advertise_listen_addr,omitempty"` - SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` - IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` - // Use Name to get the name with a default value if it's empty. - Name string `yaml:"name,omitempty"` - Port int `yaml:"port" default:"3379"` - DeployDir string `yaml:"deploy_dir,omitempty"` - DataDir string `yaml:"data_dir,omitempty"` - LogDir string `yaml:"log_dir,omitempty"` - Source string `yaml:"source,omitempty" validate:"source:editable"` - NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` - Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"` - Arch string `yaml:"arch,omitempty"` - OS string `yaml:"os,omitempty"` + Host string `yaml:"host"` + ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"` + ListenHost string `yaml:"listen_host,omitempty"` + AdvertiseListenAddr string `yaml:"advertise_listen_addr,omitempty"` + SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` + IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` + Port int `yaml:"port" default:"3379"` + DeployDir string `yaml:"deploy_dir,omitempty"` + DataDir string `yaml:"data_dir,omitempty"` + LogDir string `yaml:"log_dir,omitempty"` + Source string `yaml:"source,omitempty" validate:"source:editable"` + NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` + Config map[string]any `yaml:"config,omitempty" validate:"config:ignore"` + Arch string `yaml:"arch,omitempty"` + OS string `yaml:"os,omitempty"` } // Status queries current status of the instance @@ -203,6 +200,7 @@ func (c *TSOComponent) Instances() []Instance { // TSOInstance represent the TSO instance type TSOInstance struct { + Name string BaseInstance topo Topology } @@ -231,7 +229,6 @@ func (i *TSOInstance) InitConfig( pds = append(pds, pdspec.GetAdvertiseClientURL(enableTLS)) } cfg := &scripts.TSOScript{ - Name: spec.Name, ListenURL: fmt.Sprintf("%s://%s", scheme, utils.JoinHostPort(i.GetListenHost(), spec.Port)), AdvertiseListenURL: spec.GetAdvertiseListenURL(enableTLS), BackendEndpoints: strings.Join(pds, ","), @@ -240,9 +237,6 @@ func (i *TSOInstance) InitConfig( LogDir: paths.Log, NumaNode: spec.NumaNode, } - if !tidbver.PDSupportMicroServicesWithName(version) { - cfg.Name = "" - } fp := filepath.Join(paths.Cache, fmt.Sprintf("run_tso_%s_%d.sh", i.GetHost(), i.GetPort())) if err := cfg.ConfigToFile(fp); err != nil { diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index ce73682c01..99384cbec7 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -984,38 +984,6 @@ func (s *Specification) validatePDNames() error { return nil } -func (s *Specification) validateTSONames() error { - // check tso server name - tsoNames := set.NewStringSet() - for _, tso := range s.TSOServers { - if tso.Name == "" { - continue - } - - if tsoNames.Exist(tso.Name) { - return errors.Errorf("component tso_servers.name is not supported duplicated, the name %s is duplicated", tso.Name) - } - tsoNames.Insert(tso.Name) - } - return nil -} - -func (s *Specification) validateSchedulingNames() error { - // check scheduling server name - schedulingNames := set.NewStringSet() - for _, scheduling := range s.SchedulingServers { - if scheduling.Name == "" { - continue - } - - if schedulingNames.Exist(scheduling.Name) { - return errors.Errorf("component scheduling_servers.name is not supported duplicated, the name %s is duplicated", scheduling.Name) - } - schedulingNames.Insert(scheduling.Name) - } - return nil -} - func (s *Specification) validateTiFlashConfigs() error { c := FindComponent(s, ComponentTiFlash) for _, ins := range c.Instances() { @@ -1095,8 +1063,6 @@ func (s *Specification) Validate() error { s.dirConflictsDetect, s.validateUserGroup, s.validatePDNames, - s.validateTSONames, - s.validateSchedulingNames, s.validateTiSparkSpec, s.validateTiFlashConfigs, s.validateMonitorAgent, diff --git a/pkg/cluster/template/scripts/pdms_test.go b/pkg/cluster/template/scripts/pdms_test.go deleted file mode 100644 index 414f693f1f..0000000000 --- a/pkg/cluster/template/scripts/pdms_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// 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 scripts - -import ( - "os" - "strings" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestScheduling(t *testing.T) { - assert := require.New(t) - conf, err := os.CreateTemp("", "scheduling.conf") - assert.Nil(err) - defer os.Remove(conf.Name()) - - cfg := &SchedulingScript{ - Name: "scheduling-0", - ListenURL: "127.0.0.1", - AdvertiseListenURL: "127.0.0.2", - BackendEndpoints: "127.0.0.3", - DeployDir: "/deploy", - DataDir: "/data", - LogDir: "/log", - } - err = cfg.ConfigToFile(conf.Name()) - assert.Nil(err) - content, err := os.ReadFile(conf.Name()) - assert.Nil(err) - assert.True(strings.Contains(string(content), "--name")) - - cfg.Name = "" - err = cfg.ConfigToFile(conf.Name()) - assert.Nil(err) - content, err = os.ReadFile(conf.Name()) - assert.Nil(err) - assert.False(strings.Contains(string(content), "--name")) -} - -func TestTSO(t *testing.T) { - assert := require.New(t) - conf, err := os.CreateTemp("", "tso.conf") - assert.Nil(err) - defer os.Remove(conf.Name()) - - cfg := &TSOScript{ - Name: "tso-0", - ListenURL: "127.0.0.1", - AdvertiseListenURL: "127.0.0.2", - BackendEndpoints: "127.0.0.3", - DeployDir: "/deploy", - DataDir: "/data", - LogDir: "/log", - } - err = cfg.ConfigToFile(conf.Name()) - assert.Nil(err) - content, err := os.ReadFile(conf.Name()) - assert.Nil(err) - assert.True(strings.Contains(string(content), "--name")) - - cfg.Name = "" - err = cfg.ConfigToFile(conf.Name()) - assert.Nil(err) - content, err = os.ReadFile(conf.Name()) - assert.Nil(err) - assert.False(strings.Contains(string(content), "--name")) -} diff --git a/pkg/cluster/template/scripts/scheduling.go b/pkg/cluster/template/scripts/scheduling.go index 76142485a2..6167d9336e 100644 --- a/pkg/cluster/template/scripts/scheduling.go +++ b/pkg/cluster/template/scripts/scheduling.go @@ -24,7 +24,6 @@ import ( // SchedulingScript represent the data to generate scheduling config type SchedulingScript struct { - Name string ListenURL string AdvertiseListenURL string BackendEndpoints string diff --git a/pkg/cluster/template/scripts/tso.go b/pkg/cluster/template/scripts/tso.go index 91c3bfe1d0..0197b82c38 100644 --- a/pkg/cluster/template/scripts/tso.go +++ b/pkg/cluster/template/scripts/tso.go @@ -24,7 +24,6 @@ import ( // TSOScript represent the data to generate tso config type TSOScript struct { - Name string ListenURL string AdvertiseListenURL string BackendEndpoints string diff --git a/pkg/tidbver/tidbver.go b/pkg/tidbver/tidbver.go index c811510cfc..c659304a85 100644 --- a/pkg/tidbver/tidbver.go +++ b/pkg/tidbver/tidbver.go @@ -104,11 +104,6 @@ func PDSupportMicroServices(version string) bool { return semver.Compare(version, "v7.3.0") >= 0 || strings.Contains(version, "nightly") } -// PDSupportMicroServicesWithName return if the given version of PD supports micro services with name. -func PDSupportMicroServicesWithName(version string) bool { - return semver.Compare(version, "v8.3.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