Skip to content

Commit

Permalink
Merge pull request #13 from xiangli-cmu/master
Browse files Browse the repository at this point in the history
Clean up prints and fix len problem
  • Loading branch information
polvi committed Jul 11, 2013
2 parents 7ab3ccd + c2a80df commit 780e9f5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func startRaft(securityType int) {
if raftServer.IsLogEmpty() {

// start as a leader in a new cluster
if len(cluster) == 0 {
if len(cluster) == 1 && cluster[0] == "" {
raftServer.StartLeader()

time.Sleep(time.Millisecond * 20)
Expand All @@ -228,7 +228,7 @@ func startRaft(securityType int) {

for _, machine := range cluster {

err := joinCluster(raftServer, machine)
err = joinCluster(raftServer, machine)
if err != nil {
debug("cannot join to cluster via machine %s", machine)
} else {
Expand Down Expand Up @@ -518,10 +518,7 @@ func joinCluster(s *raft.Server, serverName string) error {

resp, err := t.Post(fmt.Sprintf("%s/join", serverName), &b)

debug("Finish Join Request to %s", serverName)

for {
fmt.Println(err, resp)
if err != nil {
return fmt.Errorf("Unable to join: %v", err)
}
Expand All @@ -530,14 +527,14 @@ func joinCluster(s *raft.Server, serverName string) error {
if resp.StatusCode == http.StatusOK {
return nil
}

if resp.StatusCode == http.StatusTemporaryRedirect {
fmt.Println("redirect")
address = resp.Header.Get("Location")
debug("Leader is %s", address)
debug("Send Join Request to %s", address)
json.NewEncoder(&b).Encode(command)
resp, err = t.Post(fmt.Sprintf("%s/join", address), &b)
} else {
return fmt.Errorf("Unable to join")
}
}

Expand Down

0 comments on commit 780e9f5

Please sign in to comment.