etcdserver: add shouldDiscover

This commit is contained in:
Xiang Li
2014-10-11 21:47:44 +08:00
parent a85ec90d68
commit 30c7a7f2dd
2 changed files with 7 additions and 3 deletions

View File

@@ -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

View File

@@ -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()