From 49c160b50c6335b31565a2402b9a16df035dd3c3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 19 Aug 2013 13:42:00 -0700 Subject: [PATCH] change getMachines --- command.go | 4 ++-- etcd_handlers.go | 2 +- machines.go | 12 ++---------- raft_server.go | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/command.go b/command.go index 8ede579ba..b5b74ade9 100644 --- a/command.go +++ b/command.go @@ -212,7 +212,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) { if c.Name == raftServer.Name() { // the removed node is this node - // if the node is not replying the previous logs + // if the node is not replaying the previous logs // and the node has sent out a join request in this // start. It is sure that this node received a new remove // command and need to be removed @@ -220,7 +220,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) { debugf("server [%s] is removed", raftServer.Name()) os.Exit(0) } else { - // the node is replying previous logs and there is a join command + // the node is replaying previous logs and there is a join command // afterwards, we should not exit if r.joinIndex == 0 { diff --git a/etcd_handlers.go b/etcd_handlers.go index c7d228e33..4c4673983 100644 --- a/etcd_handlers.go +++ b/etcd_handlers.go @@ -189,7 +189,7 @@ func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) error { // Handler to return all the known machines in the current cluster func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) error { - machines := getMachines(true) + machines := getMachines(nameToEtcdURL) w.WriteHeader(http.StatusOK) w.Write([]byte(strings.Join(machines, ", "))) diff --git a/machines.go b/machines.go index 76c827c34..fbaa48d6f 100644 --- a/machines.go +++ b/machines.go @@ -8,22 +8,14 @@ func machineNum() int { } // getMachines gets the current machines in the cluster -func getMachines(etcd bool) []string { +func getMachines(toURL func(string) (string, bool)) []string { peers := r.Peers() machines := make([]string, len(peers)+1) - var toURL func(string) (string, bool) - - if etcd { - toURL = nameToEtcdURL - } else { - toURL = nameToRaftURL - } - leader, ok := toURL(r.Leader()) - self := e.url + self, _ := toURL(r.Name()) i := 1 if ok { diff --git a/raft_server.go b/raft_server.go index 5c1689d9e..fcabd6339 100644 --- a/raft_server.go +++ b/raft_server.go @@ -82,7 +82,7 @@ func (r *raftServer) ListenAndServe() { } else { if r.pendingJoin { - cluster = getMachines(false) + cluster = getMachines(nameToRaftURL) for i := 0; i < len(cluster); i++ { u, err := url.Parse(cluster[i]) if err != nil {