mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-20 03:45:02 +00:00
add comments on retries
This commit is contained in:
parent
742f9c6eaa
commit
853ea9385b
@ -138,19 +138,21 @@ public final class RestClient implements Closeable {
|
|||||||
HttpRequestBase request = createHttpRequest(method, uri, entity);
|
HttpRequestBase request = createHttpRequest(method, uri, entity);
|
||||||
setHeaders(request, headers);
|
setHeaders(request, headers);
|
||||||
//we apply a soft margin so that e.g. if a request took 59 seconds and timeout is set to 60 we don't do another attempt
|
//we apply a soft margin so that e.g. if a request took 59 seconds and timeout is set to 60 we don't do another attempt
|
||||||
long retryTimeout = Math.round(this.maxRetryTimeoutMillis / (float)100 * 98);
|
long retryTimeoutMillis = Math.round(this.maxRetryTimeoutMillis / (float)100 * 98);
|
||||||
IOException lastSeenException = null;
|
IOException lastSeenException = null;
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
for (HttpHost host : nextHost()) {
|
for (HttpHost host : nextHost()) {
|
||||||
if (lastSeenException != null) {
|
if (lastSeenException != null) {
|
||||||
long timeElapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
|
//in case we are retrying, check whether maxRetryTimeout has been reached, in which case an exception will be thrown
|
||||||
long timeout = retryTimeout - timeElapsed;
|
long timeElapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
|
||||||
|
long timeout = retryTimeoutMillis - timeElapsedMillis;
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
IOException retryTimeoutException = new IOException(
|
IOException retryTimeoutException = new IOException(
|
||||||
"request retries exceeded max retry timeout [" + retryTimeout + "]");
|
"request retries exceeded max retry timeout [" + retryTimeoutMillis + "]");
|
||||||
retryTimeoutException.addSuppressed(lastSeenException);
|
retryTimeoutException.addSuppressed(lastSeenException);
|
||||||
throw retryTimeoutException;
|
throw retryTimeoutException;
|
||||||
}
|
}
|
||||||
|
//also reset the request to make it reusable for the next attempt
|
||||||
request.reset();
|
request.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user