Browse Source

Check for peer before demotion.

Ben Johnson 11 years ago
parent
commit
063f3b574c
1 changed files with 7 additions and 0 deletions
  1. 7 0
      server/demote_command.go

+ 7 - 0
server/demote_command.go

@@ -1,6 +1,8 @@
 package server
 package server
 
 
 import (
 import (
+	"fmt"
+
 	"github.com/coreos/etcd/log"
 	"github.com/coreos/etcd/log"
 	"github.com/coreos/etcd/third_party/github.com/coreos/raft"
 	"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) {
 func (c *DemoteCommand) Apply(context raft.Context) (interface{}, error) {
 	ps, _ := context.Server().Context().(*PeerServer)
 	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.
 	// Save URLs.
 	clientURL, _ := ps.registry.ClientURL(c.Name)
 	clientURL, _ := ps.registry.ClientURL(c.Name)
 	peerURL, _ := ps.registry.PeerURL(c.Name)
 	peerURL, _ := ps.registry.PeerURL(c.Name)