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

   ### Background
   
   JDBC Catalog writers run asynchronously in BE and use Java JDBC connections 
to write to external databases. With `enable_odbc_transcation` enabled, one 
writer's batches share an explicit transaction. Native writers pass lifecycle 
calls through the shared JNI plugin SPI.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #61141 (introduced unconditional commit on close), #66729 
(introduced the shared plugin SPI)
   PR Type: Bugfix
   
   Problem Summary:
   
   Failed or cancelled JDBC Catalog writes could commit earlier batches. This 
PR commits only after successful end-of-stream and a final status check; 
otherwise it requests rollback. It also cleans partially initialized resources 
without shutting down a shared pool. Most added lines test lifecycle boundaries.
   
   Original Java reproduction: batch one succeeded, batch two failed, then 
close still committed (commit=1, rollback=0).
   
   ### Details
   
   - **Change map:** Production code: +158/-41; tests and test resources: 
+700/-10; generated regression output: +3/-0; protocol documentation: +10/-0; 
build metadata: +1/-1. Native outcome propagation accounts for +62/-11, JDBC 
transaction/resource finalization for +84/-30, and the shared SPI hook for 
+12/-0. The remaining non-test changes document the contract and increment its 
API version.
   - **Frequency:** Always when an explicit transaction has earlier writes, a 
later failure/cancellation is visible before finalization, and the connection 
can still commit.
   - **Root cause:** `VJdbcTableWriter.close` discarded execution status; Java 
close committed unconditionally. Its shared catch could skip cleanup, and 
native cleanup skipped resources acquired before Java open completed.
   - **Why existing tests missed it:** `VJdbcTableWriterTest` checked dialect 
dispatch, and `JdbcDiagnosticsTest` checked write exceptions without subsequent 
close. The SQL transaction suite covered success only. Initial cleanup fixtures 
bypassed real zero-minimum shared-pool checkout failures.
   - **Fix:** Pass the terminal outcome through SPI `close(boolean)`; authorize 
commit only after successful EOS and a fresh native status check. Finalize 
once; independently attempt cleanup while preserving the first sanitized error, 
evicting the connection if rollback fails. Failed-open cleanup releases 
acquired resources without closing/removing the shared datasource. Normal-close 
pool policy is unchanged.
   - **Other paths and branches:** Auto-commit, legacy successful TVF close, 
and non-JDBC default hooks retain their behavior. API major 6.0 becomes 7.0: 
each BE requires matching native/SPI/bootstrap/plugin artifacts, not 
mixed-major jars. FE/BE wire and storage formats are unchanged. Only master was 
checked; release branches were not inspected.
   - **Behavior change:** Failed explicit transactions request rollback; 
successful writes still commit. Failed initialization preserves other pool 
borrowers.
   
   ### Testing
   
   All runs were local:
   
   - Original Java/mock reproduction: 3 tests, 1 expected failure, 0 
errors/skips; success and auto-commit controls passed. No historical 
full-native SQL negative control was run.
   - `run-fe-ut.sh`: 77 selected JDBC/SPI/bootstrap/Paimon/local-file tests 
passed, 0 failures/errors/skips. Real-Hikari checkout/partial-open cases failed 
two assertions before the pool correction and passed afterward.
   - `bash run-be-ut.sh --run -j 8 
--filter='VJdbcTableWriterTest.*:AsyncResultWriterTest.*'`: 10 passed with 
ASAN; native code/tests remain unchanged since that run.
   - `BUILD_TYPE=ASAN DISABLE_BE_JAVA_EXTENSIONS=OFF bash build.sh --be --fe 
--be-java-extensions -j 8`: passed, including plugin layout checks.
   - MySQL 5.7.44 / Connector/J 8.4.0, 
`external_table_p0/jdbc/test_mysql_jdbc_catalog_write_transaction`: 
generated/independently checked output, then normal comparison passed (1 suite, 
0 skipped); second-batch duplicate failure left only the seeded row visible.
   - Controlled lock-wait cancellation: transaction terminated, inserted rows 
absent. Shared-pool contention: checkout timeout of writer B left writer A 
active and able to commit both rows.
   - clang-format 16, format checks, Checkstyle, BE build hygiene and 
whitespace checks passed.
   
   ### Notes for Reviewers
   
   Guarantees are per writer, not cross-writer. Cancellation after the final 
native decision cannot reverse commit. Commit exceptions may mean an unknown 
remote outcome; rollback is best effort, never a commit retry.
   
   ### Release note
   
   With `enable_odbc_transcation` enabled, JDBC Catalog writes now request 
rollback on failure or cancellation visible before finalization. Failed 
initialization preserves shared-pool borrowers. Deploy matching 
BE/SPI/bootstrap/plugin artifacts.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No (the SPI contract is updated in this PR)
   - Pre-submission status: Partially verified: mixed-version/multi-BE E2E, 
other database/driver combinations, and the disabled non-JDBC SQL smoke suite 
were not run. Non-JDBC file writing and legacy/default hooks were verified by 
Java tests.
   
   ### AI Disclosure
   
   - Tool: Codex
   - Generated: Code, tests and this description.
   - Human review: Not reported.


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