From 8368e6a992a61bb79df62334d0e1ffc171d57054 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 --- embed/etcd.go | 15 +++++++++++---- embed/util.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 embed/util.go diff --git a/embed/etcd.go b/embed/etcd.go index d38d6dad6..2f7696eff 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -26,6 +26,7 @@ import ( "github.com/coreos/etcd/pkg/cors" runtimeutil "github.com/coreos/etcd/pkg/runtime" "github.com/coreos/etcd/pkg/transport" + "github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd/rafthttp" "github.com/coreos/pkg/capnslog" ) @@ -81,10 +82,16 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { e.Clients = append(e.Clients, sctx.l) } - urlsmap, token, uerr := cfg.PeerURLsMapAndToken("etcd") - if uerr != nil { - err = fmt.Errorf("error setting up initial cluster: %v", uerr) - return + var ( + urlsmap types.URLsMap + token string + ) + + if !isMemberInitialized(cfg) { + urlsmap, token, err = cfg.PeerURLsMapAndToken("etcd") + if err != nil { + return nil, fmt.Errorf("error setting up initial cluster: %v", err) + } } srvcfg := &etcdserver.ServerConfig{ diff --git a/embed/util.go b/embed/util.go new file mode 100644 index 000000000..39cf0ccdb --- /dev/null +++ b/embed/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 embed + +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) +}