Skip to content

Commit

Permalink
Improved driver performance when closing statements with partially re…
Browse files Browse the repository at this point in the history
…ad results
  • Loading branch information
bhvkshah committed Dec 13, 2023
1 parent 3c5fcf8 commit befa7de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public RedshiftConnectionImpl(HostSpec[] hostSpecs,
{
String iamCredentialProvider = RedshiftConnectionImpl.getOptionalConnSetting(
RedshiftProperty.CREDENTIALS_PROVIDER.getName(), info);
if(iamCredentialProvider != null && iamCredentialProvider.equalsIgnoreCase(RedshiftConstants.IDP_TOKEN_PLUGIN)) {
throw new RedshiftException(GT.tr("You can not use this authentication plugin with IAM enabled."),
RedshiftState.UNEXPECTED_ERROR);
}

if (sslExplicitlyDisabled) {
throw new RedshiftException(GT.tr("SSL should be enable in IAM authentication."),
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/com/amazon/redshift/jdbc/RedshiftStatementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,6 @@ public final void close() throws SQLException
isClosed = true;
}

// The user has closed the statement and does not want to read any more results. We send a cancellation request to
// the server. It is possible to have a situation where if the driver's ring buffer is not
// reading from the stream and the server's send buffer is full. The server treats this as a client side hang and
// closes the connection. To avoid this, we start reading from the stream again, but we throw away the rows we read
// because the user no longer needs them. Note, this is a temporary fix until a permanent server-side fix can be
// provided.
resumeReadAndDiscardResults();

cancel();

closeForNextExecution();
Expand Down Expand Up @@ -1578,34 +1570,4 @@ public ResultSet createDriverResultSet(Field[] fields, List<Tuple> tuples)

protected void transformQueriesAndParameters() throws SQLException {
}

private void resumeReadAndDiscardResults()
{
if (connection.getQueryExecutor().isRingBufferThreadRunning())
{
RedshiftResultSet rs = null;
if (firstUnclosedResult != null)
{
rs = (RedshiftResultSet) firstUnclosedResult.getResultSet();
}
if (rs != null && rs.queueRows != null)
{
boolean endOfResult = rs.queueRows.endOfResult();
if(!endOfResult)
{
rs.queueRows.setSkipRows();

// We sleep here for 2 seconds to give the ring buffer adequate time to start reading results again once it wakes up,
// and the server adequate time to detect that send buffer is no longer full
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
}
}
}
}
}
}

0 comments on commit befa7de

Please sign in to comment.