Transactions are a way to group multiple operations into a single database commit.
transaction()
method on DittoStore
to run a given block in a
read-write transaction:
.commit
and rolled back if
it returns .rollback
. The transaction will also be implicitly rolled back if
an error is thrown at any point inside the block.
You can alternatively return a value from a transaction using the second variant
of the method. Returning any value will commit the transaction and throwing an
error will roll it back:
hint
parameter for transactions, which improves the readability of log output related
to transactions and is especially helpful for debugging conflicts between
multiple transactions. Also see section Deadlock
Prevention for more information.
A transaction can be configured to be read-only using the options
parameter.
Multiple read-only transactions can be executed concurrently, including
concurrently with a read-write transaction. However, executing a mutating DQL
statement in a read-only transaction will throw an error.
transaction()
receives a DittoTransaction
object. In
addition to the execute()
method, it also provides an info
property that
returns a DittoTransactionInfo
object. This object contains information about
the transaction, such as the transaction’s unique ID, the transaction’s hint,
and the transaction’s options.
close()
method is called, when the instance is garbage
collected, or when it goes out of scope.
hint
every 5 seconds if a
transaction runs for more than 10 seconds. These time intervals can be
configured using the following system parameters:
transaction_duration_before_logging_ms
: The amount of time in milliseconds
that a transaction can be running for before logging should begin.transaction_trace_interval_ms
: The interval of time in milliseconds between
progressive trace statementsDebug
.
transaction()
.
If errors occur in an execute()
call within a transaction block and the error
is caught and handled within the block, the transaction will continue to run and
not be rolled back.
When a transaction is configured to be read-only, the execution of mutating DQL
statements (UPDATE
, DELETE
, etc.) will throw an error. Unless this error is
caught, it will be propagated to the caller of transaction(:)
and the
transaction will be rolled back.