Merge pull request #717 from xiangli-cmu/fix_join_redirection

fix(peer join) fix wrong join command redirection
release-0.4
Xiang Li 2014-04-13 21:59:39 -04:00
commit 8071dd054c
2 changed files with 11 additions and 4 deletions

View File

@ -510,15 +510,15 @@ func (s *PeerServer) joinByPeer(server raft.Server, peer string, scheme string)
if resp.StatusCode == http.StatusTemporaryRedirect {
address := resp.Header.Get("Location")
log.Debugf("Send Join Request to %s", address)
c := &JoinCommandV1{
c := &JoinCommandV2{
MinVersion: store.MinVersion(),
MaxVersion: store.MaxVersion(),
Name: server.Name(),
RaftURL: s.Config.URL,
EtcdURL: s.server.URL(),
PeerURL: s.Config.URL,
ClientURL: s.server.URL(),
}
json.NewEncoder(&b).Encode(c)
resp, _, err = t.Post(address, &b)
resp, _, err = t.Put(address, &b)
} else if resp.StatusCode == http.StatusBadRequest {
log.Debug("Reach max number peers in the cluster")

View File

@ -247,6 +247,13 @@ func (t *transporter) Get(urlStr string) (*http.Response, *http.Request, error)
return resp, req, err
}
// Send server side PUT request
func (t *transporter) Put(urlStr string, body io.Reader) (*http.Response, *http.Request, error) {
req, _ := http.NewRequest("PUT", urlStr, body)
resp, err := t.client.Do(req)
return resp, req, err
}
// PostSnapshot posts a json format snapshot to the given url
// The underlying HTTP transport has a minute level timeout
func (t *transporter) PostSnapshot(url string, body io.Reader) (*http.Response, error) {