hello-stephen commented on code in PR #71084:
URL: https://github.com/apache/doris/pull/71084#discussion_r4764586519


##########
fe/be-java-extensions/jdbc-scanner/src/main/java/org/apache/doris/jdbc/JdbcJniScanner.java:
##########
@@ -301,40 +310,62 @@ protected int getNext() throws IOException {
 
     @Override
     protected void closeInternal() throws IOException {
-        try {
-            // Use type handler for database-specific connection abort
-            if (conn != null && resultSet != null) {
-                typeHandler.abortReadConnection(conn, resultSet);
-            }
-        } catch (Exception e) {
-            String diagnostic = JdbcExceptionUtils.format("JdbcJniScanner 
abort connection error",
-                    e, jdbcPassword, jdbcUrl);
-            LOG.warn("{}", diagnostic);
+        Exception failure = closeResources(null);
+        if (failure != null) {
+            throw new JdbcIOException("JdbcJniScanner close failed", failure, 
jdbcPassword, jdbcUrl);
         }
-        try {
-            if (resultSet != null && !resultSet.isClosed()) {
+    }
+
+    private Exception closeResources(Exception failure) {
+        resultSetOpened = false;
+        resultSetMetaData = null;
+        // isAfterLast() can be false even at EOF for an empty SQLServer 
result.
+        if (conn != null && resultSet != null && !resultSetExhausted && 
!abortAttempted) {
+            abortAttempted = true;
+            failure = JdbcCleanup.attempt(failure, () -> {
+                connectionAborted = typeHandler.abortReadConnection(conn, 
resultSet);

Review Comment:
   [P2] Avoid the unsupported SQL Server cursor probe during cleanup
   
   With `selectMethod=cursor`, Doris's forward-only/read-only result uses a 
server cursor, for which the driver [rejects 
`isAfterLast()`](https://learn.microsoft.com/en-us/sql/connect/jdbc/reference/isafterlast-method-sqlserverresultset?view=sql-server-ver17).
 If the scanner closes before observing `next()==false` (for example, a LIMIT 
stopping after a full batch), `SQLServerTypeHandler.abortReadConnection()` 
throws at that probe. This new aggregation retains the exception even when all 
actual releases succeed, marks the connection unusable, and returns a 
failed-close status; with positive minimum idle it also evicts a connection 
that the previous cleanup could reuse. Make the abort decision compatible with 
these cursors using the tracked EOF state, and add a case where the positional 
probe is unsupported but resource closure succeeds.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to