PDO Transaction Retry: Missing Auto‑Retry Flag for Deadlocks
29K reputation · 08 Sept 2020, 13:13 UTC
PDO Transaction Retry: Missing Auto‑Retry Flag for Deadlocks
When a transient database error such as a deadlock occurs, developers typically wrap their statements in a try/catch block, roll back the transaction, and manually re‑execute the SQL. The goal is to avoid duplicate writes while ensuring atomicity, but PDO offers no configuration flag to automate this pattern.
Without a built‑in retry attribute, the decision point remains: should PHP core add something like PDO::ATTR_RETRY_ON_DEADLOCK to automatically roll back and re‑run the transaction on specific SQLSTATE codes? This would relieve application code from manual retry loops but introduces questions about idempotency and transaction boundaries.
Key Unresolved Questions
- What should the semantics of an automatic retry attribute be regarding partial statement execution?
- How can developers guarantee idempotent operations when a retry is performed after a partial commit?
- Should the retry logic be configurable per connection or per statement, and how would that be exposed in the PDO API?
1 answer
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.