Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,14 @@ public void close() throws Exception {
try {
stmt.cancel();
} catch (SQLException e) {
LOG.error("Error cancelling statement", e);
LOG.warn("Cannot cancelling statement: ", e);
}
}

boolean shouldAbort = conn != null && resultSet != null;
boolean aborted = false; // Used to record whether the abort operation is performed
if (shouldAbort) {
aborted = abortReadConnection(conn, resultSet);
}

// If no abort operation is performed, the resource needs to be closed manually
if (!aborted) {
closeResources(resultSet, stmt, conn);
if (conn != null && resultSet != null) {
abortReadConnection(conn, resultSet);
}
closeResources(resultSet, stmt, conn);
} finally {
if (config.getConnectionPoolMinSize() == 0 && hikariDataSource != null) {
hikariDataSource.close();
Expand All @@ -130,23 +124,16 @@ private void closeResources(AutoCloseable... closeables) {
for (AutoCloseable closeable : closeables) {
if (closeable != null) {
try {
if (closeable instanceof Connection) {
if (!((Connection) closeable).isClosed()) {
closeable.close();
}
} else {
closeable.close();
}
closeable.close();
} catch (Exception e) {
LOG.error("Cannot close resource: ", e);
LOG.warn("Cannot close resource: ", e);
}
}
}
}

protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
protected void abortReadConnection(Connection connection, ResultSet resultSet)
throws SQLException {
return false;
}

public void cleanDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ public MySQLJdbcExecutor(byte[] thriftParams) throws Exception {
}

@Override
protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
protected void abortReadConnection(Connection connection, ResultSet resultSet)
throws SQLException {
if (!resultSet.isAfterLast()) {
// Abort connection before closing. Without this, the MySQL driver
// attempts to drain the connection by reading all the results.
connection.abort(MoreExecutors.directExecutor());
return true;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ public SQLServerJdbcExecutor(byte[] thriftParams) throws Exception {
}

@Override
protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
protected void abortReadConnection(Connection connection, ResultSet resultSet)
throws SQLException {
if (!resultSet.isAfterLast()) {
// Abort connection before closing. Without this, the SQLServer driver
// attempts to drain the connection by reading all the results.
connection.abort(MoreExecutors.directExecutor());
return true;
}
return false;
}

@Override
Expand Down