From f7ec7f025be03c3c45fe29f4d57238bfe5793fca Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 13 Jul 2016 16:02:49 -0700 Subject: [PATCH] embed: only get initial cluster setting if the member is not init --- etcdmain/etcd.go | 13 ++++++++++--- etcdmain/util.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 etcdmain/util.go diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index 13c3af626..2f0659f89 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -194,9 +194,16 @@ func startEtcdOrProxyV2() { // startEtcd launches the etcd server and HTTP handlers for client/server communication. func startEtcd(cfg *config) (<-chan struct{}, error) { - urlsmap, token, err := getPeerURLsMapAndToken(cfg, "etcd") - if err != nil { - return nil, fmt.Errorf("error setting up initial cluster: %v", err) + var ( + urlsmap types.URLsMap + token string + err error + ) + if !isMemberInitialized(cfg) { + urlsmap, token, err = getPeerURLsMapAndToken(cfg, "etcd") + if err != nil { + return nil, fmt.Errorf("error setting up initial cluster: %v", err) + } } if cfg.PeerAutoTLS && cfg.peerTLSInfo.Empty() { diff --git a/etcdmain/util.go b/etcdmain/util.go new file mode 100644 index 000000000..0bd531eeb --- /dev/null +++ b/etcdmain/util.go @@ -0,0 +1,30 @@ +// Copyright 2016 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package etcdmain + +import ( + "path" + + "github.com/coreos/etcd/wal" +) + +func isMemberInitialized(cfg *config) bool { + waldir := cfg.WalDir + if waldir == "" { + waldir = path.Join(cfg.Dir, "member", "wal") + } + + return wal.Exist(waldir) +}