Functions for transaction management
For general information and examples, see section Transactions.
Observe the following rules when working with transactions:
Rule #1
The requests in a transaction must be sent to a server as a single block. It is not enough to enclose them between begin and commit or rollback. To ensure they are sent as a single block: put them in a function, or put them all on one line, or use a delimiter so that multi-line requests are handled together.
Rule #2
All database operations in a transaction should use the same storage engine.
It is not safe to access tuple sets that are defined with {engine='vinyl'}
and also access tuple sets that are defined with {engine='memtx'}
,
in the same transaction.
Rule #3
Requests which cause changes to the data definition
– create, alter, drop, truncate – are only allowed with
Tarantool version 2.1 or later.
Data-definition requests which change an index
or change a format, such as
space_object:create_index() and
space_object:format(),
are not allowed inside transactions except as the first request
after box.begin()
.
Below is a list of all functions for transaction management.
Name | Use |
---|---|
box.begin() | Begin the transaction |
box.commit() | End the transaction and save all changes |
box.rollback() | End the transaction and discard all changes |
box.savepoint() | Get a savepoint descriptor |
box.rollback_to_savepoint() | Do not end the transaction and discard all changes made after a savepoint |
box.atomic() | Execute a function, treating it as a transaction |
box.on_commit() | Define a trigger that will be activated by box.commit |
box.on_rollback() | Define a trigger that will be activated by box.rollback |
box.is_in_txn() | State whether a transaction is in progress |