Handle server unavailable response

When starting multiple servers concurrently, they can race to connect
to each other.  This change just has the join attempts retry to make
cluster setup easier.
pull/2175/head
Jason Wilder 2015-04-03 15:11:15 -06:00
parent 01ee3fe352
commit aa5696c10d
2 changed files with 8 additions and 4 deletions

View File

@ -1922,10 +1922,6 @@ func TestSeparateBrokerTwoDataNodes(t *testing.T) {
t.Fatalf("Test %s: failed to create leader data node on port %d", testName, dataConfig1.Port)
}
// FIXME: This is needed for now because cmd.Open() will return before the server
// is actually ready to handle requests.
time.Sleep(1 * time.Second)
// Join data node 2 to single broker and first data node
dataConfig2 := main.NewConfig()
dataConfig2.Port = 9012

View File

@ -691,6 +691,14 @@ func (s *Server) Join(u *url.URL, joinURL *url.URL) error {
}
defer resp.Body.Close()
// If we get a service unavailable, the other data nodes may still be booting
// so retry again
if resp.StatusCode == http.StatusServiceUnavailable {
retries += 1
time.Sleep(1 * time.Second)
continue
}
// We likely tried to join onto a broker which cannot handle this request. It
// has given us the address of a known data node to join instead.
if resp.StatusCode == http.StatusTemporaryRedirect {