@@ -186,6 +186,12 @@ final class S3ClientSettings {
186
186
key -> Setting .boolSetting (key , false , Property .NodeScope )
187
187
);
188
188
189
+ static final Setting .AffixSetting <TimeValue > CONNECTION_MAX_IDLE_TIME_SETTING = Setting .affixKeySetting (
190
+ PREFIX ,
191
+ "connection_max_idle_time" ,
192
+ key -> Setting .timeSetting (key , Defaults .CONNECTION_MAX_IDLE_TIME , Property .NodeScope )
193
+ );
194
+
189
195
/** Credentials to authenticate with s3. */
190
196
final AwsCredentials credentials ;
191
197
@@ -215,6 +221,11 @@ final class S3ClientSettings {
215
221
/** The read timeout for the s3 client. */
216
222
final int readTimeoutMillis ;
217
223
224
+ /**
225
+ * The maximum idle time (in millis) of a connection before it is discarded from the connection pool.
226
+ */
227
+ final long connectionMaxIdleTimeMillis ;
228
+
218
229
/** The maximum number of concurrent connections to use. */
219
230
final int maxConnections ;
220
231
@@ -243,6 +254,7 @@ private S3ClientSettings(
243
254
String proxyUsername ,
244
255
String proxyPassword ,
245
256
int readTimeoutMillis ,
257
+ long connectionMaxIdleTimeMillis ,
246
258
int maxConnections ,
247
259
int maxRetries ,
248
260
boolean pathStyleAccess ,
@@ -259,6 +271,7 @@ private S3ClientSettings(
259
271
this .proxyUsername = proxyUsername ;
260
272
this .proxyPassword = proxyPassword ;
261
273
this .readTimeoutMillis = readTimeoutMillis ;
274
+ this .connectionMaxIdleTimeMillis = connectionMaxIdleTimeMillis ;
262
275
this .maxConnections = maxConnections ;
263
276
this .maxRetries = maxRetries ;
264
277
this .pathStyleAccess = pathStyleAccess ;
@@ -308,12 +321,18 @@ S3ClientSettings refine(Settings repositorySettings) {
308
321
newCredentials = credentials ;
309
322
}
310
323
final String newRegion = getRepoSettingOrDefault (REGION , normalizedSettings , region );
324
+ final long newConnectionMaxIdleTimeMillis = getRepoSettingOrDefault (
325
+ CONNECTION_MAX_IDLE_TIME_SETTING ,
326
+ normalizedSettings ,
327
+ TimeValue .timeValueMillis (connectionMaxIdleTimeMillis )
328
+ ).millis ();
311
329
if (Objects .equals (protocol , newProtocol )
312
330
&& Objects .equals (endpoint , newEndpoint )
313
331
&& Objects .equals (proxyHost , newProxyHost )
314
332
&& proxyPort == newProxyPort
315
333
&& proxyScheme == newProxyScheme
316
334
&& newReadTimeoutMillis == readTimeoutMillis
335
+ && Objects .equals (connectionMaxIdleTimeMillis , newConnectionMaxIdleTimeMillis )
317
336
&& maxConnections == newMaxConnections
318
337
&& maxRetries == newMaxRetries
319
338
&& Objects .equals (credentials , newCredentials )
@@ -333,6 +352,7 @@ S3ClientSettings refine(Settings repositorySettings) {
333
352
proxyUsername ,
334
353
proxyPassword ,
335
354
newReadTimeoutMillis ,
355
+ newConnectionMaxIdleTimeMillis ,
336
356
newMaxConnections ,
337
357
newMaxRetries ,
338
358
newPathStyleAccess ,
@@ -441,6 +461,7 @@ static S3ClientSettings getClientSettings(final Settings settings, final String
441
461
proxyUsername .toString (),
442
462
proxyPassword .toString (),
443
463
Math .toIntExact (getConfigValue (settings , clientName , READ_TIMEOUT_SETTING ).millis ()),
464
+ getConfigValue (settings , clientName , CONNECTION_MAX_IDLE_TIME_SETTING ).millis (),
444
465
getConfigValue (settings , clientName , MAX_CONNECTIONS_SETTING ),
445
466
getConfigValue (settings , clientName , MAX_RETRIES_SETTING ),
446
467
getConfigValue (settings , clientName , USE_PATH_STYLE_ACCESS ),
@@ -462,6 +483,7 @@ public boolean equals(final Object o) {
462
483
final S3ClientSettings that = (S3ClientSettings ) o ;
463
484
return proxyPort == that .proxyPort
464
485
&& readTimeoutMillis == that .readTimeoutMillis
486
+ && Objects .equals (connectionMaxIdleTimeMillis , that .connectionMaxIdleTimeMillis )
465
487
&& maxConnections == that .maxConnections
466
488
&& maxRetries == that .maxRetries
467
489
&& Objects .equals (credentials , that .credentials )
@@ -488,6 +510,7 @@ public int hashCode() {
488
510
proxyUsername ,
489
511
proxyPassword ,
490
512
readTimeoutMillis ,
513
+ connectionMaxIdleTimeMillis ,
491
514
maxRetries ,
492
515
maxConnections ,
493
516
disableChunkedEncoding ,
@@ -510,6 +533,7 @@ private static <T> T getRepoSettingOrDefault(Setting.AffixSetting<T> setting, Se
510
533
511
534
static final class Defaults {
512
535
static final TimeValue READ_TIMEOUT = TimeValue .timeValueSeconds (50 );
536
+ static final TimeValue CONNECTION_MAX_IDLE_TIME = TimeValue .timeValueSeconds (60 );
513
537
static final int MAX_CONNECTIONS = 50 ;
514
538
static final int RETRY_COUNT = 3 ;
515
539
}
0 commit comments