|
@@ -425,6 +425,7 @@ func getInfo(path string) *Info {
|
|
|
|
|
|
|
|
// Delete the old configuration if exist
|
|
// Delete the old configuration if exist
|
|
|
if ignore {
|
|
if ignore {
|
|
|
|
|
+
|
|
|
logPath := fmt.Sprintf("%s/log", path)
|
|
logPath := fmt.Sprintf("%s/log", path)
|
|
|
snapshotPath := fmt.Sprintf("%s/snapshotPath", path)
|
|
snapshotPath := fmt.Sprintf("%s/snapshotPath", path)
|
|
|
os.Remove(infoPath)
|
|
os.Remove(infoPath)
|
|
@@ -507,11 +508,20 @@ func joinCluster(s *raft.Server, serverName string) error {
|
|
|
json.NewEncoder(&b).Encode(command)
|
|
json.NewEncoder(&b).Encode(command)
|
|
|
|
|
|
|
|
// t must be ok
|
|
// t must be ok
|
|
|
- t, _ := raftServer.Transporter().(transporter)
|
|
|
|
|
|
|
+ t, ok := raftServer.Transporter().(transporter)
|
|
|
|
|
+
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ panic("wrong type")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
debug("Send Join Request to %s", serverName)
|
|
debug("Send Join Request to %s", serverName)
|
|
|
|
|
+
|
|
|
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)
|
|
|
}
|
|
}
|
|
@@ -520,17 +530,17 @@ 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.StatusServiceUnavailable {
|
|
|
|
|
- address, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- warn("Cannot Read Leader info: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if resp.StatusCode == http.StatusTemporaryRedirect {
|
|
|
|
|
+ fmt.Println("redirect")
|
|
|
|
|
+ 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)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return fmt.Errorf("Unable to join: %v", err)
|
|
return fmt.Errorf("Unable to join: %v", err)
|
|
|
}
|
|
}
|