From 0199879fbd20a792debda832a5a21163bf11d4dd Mon Sep 17 00:00:00 2001 From: Gibbs Geng Date: Thu, 2 Apr 2026 09:24:44 +0000 Subject: [PATCH] [SNOW-3249917] JDBC removal Step 10c (part 2): Remove SFSession from exceptions + telemetry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove SFSession/SFBaseSession from SnowflakeSQLLoggedException and TelemetryClient. Session was always null from ingest callers. SnowflakeSQLLoggedException: - Remove SFBaseSession/SFSession from all 15 constructor signatures - Remove IB telemetry dead code (session was always null, so ibInstance was always null — only OOB path ever executed) - Remove sendInBandTelemetryMessage, createIBValue (dead code) - Simplify sendTelemetryData to always send OOB - Remove Telemetry/TelemetryField(JDBC)/TelemetryUtil(JDBC) imports - Update all callers (~12 files) to remove null session argument TelemetryClient: - Remove SFSession field and session-based constructor - Remove createTelemetry(Connection/SFSession) factory methods - Simplify isTelemetryEnabled() (no session check) - Remove session-based auth header and HTTP call branch in sendBatch() - Remove SFSession, SnowflakeConnectionV1, Connection, SQLException, UnexpectedException imports Remaining JDBC imports: 6 (HttpUtil + SnowflakeSQLException in TelemetryClient, HttpUtil + RestRequest + ExecTimeTelemetryData + HttpResponseContextDto in SnowflakeGCSClient) Co-Authored-By: Claude Opus 4.6 --- .../connection/telemetry/TelemetryClient.java | 115 +-------- .../GCSAccessStrategyAwsSdk.java | 2 - .../GCSDefaultAccessStrategy.java | 1 - .../fileTransferAgent/IcebergAzureClient.java | 5 - .../fileTransferAgent/IcebergGCSClient.java | 6 - .../fileTransferAgent/IcebergS3Client.java | 7 - .../IcebergStorageClient.java | 1 - .../SnowflakeAzureClient.java | 14 -- .../SnowflakeFileTransferAgent.java | 2 - .../fileTransferAgent/SnowflakeGCSClient.java | 15 -- .../fileTransferAgent/SnowflakeS3Client.java | 13 - .../SnowflakeSQLLoggedException.java | 235 +++--------------- .../SnowflakeStorageClient.java | 1 - .../fileTransferAgent/StorageClientUtil.java | 1 - .../SnowflakeSQLLoggedExceptionTest.java | 31 +-- 15 files changed, 55 insertions(+), 394 deletions(-) diff --git a/src/main/java/net/snowflake/ingest/connection/telemetry/TelemetryClient.java b/src/main/java/net/snowflake/ingest/connection/telemetry/TelemetryClient.java index dd3eca27f..1c88d210f 100644 --- a/src/main/java/net/snowflake/ingest/connection/telemetry/TelemetryClient.java +++ b/src/main/java/net/snowflake/ingest/connection/telemetry/TelemetryClient.java @@ -8,15 +8,10 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; -import java.rmi.UnexpectedException; -import java.sql.Connection; -import java.sql.SQLException; import java.util.LinkedList; import java.util.Objects; import java.util.concurrent.Future; import net.snowflake.client.core.HttpUtil; -import net.snowflake.client.core.SFSession; -import net.snowflake.client.jdbc.SnowflakeConnectionV1; import net.snowflake.client.jdbc.SnowflakeSQLException; import net.snowflake.ingest.streaming.internal.fileTransferAgent.ObjectMapperFactory; import net.snowflake.ingest.streaming.internal.fileTransferAgent.TelemetryThreadPool; @@ -32,7 +27,6 @@ public class TelemetryClient implements Telemetry { private static final SFLogger logger = SFLoggerFactory.getLogger(TelemetryClient.class); - private static final String SF_PATH_TELEMETRY = "/telemetry/send"; private static final String SF_PATH_TELEMETRY_SESSIONLESS = "/telemetry/send/sessionless"; // if the number of cached logs is larger than this threshold, @@ -44,7 +38,6 @@ public class TelemetryClient implements Telemetry { private final String serverUrl; private final String telemetryUrl; - private final SFSession session; private LinkedList logBatch; private static final ObjectMapper mapper = ObjectMapperFactory.getObjectMapper(); @@ -67,23 +60,6 @@ public class TelemetryClient implements Telemetry { // Retry timeout for the HTTP request private static final int TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC = 1000; - private TelemetryClient(SFSession session, int flushSize) { - this.session = session; - this.serverUrl = session.getUrl(); - this.httpClient = null; - - if (this.serverUrl.endsWith("/")) { - this.telemetryUrl = - this.serverUrl.substring(0, this.serverUrl.length() - 1) + SF_PATH_TELEMETRY; - } else { - this.telemetryUrl = this.serverUrl + SF_PATH_TELEMETRY; - } - - this.logBatch = new LinkedList<>(); - this.isClosed = false; - this.forceFlushSize = flushSize; - } - /** * Constructor for creating a sessionless telemetry client * @@ -94,7 +70,6 @@ private TelemetryClient(SFSession session, int flushSize) { */ private TelemetryClient( CloseableHttpClient httpClient, String serverUrl, String authType, int flushSize) { - this.session = null; this.serverUrl = serverUrl; this.httpClient = httpClient; @@ -127,8 +102,7 @@ private TelemetryClient( * @return whether client is enabled */ public boolean isTelemetryEnabled() { - return (this.session == null || this.session.isClientTelemetryEnabled()) - && this.isTelemetryServiceAvailable; + return this.isTelemetryServiceAvailable; } /** Disable any use of the client to add/send metrics */ @@ -137,54 +111,6 @@ public void disableTelemetry() { this.isTelemetryServiceAvailable = false; } - /** - * Initialize the telemetry connector - * - * @param conn connection with the session to use for the connector - * @param flushSize maximum size of telemetry batch before flush - * @return a telemetry connector - */ - public static Telemetry createTelemetry(Connection conn, int flushSize) { - try { - return createTelemetry( - (SFSession) conn.unwrap(SnowflakeConnectionV1.class).getSFBaseSession(), flushSize); - } catch (SQLException ex) { - logger.debug("Input connection is not a SnowflakeConnection", false); - return null; - } - } - - /** - * Initialize the telemetry connector - * - * @param conn connection with the session to use for the connector - * @return a telemetry connector - */ - public static Telemetry createTelemetry(Connection conn) { - return createTelemetry(conn, DEFAULT_FORCE_FLUSH_SIZE); - } - - /** - * Initialize the telemetry connector - * - * @param session session to use for telemetry dumps - * @return a telemetry connector - */ - public static Telemetry createTelemetry(SFSession session) { - return createTelemetry(session, DEFAULT_FORCE_FLUSH_SIZE); - } - - /** - * Initialize the telemetry connector - * - * @param session session to use for telemetry dumps - * @param flushSize maximum size of telemetry batch before flush - * @return a telemetry connector - */ - public static Telemetry createTelemetry(SFSession session, int flushSize) { - return new TelemetryClient(session, flushSize); - } - /** * Initialize the sessionless telemetry connector using KEYPAIR_JWT as the default auth type * @@ -330,14 +256,9 @@ private boolean sendBatch() throws IOException { this.logBatch = new LinkedList<>(); } - if (this.session != null && this.session.isClosed()) { - throw new UnexpectedException("Session is closed when sending log"); - } - if (!tmpList.isEmpty()) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); - // session shared with JDBC String payload = logsToString(tmpList); logger.debugNoMask("Payload of telemetry is : " + payload); @@ -346,35 +267,21 @@ private boolean sendBatch() throws IOException { post.setEntity(new StringEntity(payload)); post.setHeader("Content-type", "application/json"); - if (this.session == null) { - post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.token); - post.setHeader("X-Snowflake-Authorization-Token-Type", this.authType); - post.setHeader(HttpHeaders.ACCEPT, "application/json"); - } else { - post.setHeader( - HttpHeaders.AUTHORIZATION, - "Snowflake Token=\"" + this.session.getSessionToken() + "\""); - } + post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.token); + post.setHeader("X-Snowflake-Authorization-Token-Type", this.authType); + post.setHeader(HttpHeaders.ACCEPT, "application/json"); String response = null; try { response = - this.session == null - ? HttpUtil.executeGeneralRequest( - post, - TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC, - 0, - (int) HttpUtil.getSocketTimeout().toMillis(), - 0, - this.httpClient) - : HttpUtil.executeGeneralRequest( - post, - TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC, - 0, - this.session.getHttpClientSocketTimeout(), - 0, - this.session.getHttpClientKey()); + HttpUtil.executeGeneralRequest( + post, + TELEMETRY_HTTP_RETRY_TIMEOUT_IN_SEC, + 0, + (int) HttpUtil.getSocketTimeout().toMillis(), + 0, + this.httpClient); stopwatch.stop(); logger.debug( "Sending telemetry took {} ms. Batch size: {}", diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java index e4f182f5e..15c4b7c3b 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSAccessStrategyAwsSdk.java @@ -240,7 +240,6 @@ public boolean handleStorageException( throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.S3_OPERATION_ERROR.getMessageCode(), ex1, @@ -254,7 +253,6 @@ public boolean handleStorageException( } else { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.AWS_CLIENT_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java index 8494a2720..c710a1ead 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/GCSDefaultAccessStrategy.java @@ -189,7 +189,6 @@ public boolean handleStorageException( if (retryCount > gcsClient.getMaxRetries()) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.GCP_SERVICE_ERROR.getMessageCode(), se, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergAzureClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergAzureClient.java index 10c8531a2..a2b33b0e1 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergAzureClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergAzureClient.java @@ -308,7 +308,6 @@ private SFPair createUploadStream( } catch (FileNotFoundException ex) { logger.logError("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -317,7 +316,6 @@ private SFPair createUploadStream( } catch (IOException ex) { logger.logError("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -373,7 +371,6 @@ private static void handleAzureException( if (retryCount > azClient.getMaxRetries() || ((StorageException) ex).getHttpStatusCode() == 404) { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.AZURE_SERVICE_ERROR.getMessageCode(), se, @@ -410,7 +407,6 @@ private static void handleAzureException( || StorageClientUtil.getRootCause(ex) instanceof SocketTimeoutException) { if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -424,7 +420,6 @@ private static void handleAzureException( } } else { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergGCSClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergGCSClient.java index 3292581be..6b81cad84 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergGCSClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergGCSClient.java @@ -151,7 +151,6 @@ public String upload( String presignedUrl) throws SnowflakeSQLException { throw new SnowflakeSQLLoggedException( - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, /* session= */ "IcebergGCSClient.upload" + " only works with pre-signed URL."); @@ -324,7 +323,6 @@ private SFPair createUploadStream( } catch (FileNotFoundException ex) { logger.logError("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -333,7 +331,6 @@ private SFPair createUploadStream( } catch (IOException ex) { logger.logError("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -368,7 +365,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati // If we have exceeded the max number of retries, propagate the error if (retryCount > getMaxRetries()) { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.GCP_SERVICE_ERROR.getMessageCode(), se, @@ -403,7 +399,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati || getRootCause(ex) instanceof SocketTimeoutException) { if (retryCount > getMaxRetries()) { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -417,7 +412,6 @@ private void handleStorageException(Exception ex, int retryCount, String operati } } else { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergS3Client.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergS3Client.java index f536f48c0..79f5e1ea5 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergS3Client.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergS3Client.java @@ -356,7 +356,6 @@ public ExecutorService newExecutor() { } throw new SnowflakeSQLLoggedException( - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: upload unsuccessful without exception!"); @@ -433,7 +432,6 @@ private SFPair createUploadStream( } catch (FileNotFoundException ex) { logger.logError("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -442,7 +440,6 @@ private SFPair createUploadStream( } catch (IOException ex) { logger.logError("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -486,7 +483,6 @@ private static void handleS3Exception( // does not return the ExpiredToken error code. // If session is null we cannot renew the token so throw the exception throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.S3_OPERATION_ERROR.getMessageCode(), ex1, @@ -498,7 +494,6 @@ private static void handleS3Exception( extendedRequestId); } else { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.AWS_CLIENT_ERROR.getMessageCode(), ex, @@ -546,7 +541,6 @@ private static void handleS3Exception( || getRootCause(ex) instanceof SocketTimeoutException) { if (retryCount > s3Client.getMaxRetries()) { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -560,7 +554,6 @@ private static void handleS3Exception( } } else { throw new SnowflakeSQLLoggedException( - null /* session */, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergStorageClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergStorageClient.java index 44ab0e116..c659e02bc 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergStorageClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/IcebergStorageClient.java @@ -85,7 +85,6 @@ default String uploadWithPresignedUrlWithoutConnection( String presignedUrl) throws SnowflakeSQLException { throw new SnowflakeSQLLoggedException( - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, /* session= */ "uploadWithPresignedUrlWithoutConnection" diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java index fb3b76c48..6e83c25c6 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeAzureClient.java @@ -133,7 +133,6 @@ private void setupAzureClient(StageInfo stage, RemoteStoreFileEncryptionMaterial if (encryptionKeySize != 128 && encryptionKeySize != 192 && encryptionKeySize != 256) { throw new SnowflakeSQLLoggedException( QueryIdHelper.queryIdFromEncMatOr(encMat, null), - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "unsupported key size", @@ -336,7 +335,6 @@ public void download( if (!userDefinedMetadata.containsKey(AZ_ENCRYPTIONDATAPROP)) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Encryption data not found in the metadata of a file being downloaded"); @@ -350,7 +348,6 @@ public void download( if (key == null || iv == null) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "File metadata incomplete"); @@ -392,7 +389,6 @@ public void download( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -443,7 +439,6 @@ public InputStream downloadToStream( if (!userDefinedMetadata.containsKey(AZ_ENCRYPTIONDATAPROP)) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Encryption data not found in the metadata of a file being downloaded"); @@ -456,7 +451,6 @@ public InputStream downloadToStream( if (key == null || iv == null) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "File metadata incomplete"); @@ -498,7 +492,6 @@ public InputStream downloadToStream( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -701,7 +694,6 @@ private SFPair createUploadStream( logger.error("Failed to encrypt input", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -725,7 +717,6 @@ private SFPair createUploadStream( logger.error("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -735,7 +726,6 @@ private SFPair createUploadStream( logger.error("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -798,7 +788,6 @@ private static void handleAzureException( || ((StorageException) ex).getHttpStatusCode() == 404) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.AZURE_SERVICE_ERROR.getMessageCode(), se, @@ -846,7 +835,6 @@ private static void handleAzureException( if (retryCount > azClient.getMaxRetries()) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -861,7 +849,6 @@ private static void handleAzureException( } else { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -956,7 +943,6 @@ private SimpleEntry parseEncryptionData(String jsonEncryptionDat } catch (Exception ex) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeFileTransferAgent.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeFileTransferAgent.java index 041d859ce..21f82c23b 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeFileTransferAgent.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeFileTransferAgent.java @@ -548,7 +548,6 @@ private static InputStreamWithMetadata compressStreamWithGZIP( throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -589,7 +588,6 @@ private static InputStreamWithMetadata compressStreamWithGZIPNoDigest( throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java index e12e9b5bb..66909b130 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeGCSClient.java @@ -309,7 +309,6 @@ public void download( if (key == null || iv == null) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "File metadata incomplete"); @@ -334,7 +333,6 @@ public void download( logger.error("Error decrypting file", ex); throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Cannot decrypt file"); @@ -356,7 +354,6 @@ public void download( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -506,7 +503,6 @@ public InputStream downloadToStream( logger.error("Error decrypting file", ex); throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Cannot decrypt file"); @@ -528,7 +524,6 @@ public InputStream downloadToStream( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -769,7 +764,6 @@ public void upload( if (uploadFromStream && fileBackedOutputStream == null) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -797,7 +791,6 @@ public void upload( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: upload unsuccessful without exception!"); @@ -843,7 +836,6 @@ private void uploadWithDownScopedToken( wrappedException = new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), e, @@ -932,14 +924,12 @@ private void uploadWithPresignedUrl( } catch (URISyntaxException e) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: upload presigned URL invalid"); } catch (Exception e) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: upload with presigned url failed"); @@ -1002,7 +992,6 @@ private SFPair createUploadStream( logger.error("Failed to encrypt input", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -1026,7 +1015,6 @@ private SFPair createUploadStream( logger.error("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -1036,7 +1024,6 @@ private SFPair createUploadStream( logger.error("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -1072,7 +1059,6 @@ public void handleStorageException( if (retryCount > getMaxRetries()) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -1087,7 +1073,6 @@ public void handleStorageException( } else { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java index 86372196b..4bede51dd 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeS3Client.java @@ -188,7 +188,6 @@ private void setupSnowflakeS3Client( } else { throw new SnowflakeSQLLoggedException( QueryIdHelper.queryIdFromEncMatOr(encMat, null), - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "unsupported key size", @@ -373,7 +372,6 @@ public ExecutorService newExecutor() { if (key == null || iv == null) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "File metadata incomplete"); @@ -420,7 +418,6 @@ public ExecutorService newExecutor() { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -471,7 +468,6 @@ public InputStream downloadToStream( if (key == null || iv == null) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "File metadata incomplete"); @@ -510,7 +506,6 @@ public InputStream downloadToStream( throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: download unsuccessful without exception!"); @@ -673,7 +668,6 @@ public ExecutorService newExecutor() { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, "Unexpected: upload unsuccessful without exception!"); @@ -721,7 +715,6 @@ private SFPair createUploadStream( logger.error("Failed to encrypt input", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -748,7 +741,6 @@ private SFPair createUploadStream( logger.error("Failed to open input file", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -758,7 +750,6 @@ private SFPair createUploadStream( logger.error("Failed to open input stream", ex); throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.INTERNAL_ERROR, ErrorCode.INTERNAL_ERROR.getMessageCode(), ex, @@ -813,7 +804,6 @@ private static void handleS3Exception( throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.S3_OPERATION_ERROR.getMessageCode(), ex1, @@ -827,7 +817,6 @@ private static void handleS3Exception( } else { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.AWS_CLIENT_ERROR.getMessageCode(), ex, @@ -876,7 +865,6 @@ private static void handleS3Exception( if (retryCount > s3Client.getMaxRetries()) { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, @@ -891,7 +879,6 @@ private static void handleS3Exception( } else { throw new SnowflakeSQLLoggedException( queryId, - null, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedException.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedException.java index ab5c9a7f9..f0788a710 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedException.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedException.java @@ -3,34 +3,21 @@ * Source: https://github.com/snowflakedb/snowflake-jdbc/blob/v3.25.1/src/main/java/net/snowflake/client/jdbc/SnowflakeSQLLoggedException.java * * Permitted differences: package, SFLogger/isNullOrEmpty/ErrorCode/SnowflakeSQLException use - * ingest versions. OOB telemetry imports swapped to ingest replicated versions: - * ObjectMapperFactory/SqlState/TelemetryEvent/TelemetryService use ingest versions (same package). - * LoginInfoDTO.SF_JDBC_APP_ID/SnowflakeDriver.implementVersion → SnowflakeDriverConstants. - * IB telemetry imports (Telemetry/TelemetryField/TelemetryUtil) kept from JDBC — they interact - * with session.getTelemetryClient() which returns JDBC types. - * SFBaseSession/SFSession/SFException kept from JDBC temporarily (parameter types). + * ingest versions. All telemetry imports swapped to ingest replicated versions. + * SFSession/SFBaseSession removed (always null from callers). IB telemetry code removed + * (dead code — session was always null so ibInstance was always null, only OOB path executed). */ package net.snowflake.ingest.streaming.internal.fileTransferAgent; import static net.snowflake.ingest.streaming.internal.fileTransferAgent.StorageClientUtil.isNullOrEmpty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.SQLException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.minidev.json.JSONObject; -import net.snowflake.client.core.SFBaseSession; -import net.snowflake.client.core.SFSession; -import net.snowflake.client.jdbc.telemetry.Telemetry; -import net.snowflake.client.jdbc.telemetry.TelemetryField; -import net.snowflake.client.jdbc.telemetry.TelemetryUtil; +import net.snowflake.ingest.connection.telemetry.TelemetryField; import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLogger; import net.snowflake.ingest.streaming.internal.fileTransferAgent.log.SFLoggerFactory; @@ -43,13 +30,12 @@ public class SnowflakeSQLLoggedException extends SnowflakeSQLException { private static final SFLogger logger = SFLoggerFactory.getLogger(SnowflakeSQLLoggedException.class); - private static final ObjectMapper mapper = ObjectMapperFactory.getObjectMapper(); private static final int NO_VENDOR_CODE = -1; public SnowflakeSQLLoggedException( - String queryID, SFSession session, String sqlState, String message, Exception cause) { + String queryID, String sqlState, String message, Exception cause) { super(queryID, cause, sqlState, NO_VENDOR_CODE, message); - sendTelemetryData(queryID, sqlState, NO_VENDOR_CODE, session, this); + sendTelemetryData(queryID, sqlState, NO_VENDOR_CODE, this); } /** @@ -75,37 +61,6 @@ private static void sendOutOfBandTelemetryMessage( oobInstance.report(log); } - /** - * Function to create a TelemetryClient log and send it via in-band telemetry - * - * @param value ObjectNode containing information specific to the exception constructor that - * should be included in the telemetry log, such as SQLState or reason for the error - * @param ex The exception being thrown - * @param ibInstance Telemetry instance through which telemetry log will be sent - * @return true if in-band telemetry log sent successfully or false if it did not - */ - private static Future sendInBandTelemetryMessage( - ObjectNode value, SQLException ex, Telemetry ibInstance) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - ex.printStackTrace(pw); - String stackTrace = maskStacktrace(sw.toString()); - value.put("Stacktrace", stackTrace); - value.put("Exception", ex.getClass().getSimpleName()); - // For SQLFeatureNotSupportedExceptions, add in reason for failure as " not - // supported" - if (value.get("SQLState").toString().contains(SqlState.FEATURE_NOT_SUPPORTED)) { - String reason = ""; - StackTraceElement[] stackTraceArray = ex.getStackTrace(); - if (stackTraceArray.length >= 1) { - reason = ex.getStackTrace()[0].getMethodName() + " not supported"; - } - value.put("reason", reason); - } - ibInstance.addLogToBatch(TelemetryUtil.buildJobData(value)); - return ibInstance.sendBatchAsync(); - } - /** * Helper function to remove sensitive data (error message, reason) from the stacktrace. * @@ -152,271 +107,157 @@ static JSONObject createOOBValue(String queryId, String SQLState, int vendorCode } /** - * Helper function to create ObjectNode for IB telemetry log - * - * @param queryId query ID - * @param SQLState the SQL state - * @param vendorCode the vendor code - * @return ObjectNode for IB telemetry log - */ - static ObjectNode createIBValue(String queryId, String SQLState, int vendorCode) { - ObjectNode ibValue = mapper.createObjectNode(); - ibValue.put("type", TelemetryField.SQL_EXCEPTION.toString()); - ibValue.put("DriverType", SnowflakeDriverConstants.SF_JDBC_APP_ID); - ibValue.put("DriverVersion", SnowflakeDriverConstants.implementVersion); - if (!isNullOrEmpty(queryId)) { - ibValue.put("QueryID", queryId); - } - if (!isNullOrEmpty(SQLState)) { - ibValue.put("SQLState", SQLState); - } - if (vendorCode != NO_VENDOR_CODE) { - ibValue.put("ErrorNumber", vendorCode); - } - return ibValue; - } - - /** - * Function to construct log data based on possible exception inputs and send data through in-band - * telemetry, or oob if in-band does not work + * Function to construct log data and send via OOB telemetry. * * @param queryId query ID if exists * @param SQLState SQLState * @param vendorCode vendor code - * @param session session object, which is needed to send in-band telemetry but not oob. Might be - * null, in which case oob is used. * @param ex Exception object */ public static void sendTelemetryData( - String queryId, String SQLState, int vendorCode, SFBaseSession session, SQLException ex) { - Telemetry ibInstance = null; - // if session is not null, try sending data using in-band telemetry - if (session != null) { - ibInstance = session.getTelemetryClient(); - } - // if in-band instance is successfully created, compile sql exception data into an in-band - // telemetry log - if (ibInstance != null) { - ObjectNode ibValue = createIBValue(queryId, SQLState, vendorCode); - // try to send in-band data asynchronously - ExecutorService threadExecutor = Executors.newSingleThreadExecutor(); - Telemetry finalIbInstance = ibInstance; - try { - threadExecutor.submit( - () -> { - boolean inBandSuccess; - Future sendInBand = sendInBandTelemetryMessage(ibValue, ex, finalIbInstance); - // record whether in band telemetry message sent with boolean value inBandSuccess - try { - inBandSuccess = sendInBand.get(10, TimeUnit.SECONDS); - } catch (Exception e) { - inBandSuccess = false; - } - // In-band failed so send OOB telemetry instead - if (!inBandSuccess) { - logger.debug( - "In-band telemetry message failed to send. Sending out-of-band message" - + " instead"); - JSONObject oobValue = createOOBValue(queryId, SQLState, vendorCode); - sendOutOfBandTelemetryMessage(oobValue, ex, TelemetryService.getInstance()); - } - }); - } finally { - // Send the shutdown signal to the executor service - threadExecutor.shutdown(); - - // Add an extra hook in the telemetry client, if extra error handling is needed - ibInstance.postProcess(queryId, SQLState, vendorCode, ex); - } - } - // In-band is not possible so send OOB telemetry instead - else { - JSONObject oobValue = createOOBValue(queryId, SQLState, vendorCode); - sendOutOfBandTelemetryMessage(oobValue, ex, TelemetryService.getInstance()); - } + String queryId, String SQLState, int vendorCode, SQLException ex) { + JSONObject oobValue = createOOBValue(queryId, SQLState, vendorCode); + sendOutOfBandTelemetryMessage(oobValue, ex, TelemetryService.getInstance()); } /** - * @param session SFBaseSession * @param reason exception reason * @param SQLState the SQL state * @param vendorCode the vendor code * @param queryId the query ID */ public SnowflakeSQLLoggedException( - SFBaseSession session, String reason, String SQLState, int vendorCode, String queryId) { + String reason, String SQLState, int vendorCode, String queryId) { super(queryId, reason, SQLState, vendorCode); - sendTelemetryData(queryId, SQLState, vendorCode, session, this); + sendTelemetryData(queryId, SQLState, vendorCode, this); } /** - * @param session SFBaseSession * @param vendorCode the vendor code * @param SQLState the SQL state */ - public SnowflakeSQLLoggedException(SFBaseSession session, int vendorCode, String SQLState) { + public SnowflakeSQLLoggedException(int vendorCode, String SQLState) { super(SQLState, vendorCode); - sendTelemetryData(null, SQLState, vendorCode, session, this); + sendTelemetryData(null, SQLState, vendorCode, this); } /** * @param queryId the query ID - * @param session SFBaseSession * @param vendorCode the vendor code * @param SQLState the SQL state */ - public SnowflakeSQLLoggedException( - String queryId, SFBaseSession session, int vendorCode, String SQLState) { + public SnowflakeSQLLoggedException(String queryId, int vendorCode, String SQLState) { super(queryId, SQLState, vendorCode); - sendTelemetryData(queryId, SQLState, vendorCode, session, this); - } - - /** - * use {@link SnowflakeSQLLoggedException#SnowflakeSQLLoggedException(String, SFBaseSession, - * String, String)} - * - * @param session SFBaseSession - * @param SQLState the SQL state - * @param reason exception reason - */ - @Deprecated - public SnowflakeSQLLoggedException(SFBaseSession session, String SQLState, String reason) { - this(null, session, SQLState, reason); + sendTelemetryData(queryId, SQLState, vendorCode, this); } /** * @param queryId the query ID - * @param session SFBaseSession * @param SQLState the SQL state * @param reason the exception reason */ - public SnowflakeSQLLoggedException( - String queryId, SFBaseSession session, String SQLState, String reason) { + public SnowflakeSQLLoggedException(String queryId, String SQLState, String reason) { super(reason, SQLState); - sendTelemetryData(queryId, SQLState, NO_VENDOR_CODE, session, this); + sendTelemetryData(queryId, SQLState, NO_VENDOR_CODE, this); } /** - * @param session SFBaseSession * @param vendorCode the vendor code * @param SQLState the SQL state * @param params additional parameters */ - public SnowflakeSQLLoggedException( - SFBaseSession session, int vendorCode, String SQLState, Object... params) { - this(null, session, vendorCode, SQLState, params); + public SnowflakeSQLLoggedException(int vendorCode, String SQLState, Object... params) { + this(null, vendorCode, SQLState, params); } /** * @param queryId the query ID - * @param session SFBaseSession * @param vendorCode the vendor code * @param SQLState the SQL state * @param params additional parameters */ public SnowflakeSQLLoggedException( - String queryId, SFBaseSession session, int vendorCode, String SQLState, Object... params) { + String queryId, int vendorCode, String SQLState, Object... params) { super(queryId, SQLState, vendorCode, params); - sendTelemetryData(queryId, SQLState, vendorCode, session, this); + sendTelemetryData(queryId, SQLState, vendorCode, this); } /** - * @param session SFBaseSession * @param errorCode the error code * @param ex Throwable exception * @param params additional parameters */ - public SnowflakeSQLLoggedException( - SFBaseSession session, ErrorCode errorCode, Throwable ex, Object... params) { + public SnowflakeSQLLoggedException(ErrorCode errorCode, Throwable ex, Object... params) { super(ex, errorCode, params); - sendTelemetryData(null, errorCode.getSqlState(), errorCode.getMessageCode(), session, this); + sendTelemetryData(null, errorCode.getSqlState(), errorCode.getMessageCode(), this); } /** - * @param session SFBaseSession * @param SQLState the SQL state * @param vendorCode the vendor code * @param ex Throwable exception * @param params additional parameters */ public SnowflakeSQLLoggedException( - SFBaseSession session, String SQLState, int vendorCode, Throwable ex, Object... params) { + String SQLState, int vendorCode, Throwable ex, Object... params) { super(ex, SQLState, vendorCode, params); - sendTelemetryData(null, SQLState, vendorCode, session, this); + sendTelemetryData(null, SQLState, vendorCode, this); } /** * @param queryId the query ID - * @param session SFBaseSession * @param SQLState the SQL state * @param vendorCode the vendor code * @param ex Throwable exception * @param params additional parameters */ public SnowflakeSQLLoggedException( - String queryId, - SFBaseSession session, - String SQLState, - int vendorCode, - Throwable ex, - Object... params) { + String queryId, String SQLState, int vendorCode, Throwable ex, Object... params) { super(queryId, ex, SQLState, vendorCode, params); - sendTelemetryData(queryId, SQLState, vendorCode, session, this); + sendTelemetryData(queryId, SQLState, vendorCode, this); } /** - * use {@link SnowflakeSQLLoggedException#SnowflakeSQLLoggedException(String, SFBaseSession, - * ErrorCode, Object...)} - * - * @param session SFBaseSession * @param errorCode the error code * @param params additional parameters */ @Deprecated - public SnowflakeSQLLoggedException(SFBaseSession session, ErrorCode errorCode, Object... params) { - this(null, session, errorCode, params); + public SnowflakeSQLLoggedException(ErrorCode errorCode, Object... params) { + this(null, errorCode, params); } /** * @param queryId the query ID - * @param session SFBaseSession * @param errorCode the error code * @param params additional parameters */ - public SnowflakeSQLLoggedException( - String queryId, SFBaseSession session, ErrorCode errorCode, Object... params) { + public SnowflakeSQLLoggedException(String queryId, ErrorCode errorCode, Object... params) { super(queryId, errorCode, params); - sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this); + sendTelemetryData(queryId, null, NO_VENDOR_CODE, this); } /** - * @param session SFBaseSession * @param e throwable exception */ - public SnowflakeSQLLoggedException(SFBaseSession session, SFException e) { + public SnowflakeSQLLoggedException(SFException e) { super(e); - sendTelemetryData(null, null, NO_VENDOR_CODE, session, this); + sendTelemetryData(null, null, NO_VENDOR_CODE, this); } /** - * use {@link SnowflakeSQLLoggedException#SnowflakeSQLLoggedException(String, SFBaseSession, - * String)} - * - * @param session SFBaseSession * @param reason exception reason */ @Deprecated - public SnowflakeSQLLoggedException(SFBaseSession session, String reason) { - this(null, session, reason); + public SnowflakeSQLLoggedException(String reason) { + this(null, (String) null, reason); } /** * @param queryId the query ID - * @param session SFBaseSession * @param reason exception reason */ - public SnowflakeSQLLoggedException(String queryId, SFBaseSession session, String reason) { + public SnowflakeSQLLoggedException(String queryId, String reason) { super(queryId, reason, null); - sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this); + sendTelemetryData(queryId, null, NO_VENDOR_CODE, this); } } diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java index b7dc6dfdb..e50355f00 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeStorageClient.java @@ -308,7 +308,6 @@ default void uploadWithPresignedUrlWithoutConnection( if (!requirePresignedUrl()) { throw new SnowflakeSQLLoggedException( queryId, - null, ErrorCode.INTERNAL_ERROR.getMessageCode(), SqlState.INTERNAL_ERROR, /* session= */ "uploadWithPresignedUrlWithoutConnection" diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java index 67d20c0dd..5ef4c408e 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/StorageClientUtil.java @@ -253,7 +253,6 @@ static void throwNoSpaceLeftError( if (exMessage != null && exMessage.equals(NO_SPACE_LEFT_ON_DEVICE_ERR)) { throw new SnowflakeSQLLoggedException( queryId, - session, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), ex, diff --git a/src/test/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedExceptionTest.java b/src/test/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedExceptionTest.java index 057fb28f4..69ee37f1e 100644 --- a/src/test/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedExceptionTest.java +++ b/src/test/java/net/snowflake/ingest/streaming/internal/fileTransferAgent/SnowflakeSQLLoggedExceptionTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import com.fasterxml.jackson.databind.node.ObjectNode; import net.minidev.json.JSONObject; import org.junit.Test; @@ -14,16 +13,16 @@ public class SnowflakeSQLLoggedExceptionTest { @Test public void testConstructorWithNullSession() { // All ingest callers pass null for session — this is the primary usage - SnowflakeSQLLoggedException ex = new SnowflakeSQLLoggedException(null, 200016, "58000"); + SnowflakeSQLLoggedException ex = new SnowflakeSQLLoggedException(200016, "58000"); assertNotNull(ex.getMessage()); assertEquals("58000", ex.getSQLState()); assertEquals(200016, ex.getErrorCode()); } @Test - public void testConstructorWithNullSessionAndParams() { + public void testConstructorWithParams() { SnowflakeSQLLoggedException ex = - new SnowflakeSQLLoggedException(null, 200001, "22000", "test detail"); + new SnowflakeSQLLoggedException(200001, "22000", "test detail"); assertNotNull(ex.getMessage()); assertTrue(ex.getMessage().contains("test detail")); } @@ -31,22 +30,21 @@ public void testConstructorWithNullSessionAndParams() { @Test public void testConstructorWithErrorCode() { SnowflakeSQLLoggedException ex = - new SnowflakeSQLLoggedException(null, ErrorCode.IO_ERROR, new RuntimeException("cause")); + new SnowflakeSQLLoggedException(ErrorCode.IO_ERROR, new RuntimeException("cause")); assertEquals(ErrorCode.IO_ERROR.getSqlState(), ex.getSQLState()); assertNotNull(ex.getCause()); } @Test public void testConstructorWithQueryId() { - SnowflakeSQLLoggedException ex = - new SnowflakeSQLLoggedException("qid-456", null, 200016, "58000"); + SnowflakeSQLLoggedException ex = new SnowflakeSQLLoggedException("qid-456", 200016, "58000"); assertEquals("qid-456", ex.getQueryId()); assertEquals("58000", ex.getSQLState()); } @Test public void testExtendsSnowflakeSQLException() { - SnowflakeSQLLoggedException ex = new SnowflakeSQLLoggedException(null, 200016, "58000"); + SnowflakeSQLLoggedException ex = new SnowflakeSQLLoggedException(200016, "58000"); assertTrue(ex instanceof SnowflakeSQLException); } @@ -91,21 +89,4 @@ public void testCreateOOBValueNoVendorCode() { // NO_VENDOR_CODE (-1) should not be included assertTrue(!value.containsKey("ErrorNumber")); } - - @Test - public void testCreateIBValue() { - ObjectNode value = SnowflakeSQLLoggedException.createIBValue("qid-2", "22000", 200001); - assertEquals("client_sql_exception", value.get("type").asText()); - assertEquals("qid-2", value.get("QueryID").asText()); - assertEquals("22000", value.get("SQLState").asText()); - assertEquals(200001, value.get("ErrorNumber").asInt()); - } - - @Test - public void testCreateIBValueNullFields() { - ObjectNode value = SnowflakeSQLLoggedException.createIBValue(null, null, -1); - assertTrue(!value.has("QueryID")); - assertTrue(!value.has("SQLState")); - assertTrue(!value.has("ErrorNumber")); - } }