Skip to content

Commit dbce69a

Browse files
sfc-gh-ggengclaude
andcommitted
[SNOW-3249917] JDBC removal Step 10c: Remove SFSession from storage stack
Remove SFSession/SFBaseSession parameters and dead session-based code from the storage client stack. Session was always null from ingest callers. Storage clients (SnowflakeS3Client, SnowflakeAzureClient, SnowflakeGCSClient): - Remove SFSession/SFBaseSession fields and constructor params - Remove dead `if (session != null)` proxy/headers/permissions blocks (keep sessionless path) - Remove dead `if (session != null) { renewExpiredToken(...) }` blocks - Simplify getMaxRetries() to return default (no session property lookup) - Replace session.isOwnerOnlyStageFilePermissionsEnabled() with false Interface + strategies: - SnowflakeStorageClient: remove SFSession from all method signatures - GCSAccessStrategy/GCSAccessStrategyAwsSdk/GCSDefaultAccessStrategy: remove SFSession from constructors and handleStorageException - StorageClientFactory: remove SFSession/SFBaseSession params Agent + config: - SnowflakeFileTransferAgent: remove session from getStageInfo(), pushFileToRemoteStore(), compressStreamWithGZIP/NoDigest(). Remove dead renewExpiredToken(), parseCommandInGS(), getLocalFilePathFromCommand() methods. - SnowflakeFileTransferConfig: remove SFSession field, getter, setter Remaining SFSession imports (3): SnowflakeSQLLoggedException (constructor params), TelemetryClient (session-based code) — to be handled next. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 72f5e83 commit dbce69a

File tree

10 files changed

+189
-525
lines changed

10 files changed

+189
-525
lines changed

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
* Replicated from snowflake-jdbc (v3.25.1)
33
* Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/jdbc/cloud/storage/GCSAccessStrategy.java
44
*
5-
* Permitted differences: package, SFSession kept from JDBC temporarily,
5+
* Permitted differences: package, SFSession removed (always null from callers),
66
* SFPair uses ingest version, all storage types use ingest versions (same package).
77
*/
88
package net.snowflake.ingest.streaming.internal.fileTransferAgent;
99

1010
import java.io.File;
1111
import java.io.InputStream;
1212
import java.util.Map;
13-
import net.snowflake.client.core.SFSession;
1413
import net.snowflake.ingest.utils.SFPair;
1514

