mrhhsg opened a new pull request, #71084: URL: https://github.com/apache/doris/pull/71084
### Background JNI reader and writer plugins acquire JDBC connections, statements, result sets, or local file handles. JDBC connections come from cached Hikari pools, which can serve multiple operations. Native writers call Java close to finalize output and may read statistics afterward. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Bugfix Problem Summary: Partially failed JDBC initialization can leave resources unclosed; cleanup exceptions can skip later closes or make subsequent close falsely succeed. Separate failed-open cleanup from one-shot finalization, preserve errors, distinguish EOF from physical abort, and release each borrow without shutting down shared pools. Most additions exercise failure paths and ownership. ### Details - **Change map:** 20 files: production +228/-92, tests +1596/-3; no generated files or documentation changes. Production changes group into JDBC acquisition, cleanup and pool ownership (+176/-77), native close-result handling (+17/-9), and local-file cleanup plus diagnostics (+35/-6). - **Frequency:** Always for the reproduced partial-open/cleanup failure paths; EOF/abort behavior depends on driver closed-state semantics, and pool interference requires overlapping borrowers. Physical release depends on the driver. - **Root cause:** Open handlers omitted cleanup; shared cleanup blocks skipped later closes and discarded errors. Native close marked completion before JNI environment acquisition; flush failure skipped file close. Physical abort was confused with returning a Hikari borrow, and minimum idle count with exclusive ownership. - **Why existing tests missed it:** `JdbcDiagnosticsTest` emphasized diagnostics; counting proxies omitted post-abort physical closure, and real-Hikari coverage had one positive-minimum borrower. SQL diagnostics/transaction suites did not inject failures; `test_insert_into_local_tvf_jni` unconditionally returns. - **Fix:** Attempt cleanup independently, retaining the first exception and suppressing later failures. Roll back failed initialization without committing. Track EOF; evict successfully aborted borrows before proxy close. Atomically publish one pool, closing only unpublished candidates. Retain Java finalization outcomes; retry only pre-entry environment acquisition. Close files despite flush failure and include suppressed diagnostics with existing redaction. - **Other paths and branches:** Legacy/V2 readers share the scanner; V2 already cleans up failed open. Default/MySQL/Oracle statement creation and all three pool creators are covered. Native close serves other JNI writers and preserves statistics. JNI/SPI and wire formats are unchanged. Release branches and bug origin were not established. - **Behavior change:** Scanner cleanup errors propagate; repeated writer close retains its result without repeating finalization. Zero-minimum pools follow existing cached idle/lifetime cleanup, not per-operation shutdown. Execution/cancellation transaction policy is unchanged. ### Testing All runs were local: - Original cleanup probes: 12 failing cases and 10 passing controls before the fix; final cleanup tests pass. Failed flush previously produced `flush must not skip close ==> expected: <1> but was: <0>`. - `run-fe-ut.sh`: 206 passed, including 12 real-Hikari ownership tests; 18 existing external integration cases skipped without connection properties. - ASAN native tests via `run-be-ut.sh`: 21 passed across `VJniFormatTransformerTest`, `JniReaderTest`, `JniTableReaderTest` and `JdbcJniReaderTest`. - ASAN BE/FE and selected plugins built with `build.sh`; final Java plugins rebuilt. Checkstyle, clang-format v16, header hygiene and whitespace checks passed. - `test_jdbc_error_diagnostics` and `test_mysql_jdbc_catalog_write_transaction` passed with MySQL 8.0/Connector-J 8.4.0, plus a zero-minimum transaction run and actual zero-row JDBC read. Transaction fixtures override driver location and optionally pool minimum, not SQL or expected output. ### Notes for Reviewers Java close can commit/publish before throwing; failed-open cleanup must not commit. Real-Hikari tests use physical-connection proxies, not SQL Server/Oracle servers. ### Release note JDBC JNI operations attempt remaining cleanup after initialization/close failure and retain errors. Local-file writers close despite flush failure. Exhausted/aborted JDBC reads avoid unnecessary closed-state errors; operations no longer shut down shared zero-minimum pools. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Partially verified: real SQL Server/Oracle integration, disabled LOCAL TVF SQL, multi-BE and mixed-version runs were not performed. ### AI Disclosure - Tool: Codex - Generated: Code, tests, and this description. - Human review: Not performed yet. -- 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]
