Skip to content

Commit

Permalink
Merge branch 'master' into Snow-1213120-Reuse-Connections-4
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jf authored Oct 23, 2024
2 parents 352ac3f + e609432 commit 3086a81
Show file tree
Hide file tree
Showing 34 changed files with 411 additions and 166 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
**JDBC Driver 3.19.1**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc

**JDBC Driver 3.19.0**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
Expand Down
22 changes: 5 additions & 17 deletions FIPS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@
<parent>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.1</version>
<version>3.19.1-SNAPSHOT</version>
<relativePath>../parent-pom.xml</relativePath>
</parent>

<artifactId>snowflake-jdbc-fips</artifactId>
<version>3.19.1</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>snowflake-jdbc-fips</name>
<url>http://maven.apache.org</url>

<repositories>
<repository>
<id>Central</id>
<name>Internal Central Repo2</name>
<layout>default</layout>
<url>https://artifactory.ci1.us-west-2.aws-dev.app.snowflake.com/artifactory/development-maven-virtual/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<prerequisites>
<maven>3.3.9</maven>
</prerequisites>
Expand Down Expand Up @@ -608,15 +596,15 @@
<unzip dest="${project.build.directory}/relocate" src="${project.build.directory}/${project.build.finalName}.jar"/>
<mkdir dir="${project.build.directory}/relocate/META-INF/versions/11/${relocationBase}"/>
<mkdir dir="${project.build.directory}/relocate/META-INF/versions/17/${relocationBase}"/>
<mkdir dir="${project.build.directory}/relocate/META-INF/versions/19/${relocationBase}"/>
<mkdir dir="${project.build.directory}/relocate/META-INF/versions/21/${relocationBase}"/>
<!-- com.fasterxml.* packages are relocated to ${relocationBase}.fasterxml.* -->
<move file="${project.build.directory}/relocate/META-INF/versions/11/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/11/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/17/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/17/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/19/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/19/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/21/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/21/${relocationBase}"/>
<zip basedir="${project.build.directory}/relocate" destfile="${project.build.directory}/${project.build.finalName}.jar"/>
<delete dir="${project.build.directory}/relocate/META-INF/versions/11/${relocationBase}"/>
<delete dir="${project.build.directory}/relocate/META-INF/versions/17/${relocationBase}"/>
<delete dir="${project.build.directory}/relocate/META-INF/versions/19/${relocationBase}"/>
<delete dir="${project.build.directory}/relocate/META-INF/versions/21/${relocationBase}"/>
</target>
</configuration>
</execution>
Expand Down
4 changes: 2 additions & 2 deletions FIPS/public_pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</scm>

<properties>
<bouncycastle.bcfips.version>1.0.2.4</bouncycastle.bcfips.version>
<bouncycastle.bcpkixfips.version>1.0.5</bouncycastle.bcpkixfips.version>
<bouncycastle.bcfips.version>1.0.2.5</bouncycastle.bcfips.version>
<bouncycastle.bcpkixfips.version>1.0.7</bouncycastle.bcpkixfips.version>
<jna.version>5.13.0</jna.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion dependencies/Readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Arrow dependencies are built from internal branch `upgradeto17.0.0`. This build was applied the AIX fix.
Arrow dependencies are built from internal branch `upgradeTo17.0.0-v2`. This build was applied the AIX fix and the customer logger instead of slf4j logger.

