Skip to content

Commit 99192e7

Browse files
authored
Deprecate maxRetryTimeout in RestClient and increase default value (#38425)
This commit deprecates the `maxRetryTimeout` settings in the low-level REST client, and increases its default value from 30 seconds to 90 seconds. The goal of this is to have it set higher than the socket timeout so that users get as few listener timeouts as possible. Relates to #38085
1 parent 6d16374 commit 99192e7

File tree

11 files changed

+10
-29
lines changed

11 files changed

+10
-29
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
public final class RestClientBuilder {
4343
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 1000;
4444
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 30000;
45-
public static final int DEFAULT_MAX_RETRY_TIMEOUT_MILLIS = DEFAULT_SOCKET_TIMEOUT_MILLIS;
45+
public static final int DEFAULT_MAX_RETRY_TIMEOUT_MILLIS = 90000;
4646
public static final int DEFAULT_MAX_CONN_PER_ROUTE = 10;
4747
public static final int DEFAULT_MAX_CONN_TOTAL = 30;
4848

@@ -105,9 +105,10 @@ public RestClientBuilder setFailureListener(RestClient.FailureListener failureLi
105105
/**
106106
* Sets the maximum timeout (in milliseconds) to honour in case of multiple retries of the same request.
107107
* {@link #DEFAULT_MAX_RETRY_TIMEOUT_MILLIS} if not specified.
108-
*
108+
* @deprecated this setting is deprecated and will be removed in the future in favour of relying on socket and connect timeout
109109
* @throws IllegalArgumentException if {@code maxRetryTimeoutMillis} is not greater than 0
110110
*/
111+
@Deprecated
111112
public RestClientBuilder setMaxRetryTimeoutMillis(int maxRetryTimeoutMillis) {
112113
if (maxRetryTimeoutMillis <= 0) {
113114
throw new IllegalArgumentException("maxRetryTimeoutMillis must be greater than 0");

client/rest/src/test/java/org/elasticsearch/client/documentation/RestClientDocumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ public RequestConfig.Builder customizeRequestConfig(
305305
.setConnectTimeout(5000)
306306
.setSocketTimeout(60000);
307307
}
308-
})
309-
.setMaxRetryTimeoutMillis(60000);
308+
});
310309
//end::rest-client-config-timeouts
311310
}
312311
{

docs/java-rest/low-level/configuration.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/htt
1818
as an argument and has the same return type. The request config builder can
1919
be modified and then returned. In the following example we increase the
2020
connect timeout (defaults to 1 second) and the socket timeout (defaults to 30
21-
seconds). Also we adjust the max retry timeout accordingly (defaults to 30
22-
seconds too).
21+
seconds).
2322

2423
["source","java",subs="attributes,callouts,macros"]
2524
--------------------------------------------------

docs/java-rest/low-level/usage.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ prevent having to specify them with each single request
185185
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-init-max-retry-timeout]
186186
--------------------------------------------------
187187
<1> Set the timeout that should be honoured in case multiple attempts are made
188-
for the same request. The default value is 30 seconds, same as the default
189-
socket timeout. In case the socket timeout is customized, the maximum retry
190-
timeout should be adjusted accordingly
188+
for the same request. The default value is 90 seconds. In case the socket
189+
timeout is set to a higher value, the max retry timeout should be adjusted
190+
accordingly. deprecated[6.7.0, max retry timeout will be removed in 7.0.0]
191191

192192
["source","java",subs="attributes,callouts,macros"]
193193
--------------------------------------------------

