pg.ddx.io  aws/aws-advanced-jdbc-wrapper GitHub issues and pull requests  
help / color / mirror / Atom feed
From: karenc-bq (@karenc-bq) <noreply+karenc-bq@github.com>
To: aws/aws-advanced-jdbc-wrapper <noreply+aws-aws-advanced-jdbc-wrapper@github.com>
Subject: [aws/aws-advanced-jdbc-wrapper] PR #2215: fix: check target driver for current transaction state
Date: Mon, 02 Nov 2026 23:51:29 +0000
Message-ID: <gh-aws-aws-advanced-jdbc-wrapper-2215@github.com> (raw)

### Summary
- Ask the target driver for the current transaction state (pgjdbc `TransactionState`, Connector/J `SERVER_STATUS_IN_TRANS`, MariaDB Connector/J `ServerStatus.IN_TRANSACTION`), read from state the driver already holds, no round trip. Fall back to the state tracked from SQL statements and JDBC calls only when the driver cannot say (no dialect support, or the connection is closed).
- When the driver reports state, the SQL is no longer analyzed to infer transaction boundaries. Instead the driver's answer is recorded after every completed call, so that once the connection breaks and the driver stops reporting, failover still sees the state as of the last completed statement. `SET AUTOCOMMIT` statements are still recognized, via a cheap pre-check before the full analysis, so the driver's autocommit view stays in step. The analysis and tracking are unchanged for a dialect that reports nothing.
- The driver flag is read through internal connection pool proxies too (HikariCP and c3p0 delegate `isWrapperFor`/`unwrap`). A closed or returned-to-pool handle reports nothing.
- Each statement is analyzed at most once per call and the result reused.

### Behavior change
With `autocommit=false` on MySQL, a statement that touches no transactional table (`SELECT 1`, `SELECT @@aurora_server_id`) does not start a server-side transaction, and the driver now reports none. The old SQL heuristic treated any statement under `autocommit=false` as opening one. In that narrow case failover now raises `FailoverSuccessSQLException` rather than `TransactionStateUnknownSQLException`, and `setReadOnly` is allowed to switch. PostgreSQL is unaffected (pgjdbc opens a transaction on any statement). The affected integration tests were rewritten to open a real transaction.

### Tests
- `TransactionStateTests` (integration): the flag each of the three drivers reports for autocommit on/off, commit/rollback, explicit BEGIN/COMMIT, PG aborted transactions, closed connections and the internal-pool proxy; plus the tracked-state fallback, forced through the generic dialect.
- `DefaultConnectionPluginTest`: every tracked transition on the fallback path; the driver state is recorded and survives a connection break; `SET AUTOCOMMIT` still synced.
- `SqlMethodAnalyzerTest`: the pre-check never misses a `SET AUTOCOMMIT`.
- `PluginServiceImplTests`: driver state wins over tracked state, null falls back, no connection returns null.
- `ReadWriteSplittingTests`: the two in-transaction tests now open a transaction on a real table.

### By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

view thread (16+ messages)  latest in thread

Message-ID: <gh-aws-aws-advanced-jdbc-wrapper-2215@github.com>
Permalink:  ../gh-aws-aws-advanced-jdbc-wrapper-2215@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox