Skip to content

Commit 80a27ca

Browse files
authored
[branch-2.1][improvement](jdbc catalog) Force all resources to be closed in the close method (#39666)
pick (#39423)
1 parent ebbebdf commit 80a27ca

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/BaseJdbcExecutor.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,14 @@ public void close() throws Exception {
103103
try {
104104
stmt.cancel();
105105
} catch (SQLException e) {
106-
LOG.error("Error cancelling statement", e);
106+
LOG.warn("Cannot cancelling statement: ", e);
107107
}
108108
}
109109

110-
boolean shouldAbort = conn != null && resultSet != null;
111-
boolean aborted = false; // Used to record whether the abort operation is performed
112-
if (shouldAbort) {
113-
aborted = abortReadConnection(conn, resultSet);
114-
}
115-
116-
// If no abort operation is performed, the resource needs to be closed manually
117-
if (!aborted) {
118-
closeResources(resultSet, stmt, conn);
110+
if (conn != null && resultSet != null) {
111+
abortReadConnection(conn, resultSet);
119112
}
113+
closeResources(resultSet, stmt, conn);
120114
} finally {
121115
if (config.getConnectionPoolMinSize() == 0 && hikariDataSource != null) {
122116
hikariDataSource.close();
@@ -130,23 +124,16 @@ private void closeResources(AutoCloseable... closeables) {
130124
for (AutoCloseable closeable : closeables) {
131125
if (closeable != null) {
132126
try {
133-
if (closeable instanceof Connection) {
134-
if (!((Connection) closeable).isClosed()) {
135-
closeable.close();
136-
}
137-
} else {
138-
closeable.close();
139-
}
127+
closeable.close();
140128
} catch (Exception e) {
141-
LOG.error("Cannot close resource: ", e);
129+
LOG.warn("Cannot close resource: ", e);
142130
}
143131
}
144132
}
145133
}
146134

147-
protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
135+
protected void abortReadConnection(Connection connection, ResultSet resultSet)
148136
throws SQLException {
149-
return false;
150137
}
151138

152139
public void cleanDataSource() {

fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/MySQLJdbcExecutor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ public MySQLJdbcExecutor(byte[] thriftParams) throws Exception {
5252
}
5353

5454
@Override
55-
protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
55+
protected void abortReadConnection(Connection connection, ResultSet resultSet)
5656
throws SQLException {
5757
if (!resultSet.isAfterLast()) {
5858
// Abort connection before closing. Without this, the MySQL driver
5959
// attempts to drain the connection by reading all the results.
6060
connection.abort(MoreExecutors.directExecutor());
61-
return true;
6261
}
63-
return false;
6462
}
6563

6664
@Override

fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/SQLServerJdbcExecutor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ public SQLServerJdbcExecutor(byte[] thriftParams) throws Exception {
3838
}
3939

4040
@Override
41-
protected boolean abortReadConnection(Connection connection, ResultSet resultSet)
41+
protected void abortReadConnection(Connection connection, ResultSet resultSet)
4242
throws SQLException {
4343
if (!resultSet.isAfterLast()) {
4444
// Abort connection before closing. Without this, the SQLServer driver
4545
// attempts to drain the connection by reading all the results.
4646
connection.abort(MoreExecutors.directExecutor());
47-
return true;
4847
}
49-
return false;
5048
}
5149

5250
@Override

0 commit comments

Comments
 (0)