Skip to content
Snippets Groups Projects
Commit c006620a authored by Ilya Verbin's avatar Ilya Verbin Committed by Aleksandr Lyapunov
Browse files

box: introduce transactional event triggers

This patch introduces 3 new transaction-related events, that can be used
for setting user-defined triggers:

 * box.before_commit - triggered when a transaction is ready to commit;
 * box.on_commit - triggered when a transaction is committed;
 * box.on_rollback - triggered when a transaction is rolled back.

Each of them have 3 versions, e.g. `box.on_commit' event has:

 * box.on_commit - global version, called for all transactions;
 * box.on_commit.space.test - called for transactions that write to
   space "test";
 * box.on_commit.space[512] - called for transactions that write to
   space with id 512.

These triggers are implemented via the new trigger registry and work
independently from the core `on_commit' and `on_rollback' triggers.
One of the main advantages of the new triggers is that they can be set
for all transactions, rather than setting them within each transaction.

Space-specific triggers are called prior to global ones. If a trigger-
function fails, the remaining triggers for this event (including global)
are not executed.

If a space-specific trigger is added to the registry within an active
transaction, it may or may not be called on commit/rollback of this
transaction (the behavior is unspecified).

The trigger-function for each event may take an iterator parameter.
Similar to core triggers, the iterator goes through the effects of every
request that changed a space during the transaction.

`box.before_commit' trigger-function restrictions:

 * Yield is allowed (on memtx without mvcc it will abort the txn);
 * Allowed to write into database spaces;
 * If the function raises an error, the transaction is rolled back.

`box.on_commit' and `box.on_rollback' trigger-function restrictions:

 * Yield is forbidden (it will crash Tarantool);
 * The function should not access any database spaces;
 * If the function raises an error, the error is simply logged.

Closes #5717

NO_DOC=later (it depents on the documentation of the `trigger` module)
parent 8b78639d
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment