Browse Source

etcdserver: add shouldDiscover

Xiang Li 11 years ago
parent
commit
30c7a7f2dd
2 changed files with 7 additions and 3 deletions
  1. 4 0
      etcdserver/config.go
  2. 3 3
      etcdserver/server.go

+ 4 - 0
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

+ 3 - 3
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()