From 063f3b574c0e673009aba9ddcb99b387dddb5408 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Tue, 4 Mar 2014 08:53:13 -0700 Subject: [PATCH] Check for peer before demotion. --- server/demote_command.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/demote_command.go b/server/demote_command.go index f48ef1fe1..a224b7baf 100644 --- a/server/demote_command.go +++ b/server/demote_command.go @@ -1,6 +1,8 @@ package server import ( + "fmt" + "github.com/coreos/etcd/log" "github.com/coreos/etcd/third_party/github.com/coreos/raft" ) @@ -23,6 +25,11 @@ func (c *DemoteCommand) CommandName() string { func (c *DemoteCommand) Apply(context raft.Context) (interface{}, error) { ps, _ := context.Server().Context().(*PeerServer) + // Ignore this command if there is no peer. + if !ps.registry.PeerExists(c.Name) { + return nil, fmt.Errorf("peer does not exist: %s", c.Name) + } + // Save URLs. clientURL, _ := ps.registry.ClientURL(c.Name) peerURL, _ := ps.registry.PeerURL(c.Name)