From 30c7a7f2ddd0809c820dcd0a12551b438ceb8898 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 11 Oct 2014 21:47:44 +0800 Subject: [PATCH] etcdserver: add shouldDiscover --- etcdserver/config.go | 4 ++++ etcdserver/server.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/etcdserver/config.go b/etcdserver/config.go index 8fda09f84..fd20f2368 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -48,6 +48,10 @@ func (c *ServerConfig) SnapDir() string { return path.Join(c.DataDir, "snap") } func (c *ServerConfig) ID() uint64 { return c.Cluster.FindName(c.Name).ID } +func (c *ServerConfig) ShouldDiscover() bool { + return c.DiscoveryURL != "" +} + // IsBootstrap returns ture if a bootstrap method is provided. func (c *ServerConfig) IsBootstrap() bool { return c.DiscoveryURL != "" || c.ClusterState == ClusterStateValueNew diff --git a/etcdserver/server.go b/etcdserver/server.go index 0716c7ec8..e70188218 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -128,7 +128,7 @@ func NewServer(cfg *ServerConfig) *EtcdServer { if !cfg.IsBootstrap() { log.Fatalf("etcd: initial cluster state unset and no wal or discovery URL found") } - if cfg.DiscoveryURL != "" { + if cfg.ShouldDiscover() { d, err := discovery.New(cfg.DiscoveryURL, cfg.ID(), cfg.Cluster.String()) if err != nil { log.Fatalf("etcd: cannot init discovery %v", err) @@ -143,8 +143,8 @@ func NewServer(cfg *ServerConfig) *EtcdServer { } n, w = startNode(cfg) } else { - if cfg.DiscoveryURL != "" { - log.Printf("etcd: warn: ignoring discovery URL: etcd has already been initialized and has a valid log in %q", cfg.WALDir()) + if cfg.ShouldDiscover() { + log.Printf("etcd: warn: ignoring discovery: etcd has already been initialized and has a valid log in %q", cfg.WALDir()) } var index uint64 snapshot, err := ss.Load()