DBIO-ClickHouse
view release on metacpan or search on metacpan
docs/adr/0003-no-transactions-policy.md view on Meta::CPAN
# ADR 0003 â Transactions: no-op with a warning, but rollback throws
- Status: accepted
- Date: 2026-07-25
## Context
ClickHouse has no transactions. `BEGIN` / `COMMIT` over the MySQL wire endpoint
(ADR 0001) do not give real atomicity, and there are no savepoints â the
savepoint hooks (`_exec_svp_begin` / `_exec_svp_release` / `_exec_svp_rollback`)
already throw. What was left open is DBIO's *transaction* API:
`txn_do`, `txn_begin`, `txn_commit`, `txn_rollback`.
This is not a corner of the API that a driver can ignore. Core itself reaches
for transactions on ordinary operations: `ResultSet::populate`, `delete_all`,
`update_all`, multi-create in `Row::insert`, and cascading delete all open a
`DBIO::Storage::TxnScopeGuard`, i.e. `txn_begin` + `txn_commit`, with
`txn_rollback` on the unwind. Whatever this driver decides, it decides for the
whole ORM surface, not just for user-written `txn_do` blocks.
Three options were on the table:
- **(a) Always throw.** Honest, but it takes `populate`, multi-create,
`delete_all` and cascade delete with it: the ORM would be unusable for
anything but single-row work, and every user would have to route around core
internals they do not control.
- **(b) No-op passthrough.** The API keeps working and stays silent. It is a
lying API of exactly the kind ADR 0002 exists to prevent â the caller is told
a transaction succeeded when there never was one.
- **(c) No-op with a one-time warning.** The API keeps working, but the driver
says out loud, once, that nothing is atomic.
Within (c) the four entry points are not equivalent. `txn_begin`, `txn_commit`
and `txn_do` only ever *promise* atomicity; a silent no-op costs the caller a
guarantee they never really had. `txn_rollback` is different in kind: it
*claims work was undone*. Accepting it silently leaves the caller believing the
changes are gone while every statement is still in the table â the one place
where a no-op does not merely fail to help but actively manufactures a wrong
belief about the data.
## Decision
**(c), with `txn_rollback` as the exception.**
1. **`txn_begin` / `txn_commit` are no-ops** at the `_exec_txn_begin` /
`_exec_txn_commit` hooks: nothing is sent to the server, but core's public
methods and its `transaction_depth` bookkeeping run untouched, so nesting,
`txn_scope_guard` and "commit without begin" keep behaving the way they do
on every other driver.
2. **`txn_do` runs its coderef with no `BEGIN`/`COMMIT` bracket**, via a
`DBIO::Storage::BlockRunner` with `wrap_txn => 0`. Arguments, calling
context and core's `_in_do_block` handling are preserved. The block is
**never retried** (`retry_handler => sub { 0 }`): core's retry-on-stale-
connection is only safe because the transaction guarantees the failed
attempt left nothing behind â without one, a retry would re-apply whatever
the first attempt already wrote.
3. **A failing `txn_do` re-throws the original exception unchanged** and carps
loudly, **every time** (not once), that nothing was rolled back. Because
nothing is wrapped, there is no rollback that could fail and mask the real
error â the failure-report path in `BlockRunner` that produces
`"Transaction aborted: ... Rollback failed: ..."` is never entered.
4. **`txn_rollback` always throws** via `throw_exception`, after unwinding
`transaction_depth` by one so the storage is never left believing it is
inside a transaction.
5. **Warn-once granularity is per interpreter**, using core's own `carp_once`
from `DBIO::Carp` (the house primitive for exactly this) rather than
hand-rolled per-object state. The limitation is a property of ClickHouse
itself â not of a connection, a callsite or a moment â so repeating it per
( run in 0.774 second using v1.01-cache-2.11-cpan-eb134014566 )