Browse Source

fix join command

Xiang Li 12 years ago
parent
commit
84624f1ec0
2 changed files with 7 additions and 12 deletions
  1. 1 7
      etcd.go
  2. 6 5
      etcd_handlers.go

+ 1 - 7
etcd.go

@@ -17,7 +17,6 @@ import (
 	"net/url"
 	"os"
 	"os/signal"
-	"path"
 	"runtime/pprof"
 	"strings"
 	"time"
@@ -624,15 +623,10 @@ func joinCluster(s *raft.Server, serverName string) error {
 
 				address := resp.Header.Get("Location")
 				debugf("Send Join Request to %s", address)
-				u, err := url.Parse(address)
-
-				if err != nil {
-					return fmt.Errorf("Unable to join: %s", err.Error())
-				}
 
 				json.NewEncoder(&b).Encode(command)
 
-				resp, err = t.Post(path.Join(u.Host, u.Path), &b)
+				resp, err = t.Post(address, &b)
 
 			} else if resp.StatusCode == http.StatusBadRequest {
 				debug("Reach max number machines in the cluster")

+ 6 - 5
etcd_handlers.go

@@ -106,7 +106,7 @@ func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
 }
 
 // Dispatch the command to leader
-func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool) {
+func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
 	if raftServer.State() == "leader" {
 		if body, err := raftServer.Do(c); err != nil {
 			if _, ok := err.(store.NotFoundError); ok {
@@ -170,11 +170,12 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool)
 
 		var url string
 
-		if client {
-			clientAddr, _ := getEtcdURL(raftServer.Leader())
-			url = clientAddr + path
+		if etcd {
+			etcdAddr, _ := nameToEtcdURL(raftServer.Leader())
+			url = etcdAddr + path
 		} else {
-			url = raftServer.Leader() + path
+			raftAddr, _ := nameToRaftURL(raftServer.Leader())
+			url = raftAddr + path
 		}
 
 		debugf("Redirect to %s", url)