Skip coordinated transactions (2PC) for single-statement, single-shard procedure calls#8524
Conversation
colm-mchugh
left a comment
There was a problem hiding this comment.
Lgtm @paragikjain , thanks for addressing review comments. Approving to enable merge, but there is one necessary step to enable check-style to pass; run citus_indent --check in root dir of your citus repo and commit whatever files are flagged.
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (22.22%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## main #8524 +/- ##
===========================================
- Coverage 88.92% 44.80% -44.12%
===========================================
Files 286 286
Lines 63179 62200 -979
Branches 7922 7644 -278
===========================================
- Hits 56179 27866 -28313
- Misses 4731 31893 +27162
- Partials 2269 2441 +172 🚀 New features to boost your workflow:
|
1f50422 to
39d24a6
Compare
Replace the runtime counter approach from PR #8524 with pre-execution static analysis of procedure bodies using the PLpgSQL plugin func_beg hook. This avoids partial commits followed by ERROR that the original design could produce for multi-statement procedures. Key changes: - New procedure_body_analysis.c: PLpgSQL plugin that walks the statement tree at func_beg time, counting SQL-producing statements (EXECSQL, PERFORM, DYNEXECUTE, CALL) and detecting disqualifiers (COMMIT, ROLLBACK, and all loop types). - Loops (FOR, WHILE, LOOP, FOREACH) are treated as disqualifiers since they can execute SQL multiple times, risking partial commits. - Multi-statement procedures fall back gracefully to normal coordinated transactions (2PC) instead of raising an ERROR. - Remove ProcedureNonCoordinatedExecutionCount global counter and its three reset sites in utility_hook.c. - Update tests Replace the runtime counter approach from PR #8524 with pre-execution static analysis of procedure bodies using the PLpgSQ.
Replace the runtime counter approach from PR #8524 with pre-execution static analysis of procedure bodies using the PLpgSQL plugin func_beg hook. This avoids partial commits followed by ERROR that the original design could produce for multi-statement procedures. Key changes: - New procedure_body_analysis.c: PLpgSQL plugin that walks the statement tree at func_beg time, counting SQL-producing statements (EXECSQL, PERFORM, DYNEXECUTE, CALL) and detecting disqualifiers (COMMIT, ROLLBACK, and all loop types). - Loops (FOR, WHILE, LOOP, FOREACH) are treated as disqualifiers since they can execute SQL multiple times, risking partial commits. - Multi-statement procedures fall back gracefully to normal coordinated transactions (2PC) instead of raising an ERROR. - Remove ProcedureNonCoordinatedExecutionCount global counter and its three reset sites in utility_hook.c. - Update tests Replace the runtime counter approach from PR #8524 with pre-execution static analysis of procedure bodies using the PLpgSQ. Adds a temporary benchmarking script, for testing/dev purposes only (will not be in final commit)
citus.enable_single_shard_procedure_optimization (default off) that allows stored procedure calls containing a single distributed write targeting one shard with one placement to skip coordinated (2PC) transactions. This eliminates the overhead of BEGIN → PREPARE TRANSACTION → COMMIT PREPARED for the common case of single-statement, single-shard procedures.
Important partial-commit behavior: Because the first statement executes without 2PC, it auto-commits on the worker. If the procedure contains a second distributed statement, the ERROR prevents silent data inconsistency — but the first statement's effects are already committed and cannot be rolled back. This is explicitly documented in the GUC description, function comments, and the error message's DETAIL line