Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core, Rest: Enable useSystemProperties on RESTClient #11548

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class HTTPClient implements RESTClient {
static final int REST_MAX_CONNECTIONS_DEFAULT = 100;
static final String REST_MAX_CONNECTIONS_PER_ROUTE = "rest.client.connections-per-route";
static final int REST_MAX_CONNECTIONS_PER_ROUTE_DEFAULT = 100;
private static final String REST_USE_SYSTEM_PROPERTIES = "rest.client.use-system-properties";
private static final boolean REST_USE_SYSTEM_PROPERTIES_DEFAULT = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken the current behaviour doesn't use system properties. With this change we seem to change that behaviour and one would have to turn that off manually by setting a property to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemProperties are used for ConnectionManager but not on Client. Not sure, what would the ideal behaviour in this case.


@VisibleForTesting
static final String REST_CONNECTION_TIMEOUT_MS = "rest.client.connection-timeout-ms";
Expand Down Expand Up @@ -130,9 +132,18 @@ private HTTPClient(
clientBuilder.setProxy(proxy);
}

if (shouldUseSystemProperties(properties)) {
clientBuilder.useSystemProperties();
}

this.httpClient = clientBuilder.build();
}

private static boolean shouldUseSystemProperties(Map<String, String> properties) {
return PropertyUtil.propertyAsBoolean(
properties, REST_USE_SYSTEM_PROPERTIES, REST_USE_SYSTEM_PROPERTIES_DEFAULT);
}

private static String extractResponseBodyAsString(CloseableHttpResponse response) {
try {
if (response.getEntity() == null) {
Expand Down Expand Up @@ -465,9 +476,11 @@ static HttpClientConnectionManager configureConnectionManager(Map<String, String
if (connectionConfig != null) {
connectionManagerBuilder.setDefaultConnectionConfig(connectionConfig);
}
if (shouldUseSystemProperties(properties)) {
connectionManagerBuilder.useSystemProperties();
}

return connectionManagerBuilder
.useSystemProperties()
.setMaxConnTotal(
Integer.getInteger(
REST_MAX_CONNECTIONS,
Expand Down