Skip to content

Commit

Permalink
Validate stale connection in HTTPClient pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-tu committed Nov 24, 2021
1 parent 272d9c4 commit 7f09be8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum ClickHouseConnectionSettings implements DriverPropertyCreator {
/**
* for ConnectionManager
*/
VALIDATE_AFTER_INACTIVITY_MILLIS("validateAfterInactivityMillis", 3 * 1000, "period of inactivity in milliseconds after which persistent connections must be re-validated, this check helps detect connections that have become stale (half-closed) while kept inactive in the pool. "),
TIME_TO_LIVE_MILLIS("timeToLiveMillis", 60 * 1000, ""),
DEFAULT_MAX_PER_ROUTE("defaultMaxPerRoute", 500, ""),
MAX_TOTAL("maxTotal", 10000, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ClickHouseProperties {
private int socketTimeout;
private int connectionTimeout;
private int timeToLiveMillis;
private int validateAfterInactivityMillis;
private int defaultMaxPerRoute;
private int maxTotal;
private int maxRetries;
Expand Down Expand Up @@ -110,6 +111,7 @@ public ClickHouseProperties(Properties info) {
this.socketTimeout = (Integer)getSetting(info, ClickHouseConnectionSettings.SOCKET_TIMEOUT);
this.connectionTimeout = (Integer)getSetting(info, ClickHouseConnectionSettings.CONNECTION_TIMEOUT);
this.timeToLiveMillis = (Integer)getSetting(info, ClickHouseConnectionSettings.TIME_TO_LIVE_MILLIS);
this.validateAfterInactivityMillis = (Integer)getSetting(info, ClickHouseConnectionSettings.VALIDATE_AFTER_INACTIVITY_MILLIS);
this.defaultMaxPerRoute = (Integer)getSetting(info, ClickHouseConnectionSettings.DEFAULT_MAX_PER_ROUTE);
this.maxTotal = (Integer)getSetting(info, ClickHouseConnectionSettings.MAX_TOTAL);
this.maxRetries = (Integer)getSetting(info, ClickHouseConnectionSettings.MAX_RETRIES);
Expand Down Expand Up @@ -177,6 +179,7 @@ public Properties asProperties() {
ret.put(ClickHouseConnectionSettings.SOCKET_TIMEOUT.getKey(), String.valueOf(socketTimeout));
ret.put(ClickHouseConnectionSettings.CONNECTION_TIMEOUT.getKey(), String.valueOf(connectionTimeout));
ret.put(ClickHouseConnectionSettings.TIME_TO_LIVE_MILLIS.getKey(), String.valueOf(timeToLiveMillis));
ret.put(ClickHouseConnectionSettings.VALIDATE_AFTER_INACTIVITY_MILLIS.getKey(), String.valueOf(validateAfterInactivityMillis));
ret.put(ClickHouseConnectionSettings.DEFAULT_MAX_PER_ROUTE.getKey(), String.valueOf(defaultMaxPerRoute));
ret.put(ClickHouseConnectionSettings.MAX_TOTAL.getKey(), String.valueOf(maxTotal));
ret.put(ClickHouseConnectionSettings.MAX_RETRIES.getKey(), String.valueOf(maxRetries));
Expand Down Expand Up @@ -247,6 +250,7 @@ public ClickHouseProperties(ClickHouseProperties properties) {
setSocketTimeout(properties.socketTimeout);
setConnectionTimeout(properties.connectionTimeout);
setTimeToLiveMillis(properties.timeToLiveMillis);
setValidateAfterInactivityMillis(properties.validateAfterInactivityMillis);
setDefaultMaxPerRoute(properties.defaultMaxPerRoute);
setMaxTotal(properties.maxTotal);
setMaxRetries(properties.maxRetries);
Expand Down Expand Up @@ -566,6 +570,14 @@ public void setTimeToLiveMillis(int timeToLiveMillis) {
this.timeToLiveMillis = timeToLiveMillis;
}

public int getValidateAfterInactivityMillis() {
return validateAfterInactivityMillis;
}

public void setValidateAfterInactivityMillis(int validateAfterInactivityMillis) {
this.validateAfterInactivityMillis = validateAfterInactivityMillis;
}

public int getDefaultMaxPerRoute() {
return defaultMaxPerRoute;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private PoolingHttpClientConnectionManager getConnectionManager()
TimeUnit.MILLISECONDS
);

connectionManager.setValidateAfterInactivity(properties.getValidateAfterInactivityMillis());
connectionManager.setDefaultMaxPerRoute(properties.getDefaultMaxPerRoute());
connectionManager.setMaxTotal(properties.getMaxTotal());
connectionManager.setDefaultConnectionConfig(getConnectionConfig());
Expand Down

0 comments on commit 7f09be8

Please sign in to comment.