|
@@ -21,6 +21,8 @@ import (
|
|
|
"strings"
|
|
"strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
|
|
+ "golang.org/x/net/context"
|
|
|
|
|
+
|
|
|
"github.com/coreos/etcd/pkg/netutil"
|
|
"github.com/coreos/etcd/pkg/netutil"
|
|
|
"github.com/coreos/etcd/pkg/transport"
|
|
"github.com/coreos/etcd/pkg/transport"
|
|
|
"github.com/coreos/etcd/pkg/types"
|
|
"github.com/coreos/etcd/pkg/types"
|
|
@@ -62,7 +64,10 @@ type ServerConfig struct {
|
|
|
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
|
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
|
|
// and returns an error for things that should never happen.
|
|
// and returns an error for things that should never happen.
|
|
|
func (c *ServerConfig) VerifyBootstrap() error {
|
|
func (c *ServerConfig) VerifyBootstrap() error {
|
|
|
- if err := c.verifyLocalMember(true); err != nil {
|
|
|
|
|
|
|
+ if err := c.hasLocalMember(); err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ if err := c.advertiseMatchesCluster(); err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
if checkDuplicateURL(c.InitialPeerURLsMap) {
|
|
if checkDuplicateURL(c.InitialPeerURLsMap) {
|
|
@@ -77,10 +82,9 @@ func (c *ServerConfig) VerifyBootstrap() error {
|
|
|
// VerifyJoinExisting sanity-checks the initial config for join existing cluster
|
|
// VerifyJoinExisting sanity-checks the initial config for join existing cluster
|
|
|
// case and returns an error for things that should never happen.
|
|
// case and returns an error for things that should never happen.
|
|
|
func (c *ServerConfig) VerifyJoinExisting() error {
|
|
func (c *ServerConfig) VerifyJoinExisting() error {
|
|
|
- // no need for strict checking since the member have announced its
|
|
|
|
|
- // peer urls to the cluster before starting and do not have to set
|
|
|
|
|
- // it in the configuration again.
|
|
|
|
|
- if err := c.verifyLocalMember(false); err != nil {
|
|
|
|
|
|
|
+ // The member has announced its peer urls to the cluster before starting; no need to
|
|
|
|
|
+ // set the configuration again.
|
|
|
|
|
+ if err := c.hasLocalMember(); err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
if checkDuplicateURL(c.InitialPeerURLsMap) {
|
|
if checkDuplicateURL(c.InitialPeerURLsMap) {
|
|
@@ -92,25 +96,24 @@ func (c *ServerConfig) VerifyJoinExisting() error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// verifyLocalMember verifies the configured member is in configured
|
|
|
|
|
-// cluster. If strict is set, it also verifies the configured member
|
|
|
|
|
-// has the same peer urls as configured advertised peer urls.
|
|
|
|
|
-func (c *ServerConfig) verifyLocalMember(strict bool) error {
|
|
|
|
|
- urls := c.InitialPeerURLsMap[c.Name]
|
|
|
|
|
- // Make sure the cluster at least contains the local server.
|
|
|
|
|
- if urls == nil {
|
|
|
|
|
|
|
+// hasLocalMember checks that the cluster at least contains the local server.
|
|
|
|
|
+func (c *ServerConfig) hasLocalMember() error {
|
|
|
|
|
+ if urls := c.InitialPeerURLsMap[c.Name]; urls == nil {
|
|
|
return fmt.Errorf("couldn't find local name %q in the initial cluster configuration", c.Name)
|
|
return fmt.Errorf("couldn't find local name %q in the initial cluster configuration", c.Name)
|
|
|
}
|
|
}
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- if strict {
|
|
|
|
|
- // Advertised peer URLs must match those in the cluster peer list
|
|
|
|
|
- apurls := c.PeerURLs.StringSlice()
|
|
|
|
|
- sort.Strings(apurls)
|
|
|
|
|
- urls.Sort()
|
|
|
|
|
- if !netutil.URLStringsEqual(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, ","))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// advertiseMatchesCluster confirms peer URLs match those in the cluster peer list.
|
|
|
|
|
+func (c *ServerConfig) advertiseMatchesCluster() error {
|
|
|
|
|
+ urls, apurls := c.InitialPeerURLsMap[c.Name], c.PeerURLs.StringSlice()
|
|
|
|
|
+ urls.Sort()
|
|
|
|
|
+ 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, ","))
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|