Binary file modified dependencies/arrow-format-17.0.0.jar
Binary file not shown.
Binary file modified dependencies/arrow-memory-core-17.0.0.jar
Binary file not shown.
Binary file modified dependencies/arrow-memory-netty-buffer-patch-17.0.0.jar
Binary file not shown.
Binary file modified dependencies/arrow-memory-unsafe-17.0.0.jar
Binary file not shown.
Binary file modified dependencies/arrow-vector-17.0.0.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions linkage-checker-exclusion-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
<Source><Package name="org.bouncycastle.pkix"/></Source>
<Reason>?</Reason>
</LinkageError>
<LinkageError>
<Target><Package name="java.nio"/></Target>
<Source><Package name="org.bouncycastle.jcajce.provider.symmetric.util"/></Source>
<Reason>?</Reason>
</LinkageError>
<LinkageError>
<Target><Package name="java.nio"/></Target>
<Source><Package name="org.bouncycastle.pqc.legacy.crypto.ntru"/></Source>
<Reason>?</Reason>
</LinkageError>
<!--
<LinkageError>
<Target><Package name=""/></Target>
Expand Down
14 changes: 10 additions & 4 deletions parent-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.1</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand All @@ -25,9 +25,9 @@
<awaitility.version>4.2.0</awaitility.version>
<awssdk.version>1.12.655</awssdk.version>
<azure.storage.version>5.0.0</azure.storage.version>
<bouncycastle.version>1.74</bouncycastle.version>
<bouncycastle.bcfips.version>1.0.2.4</bouncycastle.bcfips.version>
<bouncycastle.bcpkixfips.version>1.0.5</bouncycastle.bcpkixfips.version>
<bouncycastle.version>1.78.1</bouncycastle.version>
<bouncycastle.bcfips.version>1.0.2.5</bouncycastle.bcfips.version>
<bouncycastle.bcpkixfips.version>1.0.7</bouncycastle.bcpkixfips.version>
<bytebuddy.version>1.14.17</bytebuddy.version>
<classworlds.version>1.1</classworlds.version>
<checkerframework.version>3.33.0</checkerframework.version>
Expand Down Expand Up @@ -448,6 +448,12 @@
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<!-- for non-FIPS JAR -->
<groupId>org.bouncycastle</groupId>
<artifactId>bcutil-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<!-- for FIPS JAR -->
<groupId>org.bouncycastle</groupId>
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.1</version>
<version>3.19.1-SNAPSHOT</version>
<relativePath>./parent-pom.xml</relativePath>
</parent>

<!-- Maven complains about using property here, but it makes install and deploy process easier to override final package names and localization -->
<artifactId>${artifactId}</artifactId>
<version>3.19.1</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${artifactId}</name>
Expand All @@ -36,6 +36,10 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcutil-jdk18on</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -1031,6 +1035,7 @@
<move file="${project.build.directory}/relocate/META-INF/versions/9/org" todir="${project.build.directory}/relocate/META-INF/versions/9/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/11/org" todir="${project.build.directory}/relocate/META-INF/versions/11/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/15/org" todir="${project.build.directory}/relocate/META-INF/versions/15/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/21/org" todir="${project.build.directory}/relocate/META-INF/versions/21/${relocationBase}"/>
<!-- com.fasterxml.* packages are relocated to ${relocationBase}.fasterxml.* -->
<move file="${project.build.directory}/relocate/META-INF/versions/11/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/11/${relocationBase}"/>
<move file="${project.build.directory}/relocate/META-INF/versions/17/com/fasterxml" todir="${project.build.directory}/relocate/META-INF/versions/17/${relocationBase}"/>
Expand Down Expand Up @@ -1105,7 +1110,7 @@
<!--
Downloading
1. japicmp
2. maven-dependency-lugin analyst
2. maven-dependency-plugin analyst
in jenkins node would cause http connection failure. Temporarily disable them.
-->
<plugin>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/snowflake/client/core/CancellationReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc. All rights reserved.
*/
package net.snowflake.client.core;

