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

Fix: duplicated pd_servers.name in the topology before truly deploy #922

Merged
merged 4 commits into from
Nov 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,22 @@ func (s *Specification) validateTLSEnabled() error {
return nil
}

func (s *Specification) validatePDNames() error {
// check pdserver name
pdNames := set.NewStringSet()
for _, pd := range s.PDServers {
if pd.Name == "" {
continue
}

if pdNames.Exist(pd.Name) {
return errors.Errorf("component pd_servers.name is not supported duplicated, the name %s is duplicated", pd.Name)
}
pdNames.Insert(pd.Name)
}
return nil
}

// Validate validates the topology specification and produce error if the
// specification invalid (e.g: port conflicts or directory conflicts)
func (s *Specification) Validate() error {
Expand All @@ -817,6 +833,10 @@ func (s *Specification) Validate() error {
return err
}

if err := s.validatePDNames(); err != nil {
return err
}

return RelativePathDetect(s, isSkipField)
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/cluster/spec/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,31 @@ pd_servers:
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "directory conflict for '/test-1' between 'tiflash_servers:172.16.5.138.data_dir' and 'tiflash_servers:172.16.5.138.data_dir'")
}

func (s *metaSuiteTopo) TestPdServerWithSameName(c *C) {
topo := Specification{}
err := yaml.Unmarshal([]byte(`
pd_servers:
- host: 172.16.5.138
peer_port: 1234
name: name1
- host: 172.16.5.139
perr_port: 1234
name: name2
`), &topo)
c.Assert(err, IsNil)

topo = Specification{}
err = yaml.Unmarshal([]byte(`
pd_servers:
- host: 172.16.5.138
peer_port: 1234
name: name1
- host: 172.16.5.139
perr_port: 1234
name: name1
`), &topo)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "component pd_servers.name is not supported duplicated, the name name1 is duplicated")

}