Elasticsearch: Allow to configure REST client's retry timeout
Add a new configuration value elasticsearch.maxRetryTimeout which is
used to set the retry timeout on the REST client. Make the value
default to 30000 ms which is the same as the default used by the
client when not set.
Remove the following configuration values which were previously used
to configure the JEST client and are redundant since moving to the
Elasticsearch REST client in change I720c9885c:
- elasticsearch.requestCompression
- elasticsearch.connectionTimeout
- elasticsearch.maxConnectionIdleTime
- elasticsearch.maxReadTimeout
- elasticsearch.maxTotalConnection
Bug: Issue 9373
Change-Id: Ie3dcbbfe2dec5944bb4a2549f64d9ee9cdab2ad5
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 4131b58..12e5a88 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -2821,41 +2821,13 @@
+
Not set by default.
-[[elasticsearch.requestCompression]]elasticsearch.requestCompression::
+[[elasticsearch.maxRetryTimeout]]elasticsearch.maxRetryTimeout::
+
-Enable request compression.
-+
-Defaults to `false`.
-
-[[elasticsearch.connectionTimeout]]elasticsearch.connectionTimeout::
-+
-How long should Gerrit waits for connection.
+Sets the maximum timeout to honor in case of multiple retries of the same request.
+
The value is in the usual time-unit format like `1 m`, `5 m`.
+
-Defaults to `5 m`
-
-[[elasticsearch.maxConnectionIdleTime]]elasticsearch.maxConnectionIdleTime::
-+
-How long connection can stay in idle.
-+
-The value is in the usual time-unit format like `1 m`, `5 m`.
-+
-Defaults to `5 m`
-
-[[elasticsearch.maxTotalConnection]]elasticsearch.maxTotalConnection::
-+
-How many connections can be spawned simultaneously.
-+
-Defaults to `1`
-
-[[elasticsearch.maxReadTimeout]]elasticsearch.maxReadTimeout::
-+
-Timeout for read operations.
-+
-The value is in the usual time-unit format like `1 m`, `5 m`.
-+
-Defaults to `5 m`
+Defaults to `30000 ms`.
==== Elasticsearch server(s) configuration
diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
index 6b2fa13..591a9cb 100644
--- a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
+++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticConfiguration.java
@@ -42,11 +42,7 @@
final String username;
final String password;
- final boolean requestCompression;
- final long connectionTimeout;
- final long maxConnectionIdleTime;
- final int maxTotalConnection;
- final int readTimeout;
+ final int maxRetryTimeout;
final String prefix;
@Inject
@@ -54,15 +50,9 @@
this.cfg = cfg;
this.username = cfg.getString("elasticsearch", null, "username");
this.password = cfg.getString("elasticsearch", null, "password");
- this.requestCompression = cfg.getBoolean("elasticsearch", null, "requestCompression", false);
- this.connectionTimeout =
- cfg.getTimeUnit("elasticsearch", null, "connectionTimeout", 3000, TimeUnit.MILLISECONDS);
- this.maxConnectionIdleTime =
- cfg.getTimeUnit(
- "elasticsearch", null, "maxConnectionIdleTime", 3000, TimeUnit.MILLISECONDS);
- this.maxTotalConnection = cfg.getInt("elasticsearch", null, "maxTotalConnection", 1);
- this.readTimeout =
- (int) cfg.getTimeUnit("elasticsearch", null, "readTimeout", 3000, TimeUnit.MICROSECONDS);
+ this.maxRetryTimeout =
+ (int)
+ cfg.getTimeUnit("elasticsearch", null, "maxRetryTimeout", 30000, TimeUnit.MILLISECONDS);
this.prefix = Strings.nullToEmpty(cfg.getString("elasticsearch", null, "prefix"));
Set<String> subsections = cfg.getSubsections("elasticsearch");
diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
index f7580bd..b7898ae 100644
--- a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
+++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/ElasticRestClientProvider.java
@@ -128,6 +128,7 @@
private RestClient build() {
RestClientBuilder builder = RestClient.builder(cfg.getHosts());
+ builder.setMaxRetryTimeoutMillis(cfg.maxRetryTimeout);
setConfiguredCredentialsIfAny(builder);
return builder.build();
}