Skip to content

Commit

Permalink
Merge pull request #2304 from xiang90/fix_discovery_validation
Browse files Browse the repository at this point in the history
etcdserver: validate discovery cluster
  • Loading branch information
xiang90 committed Feb 13, 2015
2 parents b59390c + cfa7ab6 commit f7998bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 14 additions & 0 deletions etcdserver/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ func (c *Cluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes) {
c.members[id].RaftAttributes = raftAttr
}

// Validate ensures that there is no identical urls in the cluster peer list
func (c *Cluster) Validate() error {
urlMap := make(map[string]bool)
for _, m := range c.Members() {
for _, url := range m.PeerURLs {
if urlMap[url] {
return fmt.Errorf("duplicate url %v in cluster config", url)
}
urlMap[url] = true
}
}
return nil
}

func membersFromStore(st store.Store) (map[types.ID]*Member, map[types.ID]bool) {
members := make(map[types.ID]*Member)
removed := make(map[types.ID]bool)
Expand Down
11 changes: 2 additions & 9 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ func (c *ServerConfig) VerifyBootstrapConfig() error {
return fmt.Errorf("initial cluster state unset and no wal or discovery URL found")
}

// No identical IPs in the cluster peer list
urlMap := make(map[string]bool)
for _, m := range c.Cluster.Members() {
for _, url := range m.PeerURLs {
if urlMap[url] {
return fmt.Errorf("duplicate url %v in cluster config", url)
}
urlMap[url] = true
}
if err := c.Cluster.Validate(); err != nil {
return err
}

// Advertised peer URLs must match those in the cluster peer list
Expand Down
3 changes: 3 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
if cfg.Cluster, err = NewClusterFromString(cfg.Cluster.token, s); err != nil {
return nil, err
}
if cfg.Cluster.Validate() != nil {
return nil, fmt.Errorf("bad discovery cluster: %v", err)
}
}
cfg.Cluster.SetStore(st)
cfg.PrintWithInitial()
Expand Down

0 comments on commit f7998bb

Please sign in to comment.