Browse Source

change getMachines

Xiang Li 12 years ago
parent
commit
49c160b50c
4 changed files with 6 additions and 14 deletions
  1. 2 2
      command.go
  2. 1 1
      etcd_handlers.go
  3. 2 10
      machines.go
  4. 1 1
      raft_server.go

+ 2 - 2
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 {

+ 1 - 1
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, ", ")))

+ 2 - 10
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 {

+ 1 - 1
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 {