|
@@ -206,7 +206,7 @@ func startRaft(securityType int) {
|
|
|
if raftServer.IsLogEmpty() {
|
|
if raftServer.IsLogEmpty() {
|
|
|
|
|
|
|
|
// start as a leader in a new cluster
|
|
// start as a leader in a new cluster
|
|
|
- if len(cluster) == 0 {
|
|
|
|
|
|
|
+ if len(cluster) == 1 && cluster[0] == "" {
|
|
|
raftServer.StartLeader()
|
|
raftServer.StartLeader()
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 20)
|
|
time.Sleep(time.Millisecond * 20)
|
|
@@ -228,7 +228,7 @@ func startRaft(securityType int) {
|
|
|
|
|
|
|
|
for _, machine := range cluster {
|
|
for _, machine := range cluster {
|
|
|
|
|
|
|
|
- err := joinCluster(raftServer, machine)
|
|
|
|
|
|
|
+ err = joinCluster(raftServer, machine)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
debug("cannot join to cluster via machine %s", machine)
|
|
debug("cannot join to cluster via machine %s", machine)
|
|
|
} else {
|
|
} else {
|
|
@@ -518,10 +518,7 @@ func joinCluster(s *raft.Server, serverName string) error {
|
|
|
|
|
|
|
|
resp, err := t.Post(fmt.Sprintf("%s/join", serverName), &b)
|
|
resp, err := t.Post(fmt.Sprintf("%s/join", serverName), &b)
|
|
|
|
|
|
|
|
- debug("Finish Join Request to %s", serverName)
|
|
|
|
|
-
|
|
|
|
|
for {
|
|
for {
|
|
|
- fmt.Println(err, resp)
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("Unable to join: %v", err)
|
|
return fmt.Errorf("Unable to join: %v", err)
|
|
|
}
|
|
}
|
|
@@ -530,14 +527,14 @@ func joinCluster(s *raft.Server, serverName string) error {
|
|
|
if resp.StatusCode == http.StatusOK {
|
|
if resp.StatusCode == http.StatusOK {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if resp.StatusCode == http.StatusTemporaryRedirect {
|
|
if resp.StatusCode == http.StatusTemporaryRedirect {
|
|
|
- fmt.Println("redirect")
|
|
|
|
|
address = resp.Header.Get("Location")
|
|
address = resp.Header.Get("Location")
|
|
|
debug("Leader is %s", address)
|
|
debug("Leader is %s", address)
|
|
|
debug("Send Join Request to %s", address)
|
|
debug("Send Join Request to %s", address)
|
|
|
json.NewEncoder(&b).Encode(command)
|
|
json.NewEncoder(&b).Encode(command)
|
|
|
resp, err = t.Post(fmt.Sprintf("%s/join", address), &b)
|
|
resp, err = t.Post(fmt.Sprintf("%s/join", address), &b)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return fmt.Errorf("Unable to join")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|