plugins/repository-azure/qa/microsoft-azure-storage/src/test/java/org/elasticsearch/repositories/azure/AzureStorageRepositoryClientYamlTestSuiteIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public static Iterable<Object[]> parameters() throws Exception {
4141
protected Settings restClientSettings() {
4242
// Give more time to repository-azure to complete the snapshot operations
4343
return Settings.builder().put(super.restClientSettings())
44-
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "60s")
4544
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "60s")
4645
.build();
4746
}

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractRollingTestCase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ protected final Settings restClientSettings() {
6969
// increase the timeout here to 90 seconds to handle long waits for a green
7070
// cluster health. the waits for green need to be longer than a minute to
7171
// account for delayed shards
72-
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "90s")
7372
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
7473
.build();
7574
}

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ protected Settings restClientSettings() {
6565
// increase the timeout here to 90 seconds to handle long waits for a green
6666
// cluster health. the waits for green need to be longer than a minute to
6767
// account for delayed shards
68-
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "90s")
6968
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
7069
.build();
7170
}

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
public abstract class ESRestTestCase extends ESTestCase {
9393
public static final String TRUSTSTORE_PATH = "truststore.path";
9494
public static final String TRUSTSTORE_PASSWORD = "truststore.password";
95-
public static final String CLIENT_RETRY_TIMEOUT = "client.retry.timeout";
9695
public static final String CLIENT_SOCKET_TIMEOUT = "client.socket.timeout";
9796
public static final String CLIENT_PATH_PREFIX = "client.path.prefix";
9897

@@ -729,11 +728,6 @@ protected static void configureClient(RestClientBuilder builder, Settings settin
729728
}
730729
builder.setDefaultHeaders(defaultHeaders);
731730
}
732-
final String requestTimeoutString = settings.get(CLIENT_RETRY_TIMEOUT);
733-
if (requestTimeoutString != null) {
734-
final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT);
735-
builder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis()));
736-
}
737731
final String socketTimeoutString = settings.get(CLIENT_SOCKET_TIMEOUT);
738732
if (socketTimeoutString != null) {
739733
final TimeValue socketTimeout = TimeValue.parseTimeValue(socketTimeoutString, CLIENT_SOCKET_TIMEOUT);

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ protected Settings restClientSettings() {
6363
// we increase the timeout here to 90 seconds to handle long waits for a green
6464
// cluster health. the waits for green need to be longer than a minute to
6565
// account for delayed shards
66-
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "90s")
6766
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
6867
.build();
6968
}

x-pack/qa/kerberos-tests/src/test/java/org/elasticsearch/xpack/security/authc/kerberos/KerberosAuthenticationIT.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.test.rest.ESRestTestCase;
2424
import org.junit.Before;
2525

26+
import javax.security.auth.login.LoginContext;
2627
import java.io.IOException;
2728
import java.net.InetAddress;
2829
import java.net.UnknownHostException;
@@ -33,8 +34,6 @@
3334
import java.util.List;
3435
import java.util.Map;
3536

36-
import javax.security.auth.login.LoginContext;
37-
3837
import static org.elasticsearch.common.xcontent.XContentHelper.convertToMap;
3938
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
4039
import static org.hamcrest.Matchers.contains;
@@ -148,13 +147,7 @@ private RestClient buildRestClientForKerberos(final SpnegoHttpClientConfigCallba
148147
return restClientBuilder.build();
149148
}
150149

151-
private static void configureRestClientBuilder(final RestClientBuilder restClientBuilder, final Settings settings)
152-
throws IOException {
153-
final String requestTimeoutString = settings.get(CLIENT_RETRY_TIMEOUT);
154-
if (requestTimeoutString != null) {
155-
final TimeValue maxRetryTimeout = TimeValue.parseTimeValue(requestTimeoutString, CLIENT_RETRY_TIMEOUT);
156-
restClientBuilder.setMaxRetryTimeoutMillis(Math.toIntExact(maxRetryTimeout.getMillis()));
157-
}
150+
private static void configureRestClientBuilder(final RestClientBuilder restClientBuilder, final Settings settings) {
158151
final String socketTimeoutString = settings.get(CLIENT_SOCKET_TIMEOUT);
159152
if (socketTimeoutString != null) {
160153
final TimeValue socketTimeout = TimeValue.parseTimeValue(socketTimeoutString, CLIENT_SOCKET_TIMEOUT);

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ protected Settings restClientSettings() {
103103
// we increase the timeout here to 90 seconds to handle long waits for a green
104104
// cluster health. the waits for green need to be longer than a minute to
105105
// account for delayed shards
106-
.put(ESRestTestCase.CLIENT_RETRY_TIMEOUT, "90s")
107106
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
108107
.build();
109108
}

0 commit comments

Comments
 (0)