Skip to content

Commit

Permalink
etcdserver: better warning when initial-cluster doesn't match adverti…
Browse files Browse the repository at this point in the history
…se urls

The old error was not clear about what URLs needed to be added, sometimes
truncating the list. To make it clearer, print out the missing entries
for --initial-cluster and print the full list of initial advertise peers.

Fixes etcd-io#8079 and etcd-io#7927
  • Loading branch information
heyitsanthony authored and Iwasaki Yudai committed Oct 5, 2017
1 parent 5f80e86 commit 5708f6f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
38 changes: 34 additions & 4 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,41 @@ func (c *ServerConfig) advertiseMatchesCluster() error {
sort.Strings(apurls)
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()
if !netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) {
umap := map[string]types.URLs{c.Name: c.PeerURLs}
return fmt.Errorf("--initial-cluster must include %s given --initial-advertise-peer-urls=%s", types.URLsMap(umap).String(), strings.Join(apurls, ","))
if netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) {
return nil
}
return nil

initMap, apMap := make(map[string]struct{}), make(map[string]struct{})
for _, url := range c.PeerURLs {
apMap[url.String()] = struct{}{}
}
for _, url := range c.InitialPeerURLsMap[c.Name] {
initMap[url.String()] = struct{}{}
}

missing := []string{}
for url := range initMap {
if _, ok := apMap[url]; !ok {
missing = append(missing, url)
}
}
if len(missing) > 0 {
for i := range missing {
missing[i] = c.Name + "=" + missing[i]
}
mstr := strings.Join(missing, ",")
apStr := strings.Join(apurls, ",")
return fmt.Errorf("--initial-cluster has %s but missing from --initial-advertise-peer-urls=%s ", mstr, apStr)
}

for url := range apMap {
if _, ok := initMap[url]; !ok {
missing = append(missing, url)
}
}
mstr := strings.Join(missing, ",")
umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs})
return fmt.Errorf("--initial-advertise-peer-urls has %s but missing from --initial-cluster=%s", mstr, umap.String())
}

func (c *ServerConfig) MemberDir() string { return filepath.Join(c.DataDir, "member") }
Expand Down
8 changes: 8 additions & 0 deletions etcdserver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ func TestConfigVerifyLocalMember(t *testing.T) {

true,
},
{
// Advertised peer URLs must match those in cluster-state
"node1=http://localhost:12345",
[]string{"http://localhost:2380", "http://localhost:12345"},
true,

true,
},
{
// Advertised peer URLs must match those in cluster-state
"node1=http://localhost:2380",
Expand Down

0 comments on commit 5708f6f

Please sign in to comment.