mrhhsg opened a new pull request, #71326:
URL: https://github.com/apache/doris/pull/71326

   ### What problem does this PR solve?
   
   Issue Number: None
   
   Related PR: #71084
   
   Cherry-picked from #71084 and adapted to the JDBC/JNI interfaces in 
`branch-4.2`.
   
   JDBC initialization and cleanup failures can leave partially acquired 
resources open, hide subsequent cleanup errors, or shut down a cached pool that 
other executors still use. Physically aborted or incompletely cleaned 
connections must not be recycled. Separately, an explicit flush failure can 
prevent the local file writer from closing its delegate.
   
   This backport:
   - Cleans up independently acquired resources after initialization/read 
failures and during close, preserving the first failure and suppressed cleanup 
failures. A statement is closed if fetch-size configuration fails.
   - Separates shared-pool ownership from borrowed connections. Pool 
publication is atomic, and only unpublished competing candidates are closed.
   - Tracks EOF and physical abort state, avoids accessing resources already 
terminated by abort, and evicts unusable borrows without subsequently resetting 
a detached Hikari pool entry.
   - Uses a private, one-shot pool for connection probes and releases it before 
the probe returns.
   - Preserves JDBC cause/next/suppressed diagnostics with cycle detection and 
redaction. The JNI bridge uses sanitized summaries and stack traces for the new 
cleanup exception without changing ordinary exception handling.
   - Closes the local file writer through `BufferedWriter.close()` even when 
flushing fails, and clears its reference in `finally`.
   
   #### Branch-specific adaptations
   
   The scanner/writer/type-handler changes are mapped to `BaseJdbcExecutor` and 
the existing database executors rather than importing the newer plugin 
architecture. JDBC diagnostics live in `java-common`, and connection probes use 
the existing native JNI entry point. Native explicit transaction boundaries, 
JNI/Thrift method signatures, and existing timestamp conversion behavior are 
preserved. Failure-path tests are adapted to these interfaces, including real 
Hikari pool ownership and connection replacement checks.
   
   ### Release note
   
   Fix resource leaks and shared JDBC pool shutdowns on JNI initialization and 
cleanup failures.
   
   ### Check List (For Author)
   
   - Test:
       - [x] Unit Test
       - [ ] Regression test
   
   Validation performed:
   - Affected Java plugins build successfully:
     ```bash
     DISABLE_BE_JAVA_EXTENSIONS=OFF ./build.sh --be-java-extensions 
--be-extension-ignore 
iceberg-metadata-scanner,hadoop-hudi-scanner,java-udf,paimon-connector,trino-connector-scanner,max-compute-connector,avro-scanner,preload-extensions,hadoop-deps
 -j 16
     ```
   - Java unit tests: **98 passed, 14 skipped, 0 failures/errors**. The skipped 
tests require external database connection settings.
     ```bash
     
EXTRA_FE_MODULES="jdbc=be-java-extensions/jdbc-scanner,writer=be-java-extensions/java-writer,common=be-java-extensions/java-common"
 ./run-fe-ut.sh --run 
"org.apache.doris.jdbc.*Test,org.apache.doris.common.jni.jdbc.*Test,org.apache.doris.writer.LocalFileResourceCleanupTest"
     ```
   - Native ASAN build and selected unit tests: **27 passed**.
     ```bash
     ./run-be-ut.sh --run 
--filter="JniConnectorTest.*:JdbcConnectorTest.*:JdbcJniReaderTest.*:JniTableReaderTest.*"
 -j 24
     ```
   - Maven validation/Checkstyle: passed with zero violations.
     ```bash
     cd fe && mvn validate -pl 
be-java-extensions/jdbc-scanner,be-java-extensions/java-common,be-java-extensions/java-writer
 -am
     ```
   - clang-format 16 and `git diff --check`: passed.
   
   SQL regression, live SQL Server/Oracle validation, multi-BE, and 
mixed-version testing were not run.
   
   - Behavior changed:
       - [x] Yes. Failed operations release acquired resources, cleanup errors 
are retained, unusable connections are retired, and individual executors do not 
shut down shared pools.
   - Does this need documentation?
       - [x] No. Bug fix; no new user-facing configuration or interfaces.


-- 
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