Skip to content

Commit

Permalink
Fix duplicated pd_servers.name in the topology before truly deploy th…
Browse files Browse the repository at this point in the history
…e cluster(#764)
  • Loading branch information
anywhy committed Nov 21, 2020
1 parent d1c4866 commit 36ed94f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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")

}

0 comments on commit 36ed94f

Please sign in to comment.