Repository navigation
fix(#6543): recognize ROLLBACK over the Postgres extended-query protocol - #6546
Conversation
parseCommand()'s Parse-time dispatch tracked explicit-transaction state for BEGIN/BEGIN TRANSACTION and COMMIT only. There was no ROLLBACK branch, and sqlEngine.parse() was called unconditionally before that dispatch ever ran, so a bare ROLLBACK sent as its own Parse/Bind/Execute fell through, parsed as ArcadeDB SQL's own RollbackStatement (which does call database.rollback()), but left explicitTransactionStarted set - wedging the wire-level session at ReadyForQuery status 'T' forever afterwards, since syncCommand()'s implicit- commit branch only runs once that flag is clear. Add a ROLLBACK branch that clears the flag and explicitly rolls back (it cannot lean on Sync's implicit-commit branch the way COMMIT does, since clearing the flag without rolling back first would make the next Sync COMMIT the transaction instead). Move the BEGIN/COMMIT/ROLLBACK check ahead of sqlEngine.parse() entirely, mirroring queryCommand's simple-query dispatch: the grammar's begin/commit/rollbackStatement productions accept only the bare keyword, so "BEGIN TRANSACTION"/"COMMIT WORK"/ "ROLLBACK TRANSACTION" all fail to parse as SQL, and calling parse() unconditionally is what made the follow-up ask - widening isCommitStatement/isRollbackStatement to the SQL-standard WORK forms - throw a syntax error instead of silently doing nothing. Regression test speaks the wire protocol directly over a raw socket so the extended-query Parse/Bind/Execute path is actually exercised (JDBC/psycopg2 normally send transaction control over the simple-query protocol instead).
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 6 |
🟢 Coverage 93.33% diff coverage · -6.55% coverage variation
Metric Results Coverage variation ✅ -6.55% coverage variation Diff coverage ✅ 93.33% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (49d2025) 164158 131234 79.94% Head commit (b7c783d) 196552 (+32394) 144252 (+13018) 73.39% (-6.55%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6546) 15 14 93.33% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewSolid, well-scoped fix. I traced through
Minor observations (non-blocking)
Test coverageThe new No security or performance concerns - this is a dispatch-ordering/matching fix with no new allocations or hot-path impact. |
… protocol The Claude review on this PR noted a coverage gap: isCommitStatement() was widened to COMMIT WORK/END/END TRANSACTION/END WORK alongside the ROLLBACK fix, but the new IT class only exercised the ROLLBACK side. Add a companion test exercising COMMIT WORK and END over Parse/Bind/Execute/Sync.
ReviewSolid, well-scoped fix. Mirrors Potential follow-up bug (not introduced by this PR, same bug class as #6543)
if (errorInTransaction)
return;before the new BEGIN/COMMIT/ROLLBACK dispatch ( Compare with When This looks pre-existing (the Minor: test coverage gapThe new Nits
Nice writeup in the PR description connecting the fix to the exact mechanics of |
…ases too Closes the remaining test-coverage nit from the review: isCommitStatement() also recognizes COMMIT TRANSACTION/END TRANSACTION/END WORK, which weren't yet exercised over the extended query protocol. Files a companion follow-up issue (#6548, referenced in the PR body) for the separately-scoped errorInTransaction early-return gap the same review flagged.
ReviewReviewed the diff in Correctness
Minor observations (not blockers)
Test coverage
Security / Performance
Overall this is a well-scoped, well-tested fix with clear reasoning in the comments and PR description. Nice job separating the genuinely-out-of-scope follow-up work (#6548) instead of scope-creeping this PR. |
…nt helper PostgreSQL's own grammar is BEGIN [ WORK | TRANSACTION ], so BEGIN WORK is a real form a client can send. Add isBeginStatement (BEGIN/BEGIN TRANSACTION/BEGIN WORK), matching the three-way shape of isCommitStatement/ isRollbackStatement, and use it in queryCommand(), parseCommand(), and getTag() in place of each site's ad hoc literal check. Extends the extended- protocol regression test with a BEGIN WORK -> ROLLBACK case.
ReviewVerified against the actual merged file ( Correctness
Scope discipline
Test coverage
Nits
Overall: a well-scoped, well-tested fix that correctly resists the temptation to also fix the two adjacent gaps it surfaced ( |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6546 +/- ##
==========================================
- Coverage 71.24% 71.22% -0.02%
==========================================
Files 1866 1866
Lines 164158 164165 +7
Branches 34688 34690 +2
==========================================
- Hits 116948 116931 -17
- Misses 32967 32999 +32
+ Partials 14243 14235 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What does this PR do?
Closes #6543
Over the Postgres extended query protocol (Parse/Bind/Execute),
PostgresNetworkExecutor.parseCommand()'sdispatch that tracks explicit-transaction state (
explicitTransactionStarted) recognized onlyBEGIN/BEGIN TRANSACTIONandCOMMIT. There was noROLLBACKbranch, and worse,sqlEngine.parse()was called unconditionally before that dispatch ever ran. A bareROLLBACKsent as itsown Parse/Bind/Execute (as opposed to the simple-query protocol fixed in #6457/#6542) therefore fell through,
parsed successfully as ArcadeDB SQL's own
RollbackStatement(whoseexecuteSimple()does calldatabase.rollback()), but leftexplicitTransactionStartedset. SincewriteReadyForQueryMessage()reportsstatus
'T'whenever that flag is set, andsyncCommand()'s implicit-commit branch only runs once the flag isclear, the wire-level session stayed reported as "inside an explicit transaction" forever after the ROLLBACK.
The fix:
ROLLBACKbranch to the Parse dispatch, alongside the existingBEGIN/COMMIThandling. UnlikeCOMMIT(which can lean onsyncCommand()'s implicit-commit branch simply by clearing the flag),ROLLBACKcalls
database.rollback()directly and then clears the flag - clearing it first, without rolling back, wouldmake the next
Synccommit the transaction instead, the opposite of what the client asked for.BEGIN/COMMIT/ROLLBACKcheck ahead ofsqlEngine.parse()entirely, the same orderingqueryCommand()'s simple-query dispatch already uses. This turned out to be necessary, not cosmetic: ArcadeDBSQL's
beginStatement/commitStatement/rollbackStatementgrammar productions accept only the bare keyword(plus BEGIN's own
ISOLATIONclause and COMMIT's ownRETRYclause), sosqlEngine.parse("ROLLBACK WORK", ...)or
sqlEngine.parse("BEGIN TRANSACTION", ...)throws a syntax error. With the unconditional parse still inplace, widening
isCommitStatement/isRollbackStatementto recognize those forms (see below) would have madea
ROLLBACK WORKreach aCommandParsingExceptioninstead of silently falling through - confirmed by aregression run before this reordering was added (see "Also worth covering" below).
isCommitStatement/isRollbackStatementnow recognize theSQL-standard
COMMIT WORK/ROLLBACK WORK/END WORKforms alongside the bare and... TRANSACTIONformsalready handled. Since the extended-protocol COMMIT branch previously matched only the exact literal
"COMMIT"(narrower than the simple-query protocol's
isCommitStatement), it now uses the same helper as ROLLBACK,so
COMMIT TRANSACTION/END/END TRANSACTION/END WORKare recognized there too - matching the simple-queryprotocol's coverage rather than adding new scope.
isBeginStatementhelper (BEGIN/BEGIN TRANSACTION/BEGIN WORK) and uses it in bothqueryCommand()andparseCommand()in place of the ad hoc literal checks each previously had, per reviewfeedback: PostgreSQL's own grammar is
BEGIN [ WORK | TRANSACTION ], soBEGIN WORKis a real form a clientcan send, and it now gets the same three-way recognition as COMMIT/ROLLBACK instead of falling through to
sqlEngine.parse()and erroring.Motivation
Follow-up from the Claude Code review on PR #6542 (the #6457 fix), which was explicitly scoped to the
simple-query protocol only.
Related issues
Closes #6543. Same class of bug as #6457/#6542, on the extended-query wire path.
Additional Notes
Discovered while testing, left as a separate follow-up (not fixed in this PR):
parseCommand()'sBEGINbranch only sets
explicitTransactionStarted = true- unlikequeryCommand()'sBEGINbranch, it never callsdatabase.begin(). So a write made after an extended-queryBEGINcurrently auto-commits on its own (via theper-statement auto-transaction wrapping) before any following
COMMIT/ROLLBACKis reached - "explicittransactions" over the extended query protocol don't yet behave transactionally at all. This is independent of
#6543 (which is about wire-status/dispatch correctness, not about starting a real underlying transaction) and is
a materially bigger change - filing it separately seemed better than folding it into this fix. The regression
test's javadoc calls this out explicitly and deliberately does not assert data-discarding for that reason.
Filed as a companion follow-up, per the Claude review on this PR: #6548.
parseCommand()/bindCommand()/executeCommand()all short-circuit withif (errorInTransaction) return;before the new BEGIN/COMMIT/ROLLBACKdispatch. So once a transaction is aborted, a client that sends an explicit
ROLLBACKover the extendedprotocol to recover never reaches the dispatch added here -
Sync'serrorInTransactionbranch does roll backbut never clears
explicitTransactionStarted, so the client ends up back at status'T'instead of'I'. Samesymptom this PR fixes, reached via the aborted-transaction path instead of a plain
ROLLBACK. Pre-existing(the early-return guard predates this diff), touches three call sites instead of one, and needs its own
regression coverage - out of scope here, tracked in #6548.
Review nits closed in this PR: the initial version of the regression test only exercised the ROLLBACK-side
aliases; a follow-up commit added
COMMIT WORK/COMMIT TRANSACTION/END/END TRANSACTION/END WORKcoverageso every form
isCommitStatement/isRollbackStatementrecognizes is now exercised over the extended protocol,not just the ROLLBACK half. A later review pass also flagged
BEGIN WORKas unrecognized (real PostgreSQLsyntax, and the PR's own stated goal was matching the
WORKform to the SQL standard) - folded in above withisBeginStatementand aBEGIN WORK->ROLLBACKregression case.Test plan
Issue6543RollbackExtendedProtocolIT(raw-socket, extended-query Parse/Bind/Execute/Sync), 3 tests:rollbackOverExtendedProtocolEndsTransaction: BEGIN ->'T'; ROLLBACK -> no ErrorResponse, status back to'I'; a following statement on the same connection still works (not wedged in'T').rollbackAliasesAreRecognizedOverExtendedProtocol:ROLLBACK WORKandROLLBACK TRANSACTIONbothrecognized and clear the flag, over the extended query protocol.
commitAliasesAreRecognizedOverExtendedProtocol:COMMIT WORK,COMMIT TRANSACTION,END,END TRANSACTION, andEND WORKall recognized and clear the flag, over the extended query protocol -the COMMIT-side counterpart, added in response to review feedback on this PR.
SocketException/EOFExceptionfor theWORK/TRANSACTION forms once
isCommitStatement/isRollbackStatementwere widened without first reorderingthe parse call, and a stuck
'T'status for the bareROLLBACKcase).Issue6457AbortedTransactionSimpleQueryIT(simple-query protocol, Postgres simple-query: an aborted BEGIN block wedges the session (ReadyForQuery never 'E', COMMIT/ROLLBACK unrecognized, statements silently swallowed) #6457/fix(#6457): recognize COMMIT/ROLLBACK/END over the Postgres simple-query protocol #6542) still passes -confirms the simple-query dispatch and its
COMMIT/ROLLBACK/ENDhandling are unaffected.postgreswmodule test suite: 414 tests, 0 failures, 0 errors.mvn compile/test-compileclean forpostgreswand its reactor dependencies.Checklist
mvn clean packagecommand