Skip to content

Commit

Permalink
etcdserver: delete member directory when discovery fails
Browse files Browse the repository at this point in the history
When discovery fails, etcd node falls back to proxy. And in order to
start as a proxy, we need to make sure there are conflicting directories:
'member' and 'proxy' directories cannot be existent together. This deletes
'member' directory only when startEtcd fails (#3827).
  • Loading branch information
gyuho committed Dec 29, 2015
1 parent c3655cb commit aacad34
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type EtcdServer struct {

// NewServer creates a new EtcdServer from the supplied configuration. The
// configuration is considered static for the lifetime of the EtcdServer.
func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) {
st := store.New(StoreClusterPrefix, StoreKeysPrefix)
var (
w *wal.WAL
Expand Down Expand Up @@ -223,12 +223,21 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
}

haveWAL := wal.Exist(cfg.WALDir())
if !haveWAL {
defer func() {
if err != nil {
// cleans up member directory if bootstrap fails (including forming or joining a new cluster)
os.RemoveAll(cfg.MemberDir())
}
}()
}
ss := snap.New(cfg.SnapDir())

prt, err := rafthttp.NewRoundTripper(cfg.PeerTLSInfo, cfg.peerDialTimeout())
if err != nil {
return nil, err
}

var remotes []*Member
switch {
case !haveWAL && !cfg.NewCluster:
Expand Down Expand Up @@ -335,7 +344,7 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
sstats.Initialize()
lstats := stats.NewLeaderStats(id.String())

srv := &EtcdServer{
srv = &EtcdServer{
cfg: cfg,
snapCount: cfg.SnapCount,
errorc: make(chan error, 1),
Expand Down

0 comments on commit aacad34

Please sign in to comment.