1615
interface GCSAccessStrategy {
@@ -40,7 +39,6 @@ boolean handleStorageException(
4039
Exception ex,
4140
int retryCount,
4241
String operation,
43-
SFSession session,
4442
String command,
4543
String queryId,
4644
SnowflakeGCSClient gcsClient)

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
import com.amazonaws.services.s3.transfer.Upload;
2828
import java.io.File;
2929
import java.io.InputStream;
30-
import java.util.List;
3130
import java.util.Map;
3231
import java.util.Optional;
3332
import java.util.stream.Collectors;
34-
import net.snowflake.client.core.SFBaseSession;
35-
import net.snowflake.client.core.SFSession;
3633
import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLogger;
3734
import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLoggerFactory;
3835
import net.snowflake.ingest.utils.SFPair;
@@ -42,7 +39,7 @@ class GCSAccessStrategyAwsSdk implements GCSAccessStrategy {
4239
private static final SFLogger logger = SFLoggerFactory.getLogger(GCSAccessStrategyAwsSdk.class);
4340
private final AmazonS3 amazonClient;
4441

45-
GCSAccessStrategyAwsSdk(StageInfo stage, SFBaseSession session)
42+
GCSAccessStrategyAwsSdk(StageInfo stage)
4643
throws SnowflakeSQLException, net.snowflake.client.jdbc.SnowflakeSQLException {
4744
String accessToken = (String) stage.getCredentials().get("GCS_ACCESS_TOKEN");
4845

@@ -74,21 +71,7 @@ class GCSAccessStrategyAwsSdk implements GCSAccessStrategy {
7471
clientConfig
7572
.getApacheHttpClientConfig()
7673
.setSslSocketFactory(SnowflakeS3Client.getSSLConnectionSocketFactory());
77-
if (session != null) {
78-
S3HttpUtil.setProxyForS3(session.getHttpClientKey(), clientConfig);
79-
} else {
80-
S3HttpUtil.setSessionlessProxyForS3(stage.getProxyProperties(), clientConfig);
81-
}
82-
83-
if (session instanceof SFSession) {
84-
List<net.snowflake.client.jdbc.HttpHeadersCustomizer> headersCustomizers =
85-
((SFSession) session).getHttpHeadersCustomizers();
86-
if (headersCustomizers != null && !headersCustomizers.isEmpty()) {
87-
amazonS3Builder.withRequestHandlers(
88-
new net.snowflake.client.core.HeaderCustomizerHttpRequestInterceptor(
89-
headersCustomizers));
90-
}
91-
}
74+
S3HttpUtil.setSessionlessProxyForS3(stage.getProxyProperties(), clientConfig);
9275

9376
if (accessToken != null) {
9477
amazonS3Builder.withCredentials(
@@ -237,7 +220,6 @@ public boolean handleStorageException(
237220
Exception ex,
238221
int retryCount,
239222
String operation,
240-
SFSession session,
241223
String command,
242224
String queryId,
243225
SnowflakeGCSClient gcsClient)
@@ -256,30 +238,23 @@ public boolean handleStorageException(
256238
if (ex instanceof AmazonServiceException) {
257239
AmazonServiceException ex1 = (AmazonServiceException) ex;
258240

259-
// The AWS credentials might have expired when server returns error 400 and
260-
// does not return the ExpiredToken error code.
261-
// If session is null we cannot renew the token so throw the exception
262-
if (ex1.getStatusCode() == HttpStatus.SC_BAD_REQUEST && session != null) {
263-
SnowflakeFileTransferAgent.renewExpiredToken(session, command, gcsClient);
264-
} else {
265-
throw new SnowflakeSQLLoggedException(
266-
queryId,
267-
session,
268-
SqlState.SYSTEM_ERROR,
269-
ErrorCode.S3_OPERATION_ERROR.getMessageCode(),
270-
ex1,
271-
operation,
272-
ex1.getErrorType().toString(),
273-
ex1.getErrorCode(),
274-
ex1.getMessage(),
275-
ex1.getRequestId(),
276-
extendedRequestId);
277-
}
241+
throw new SnowflakeSQLLoggedException(
242+
queryId,
243+
null,
244+
SqlState.SYSTEM_ERROR,
245+
ErrorCode.S3_OPERATION_ERROR.getMessageCode(),
246+
ex1,
247+
operation,
248+
ex1.getErrorType().toString(),
249+
ex1.getErrorCode(),
250+
ex1.getMessage(),
251+
ex1.getRequestId(),
252+
extendedRequestId);
278253

279254
} else {
280255
throw new SnowflakeSQLLoggedException(
281256
queryId,
282-
session,
257+
null,
283258
SqlState.SYSTEM_ERROR,
284259
ErrorCode.AWS_CLIENT_ERROR.getMessageCode(),
285260
ex,
@@ -314,16 +289,11 @@ public boolean handleStorageException(
314289
if (ex instanceof AmazonS3Exception) {
315290
AmazonS3Exception s3ex = (AmazonS3Exception) ex;
316291
if (s3ex.getErrorCode().equalsIgnoreCase(EXPIRED_AWS_TOKEN_ERROR_CODE)) {
317-
// If session is null we cannot renew the token so throw the ExpiredToken exception
318-
if (session != null) {
319-
SnowflakeFileTransferAgent.renewExpiredToken(session, command, gcsClient);
320-
} else {
321-
throw new SnowflakeSQLException(
322-
queryId,
323-
s3ex.getErrorCode(),
324-
CLOUD_STORAGE_CREDENTIALS_EXPIRED,
325-
"S3 credentials have expired");
326-
}
292+
throw new SnowflakeSQLException(
293+
queryId,
294+
s3ex.getErrorCode(),
295+
CLOUD_STORAGE_CREDENTIALS_EXPIRED,
296+
"S3 credentials have expired");
327297
}
328298
}
329299
}

src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.InputStream;
2020
import java.nio.channels.Channels;
2121
import java.util.Map;
22-
import net.snowflake.client.core.SFSession;
2322
import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLogger;
2423
import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLoggerFactory;
2524
import net.snowflake.ingest.utils.SFPair;
@@ -28,15 +27,15 @@ class GCSDefaultAccessStrategy implements GCSAccessStrategy {
2827
private static final SFLogger logger = SFLoggerFactory.getLogger(GCSDefaultAccessStrategy.class);
2928
private Storage gcsClient = null;
3029

31-
GCSDefaultAccessStrategy(StageInfo stage, SFSession session) {
30+
GCSDefaultAccessStrategy(StageInfo stage) {
3231
String accessToken = (String) stage.getCredentials().get("GCS_ACCESS_TOKEN");
3332

3433
if (accessToken != null) {
3534
// We are authenticated with an oauth access token.
3635
StorageOptions.Builder builder = StorageOptions.newBuilder();
3736
overrideHost(stage, builder);
3837

39-
if (SnowflakeGCSClient.areDisabledGcsDefaultCredentials(session)) {
38+
if (SnowflakeGCSClient.areDisabledGcsDefaultCredentials()) {
4039
logger.debug(
4140
"Adding explicit credentials to avoid default credential lookup by the GCS client");
4241
builder.setCredentials(GoogleCredentials.create(new AccessToken(accessToken, null)));
@@ -176,7 +175,6 @@ public boolean handleStorageException(
176175
Exception ex,
177176
int retryCount,
178177
String operation,
179-
SFSession session,
180178
String command,
181179
String queryId,
182180
SnowflakeGCSClient gcsClient)
@@ -191,7 +189,7 @@ public boolean handleStorageException(
191189
if (retryCount > gcsClient.getMaxRetries()) {
192190
throw new SnowflakeSQLLoggedException(
193191
queryId,
194-
session,
192+
null,
195193
SqlState.SYSTEM_ERROR,
196194
ErrorCode.GCP_SERVICE_ERROR.getMessageCode(),
197195
se,
@@ -223,17 +221,11 @@ public boolean handleStorageException(
223221
}
224222

225223
if (se.getCode() == 401 && command != null) {
226-
if (session != null) {
227-
// A 401 indicates that the access token has expired,
228-
// we need to refresh the GCS client with the new token
229-
SnowflakeFileTransferAgent.renewExpiredToken(session, command, gcsClient);
230-
} else {
231-
throw new SnowflakeSQLException(
232-
queryId,
233-
se.getMessage(),
234-
CLOUD_STORAGE_CREDENTIALS_EXPIRED,
235-
"GCS credentials have expired");
236-
}
224+
throw new SnowflakeSQLException(
225+
queryId,
226+
se.getMessage(),
227+
CLOUD_STORAGE_CREDENTIALS_EXPIRED,
228+
"GCS credentials have expired");
237229
}
238230
}
239231
return true;

0 commit comments

Comments
 (0)