@SnowflakeJdbcInternalApi
public enum CancellationReason {
UNKNOWN,
CLIENT_REQUESTED,
TIMEOUT
}
14 changes: 14 additions & 0 deletions src/main/java/net/snowflake/client/core/SFBaseStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,23 @@ public abstract SFBaseResultSet asyncExecute(
*
* @throws SFException if the statement is already closed.
* @throws SQLException if there are server-side errors from trying to abort.
* @deprecated use {@link #cancel(CancellationReason)} instead
*/
@Deprecated
public abstract void cancel() throws SFException, SQLException;

/**
* Aborts the statement.
*
* @param cancellationReason reason for the cancellation
* @throws SFException if the statement is already closed.
* @throws SQLException if there are server-side errors from trying to abort.
*/
@SnowflakeJdbcInternalApi
public void cancel(CancellationReason cancellationReason) throws SFException, SQLException {
cancel(); // default cancel is called to keep interface backward compatibility
}

/**
* Sets a property within session properties, i.e., if the sql is using set-sf-property
*
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/snowflake/client/core/SFLoginOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SFLoginOutput {
private int databaseMajorVersion;
private int databaseMinorVersion;
private Duration httpClientSocketTimeout;
private Duration httpClientConnectionTimeout;
private String sessionDatabase;
private String sessionSchema;
private String sessionRole;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class SFLoginOutput {
this.databaseMajorVersion = databaseMajorVersion;
this.databaseMinorVersion = databaseMinorVersion;
this.httpClientSocketTimeout = Duration.ofMillis(httpClientSocketTimeout);
this.httpClientConnectionTimeout = Duration.ofMillis(httpClientConnectionTimeout);
this.sessionDatabase = sessionDatabase;
this.sessionSchema = sessionSchema;
this.sessionRole = sessionRole;
Expand Down Expand Up @@ -113,7 +115,7 @@ Duration getHttpClientSocketTimeout() {
}

Duration getHttpClientConnectionTimeout() {
return httpClientSocketTimeout;
return httpClientConnectionTimeout;
}

Map<String, Object> getCommonParams() {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/snowflake/client/core/SFStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private TimeBombTask(SFStatement statement) {
@Override
public Void call() throws SQLException {
try {
statement.cancel();
statement.cancel(CancellationReason.TIMEOUT);
} catch (SFException ex) {
throw new SnowflakeSQLLoggedException(
session, ex.getSqlState(), ex.getVendorCode(), ex, ex.getParams());
Expand Down Expand Up @@ -711,10 +711,11 @@ private void reauthenticate() throws SFException, SnowflakeSQLException {
*
* @param sql sql statement
* @param mediaType media type
* @param cancellationReason reason for the cancellation
* @throws SnowflakeSQLException if failed to cancel the statement
* @throws SFException if statement is already closed
*/
private void cancelHelper(String sql, String mediaType)
private void cancelHelper(String sql, String mediaType, CancellationReason cancellationReason)
throws SnowflakeSQLException, SFException {
synchronized (this) {
if (isClosed) {
Expand All @@ -734,7 +735,7 @@ private void cancelHelper(String sql, String mediaType)
.setMaxRetries(session.getMaxHttpRetries())
.setHttpClientSettingsKey(session.getHttpClientKey());

StmtUtil.cancel(stmtInput);
StmtUtil.cancel(stmtInput, cancellationReason);

synchronized (this) {
/*
Expand Down Expand Up @@ -842,6 +843,12 @@ public void close() {
@Override
public void cancel() throws SFException, SQLException {
logger.trace("void cancel()", false);
cancel(CancellationReason.UNKNOWN);
}

@Override
public void cancel(CancellationReason cancellationReason) throws SFException, SQLException {
logger.trace("void cancel(CancellationReason)", false);

if (canceling.get()) {
logger.debug("Query is already cancelled", false);
Expand All @@ -866,7 +873,7 @@ public void cancel() throws SFException, SQLException {
}

// cancel the query on the server side if it has been issued
cancelHelper(this.sqlText, StmtUtil.SF_MEDIA_TYPE);
cancelHelper(this.sqlText, StmtUtil.SF_MEDIA_TYPE, cancellationReason);
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/snowflake/client/core/StmtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,23 @@ protected static JsonNode getQueryResultJSON(String queryId, SFSession session)
* @param stmtInput input statement
* @throws SFException if there is an internal exception
* @throws SnowflakeSQLException if failed to cancel the statement
* @deprecated use {@link #cancel(StmtInput, CancellationReason)} instead
*/
@Deprecated
public static void cancel(StmtInput stmtInput) throws SFException, SnowflakeSQLException {
cancel(stmtInput, CancellationReason.UNKNOWN);
}

/**
* Cancel a statement identifiable by a request id
*
* @param stmtInput input statement
* @param cancellationReason reason for the cancellation
* @throws SFException if there is an internal exception
* @throws SnowflakeSQLException if failed to cancel the statement
*/
public static void cancel(StmtInput stmtInput, CancellationReason cancellationReason)
throws SFException, SnowflakeSQLException {
HttpPost httpRequest = null;

AssertUtil.assertTrue(
Expand All @@ -701,7 +716,7 @@ public static void cancel(StmtInput stmtInput) throws SFException, SnowflakeSQLE

try {
URIBuilder uriBuilder = new URIBuilder(stmtInput.serverUrl);

logger.warn("Cancelling query {} with reason {}", stmtInput.requestId, cancellationReason);
logger.debug("Aborting query: {}", stmtInput.sql);

uriBuilder.setPath(SF_PATH_ABORT_REQUEST_V1);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/net/snowflake/client/jdbc/RestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,14 @@ public static CloseableHttpResponse execute(
// if an SSL issue occurs like an SSLHandshakeException then fail
// immediately and stop retrying the requests

throw new SnowflakeSQLLoggedException(null, ErrorCode.NETWORK_ERROR, ex, ex.getMessage());
String formattedMsg =
ex.getMessage()
+ "\n"
+ "Verify that the hostnames and portnumbers in SYSTEM$ALLOWLIST are added to your firewall's allowed list.\n"
+ "To troubleshoot your connection further, you can refer to this article:\n"
+ "https://docs.snowflake.com/en/user-guide/client-connectivity-troubleshooting/overview";

throw new SnowflakeSQLLoggedException(null, ErrorCode.NETWORK_ERROR, ex, formattedMsg);

} catch (Exception ex) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ private void uploadStream() throws SnowflakeSQLException {
/** Download a file from remote, and return an input stream */
@Override
public InputStream downloadStream(String fileName) throws SnowflakeSQLException {
logger.debug("Downloading file as stream: {}", fileName);
if (stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS) {
logger.error("downloadStream function doesn't support local file system", false);

Expand All @@ -1662,14 +1663,32 @@ public InputStream downloadStream(String fileName) throws SnowflakeSQLException

remoteLocation remoteLocation = extractLocationAndPath(stageInfo.getLocation());

String stageFilePath = fileName;
// when downloading files as stream there should be only one file in source files
String sourceLocation =
sourceFiles.stream()
.findFirst()
.orElseThrow(
() ->
new SnowflakeSQLException(
queryID,
SqlState.NO_DATA,
ErrorCode.FILE_NOT_FOUND.getMessageCode(),
session,
"File not found: " + fileName));

if (!fileName.equals(sourceLocation)) {
// filename may be different from source location e.g. in git repositories
logger.debug("Changing file to download location from {} to {}", fileName, sourceLocation);
}
String stageFilePath = sourceLocation;

if (!remoteLocation.path.isEmpty()) {
stageFilePath = SnowflakeUtil.concatFilePathNames(remoteLocation.path, fileName, "/");
stageFilePath = SnowflakeUtil.concatFilePathNames(remoteLocation.path, sourceLocation, "/");
}
logger.debug("Stage file path for {} is {}", sourceLocation, stageFilePath);

RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(fileName);
String presignedUrl = srcFileToPresignedUrl.get(fileName);
RemoteStoreFileEncryptionMaterial encMat = srcFileToEncMat.get(sourceLocation);
String presignedUrl = srcFileToPresignedUrl.get(sourceLocation);

return storageFactory
.createClient(stageInfo, parallel, encMat, session)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.snowflake.client.core.CancellationReason;
import net.snowflake.client.core.ExecTimeTelemetryData;
import net.snowflake.client.core.ParameterBindingDTO;
import net.snowflake.client.core.ResultUtil;
Expand Down Expand Up @@ -952,7 +953,7 @@ public void cancel() throws SQLException {
raiseSQLExceptionIfStatementIsClosed();

try {
sfBaseStatement.cancel();
sfBaseStatement.cancel(CancellationReason.CLIENT_REQUESTED);
} catch (SFException ex) {
throw new SnowflakeSQLException(ex, ex.getSqlState(), ex.getVendorCode(), ex.getParams());
}
Expand Down
Loading

0 comments on commit 3086a81

Please sign in to comment.