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

SNOW-965966: Remove unnecessary TODOs from DefaultResultStreamProvider #1607

Merged
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions src/main/java/net/snowflake/client/core/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
import net.snowflake.common.core.SqlState;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
Expand Down Expand Up @@ -916,4 +918,43 @@ static void applyAdditionalHeadersForSnowsight(
additionalHeaders.forEach(request::addHeader);
}
}

/**
* This method was moved from DefaultResultStreamProvider to take advantage of the HTTP connection
* pool manager initialized by HttpUtil
*
* @param oscpAndProxyKey OCSP mode and proxy settings for httpclient
* @param httpRequest HttpRequest
* @param networkTimeout network timeout
* @param authTimeout authenticator specific timeout
* @param socketTimeout socket timeout (in ms)
* @return
* @throws SnowflakeSQLException
*/
public static HttpResponse getHttpResponseForS3Request(
HttpClientSettingsKey oscpAndProxyKey,
HttpGet httpRequest,
int networkTimeout,
int authTimeout,
int socketTimeout)
throws SnowflakeSQLException {
CloseableHttpClient httpClient = HttpUtil.getHttpClient(oscpAndProxyKey);

// fetch the result chunk
return RestRequest.execute(
httpClient,
httpRequest,
networkTimeout / 1000, // retry timeout
authTimeout,
socketTimeout,
0,
0, // no socket timeout injection
null, // no canceling
false, // no cookie
false, // no retry parameters in url
false, // no request_guid
true, // retry on HTTP403 for AWS S3
true, // no retry on http request
new ExecTimeTelemetryData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.net.URISyntaxException;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import net.snowflake.client.core.ExecTimeTelemetryData;
import net.snowflake.client.core.HttpClientSettingsKey;
import net.snowflake.client.core.HttpUtil;
import net.snowflake.client.log.ArgSupplier;
import net.snowflake.client.util.SecretDetector;
Expand All @@ -18,7 +18,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;

public class DefaultResultStreamProvider implements ResultStreamProvider {
// SSE-C algorithm header
Expand Down Expand Up @@ -112,28 +111,14 @@ else if (context.getQrmk() != null) {
context.getChunkIndex(),
context.getResultChunk().getScrubbedUrl());

// TODO move this s3 request to HttpUtil class. In theory, upper layer
// TODO does not need to know about http client
CloseableHttpClient httpClient =
HttpUtil.getHttpClient(context.getChunkDownloader().getHttpClientSettingsKey());
HttpClientSettingsKey oscpAndProxyKey = context.getChunkDownloader().getHttpClientSettingsKey();
int networkTimeout = context.getNetworkTimeoutInMilli();
int authTimeout = context.getAuthTimeout();
int socketTimeout = context.getSocketTimeout();

// fetch the result chunk
HttpResponse response =
RestRequest.execute(
httpClient,
httpRequest,
context.getNetworkTimeoutInMilli() / 1000, // retry timeout
context.getAuthTimeout(),
context.getSocketTimeout(),
0,
0, // no socket timeout injection
null, // no canceling
false, // no cookie
false, // no retry parameters in url
false, // no request_guid
true, // retry on HTTP403 for AWS S3
true, // no retry on http request
new ExecTimeTelemetryData());
HttpUtil.getHttpResponseForS3Request(
oscpAndProxyKey, httpRequest, networkTimeout, authTimeout, socketTimeout);

SnowflakeResultSetSerializableV1.logger.debug(
"Thread {} Call #chunk{} returned for URL: {}, response={}",
Expand Down