Check for peer before demotion.

This commit is contained in:
Ben Johnson 2014-03-04 08:53:13 -07:00
parent c8d6b26dfd
commit 063f3b574c

View File

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