Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change client behavior on 503 from retry to failover #686

Merged
merged 9 commits into from
Mar 1, 2018
Merged

Change client behavior on 503 from retry to failover #686

merged 9 commits into from
Mar 1, 2018

Conversation

gregakinman
Copy link
Contributor

@gregakinman gregakinman commented Feb 28, 2018

@uschi2000
Copy link
Contributor

this looks good. i'll have to run for dinner now, but will take a more in-depth look later.

@gregakinman
Copy link
Contributor Author

gregakinman commented Feb 28, 2018 via email

@@ -118,10 +118,23 @@ public void testConnectionError_performsFailoverOnDnsFailure() throws Exception

@Test
public void testQosError_performsFailover() throws Exception {
server1.enqueue(new MockResponse().setResponseCode(503));
server1.enqueue(new MockResponse().setResponseCode(UNAVAILABLE_RESPONSE_CODE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think I prefer the 503 here

@@ -118,10 +118,23 @@ public void testConnectionError_performsFailoverOnDnsFailure() throws Exception

@Test
public void testQosError_performsFailover() throws Exception {
server1.enqueue(new MockResponse().setResponseCode(503));
server1.enqueue(new MockResponse().setResponseCode(UNAVAILABLE_RESPONSE_CODE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think I prefer the 503 here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a similar test for okhttp-clients?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

scheduleExecution(callback, backoff.get());
}
return null;
return redirectToUrl(callback, call,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to retry another host with backoff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking of the single-node case here? I thought about this and ended up going this way just to index on the multi-node case - if we get a 503 from one node, we have no data on the health of the other nodes, thus we can safely assume (as we always do when we are issuing the first try of a request) that any other node is healthy right now, and we can try immediately with no backoff. But in the single-node case we'd definitely want to back off. But the logic of how many URLs there are shouldn't be present at this level... and I guess you could run into the case where all nodes are unavailable due to load, and the client is getting bounced around, in which case it still makes sense to back off. And backing off the first time or two probably isn't the worst penalty to pay. Okay.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly

Copy link
Contributor

@uschi2000 uschi2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should perform backoff on 503

@@ -212,10 +213,10 @@ public void onResponse(Call call, Response response) throws IOException {
}

@SuppressWarnings("FutureReturnValueIgnored")
private void scheduleExecution(Callback callback, Duration backoff) {
private void scheduleExecution(Callback callback, Duration backoff, Runnable execution) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback is now unused?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to order (execution, backoff)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, fixed

() -> urls.redirectToNext(request().url()),
"Failed to determine valid redirect URL for base URLs " + urls.getBaseUrls(),
request -> scheduleExecution(() -> client.newCallWithMutableState(request,
backoffStrategy, maxNumRelocations - 1).enqueue(callback), backoff.get()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we need to decrease maxNumRelocations in this case. backoff already limits the number of retries for 503s.

}
return null;
}
};
}

private void redirectToUrl(Callback callback, Call call, Supplier<Optional<HttpUrl>> optionalUrlSupplier,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this construction is pretty hard to grok, maybe be more readable with a little bit of code duplication in the visit() methods. summarizing:

  • RetryOther should fail if maxNumRetries <= 0 or no URL can be determined
  • Unavailable should fail if backoff is empty or no URL can be determined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah realized i was possibly going overboard with the DRY there

server2.enqueue(new MockResponse().setResponseCode(200).setBody("foo"));
public void handlesQos_failsOverToAnotherUrl() throws Exception {
server.enqueue(new MockResponse().setResponseCode(503));
server.enqueue(new MockResponse().setBody("foo"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

server.enqueue(new MockResponse().setResponseCode(308).addHeader(HttpHeaders.LOCATION, url2));
server2.enqueue(new MockResponse().setResponseCode(503));
server2.enqueue(new MockResponse().setResponseCode(200).setBody("foo"));
public void handlesQos_failsOverToAnotherUrl() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handlesQos_503FailsOverToAnotherUrl

@uschi2000 uschi2000 merged commit c055cdd into palantir:develop Mar 1, 2018
@uschi2000
Copy link
Contributor

thanks, @gregakinman

@gregakinman gregakinman deleted the gk/failover branch March 1, 2018 00:59
@gregakinman
Copy link
Contributor Author

np! would like to cut 3.19.0 with this too if you weren't planning to already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants