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)
Showing
- changelogs/unreleased/gh-5717-transactional-event-triggers.md 6 additions, 0 deletions...gelogs/unreleased/gh-5717-transactional-event-triggers.md
- perf/memtx.cc 2 additions, 0 deletionsperf/memtx.cc
- src/box/CMakeLists.txt 1 addition, 0 deletionssrc/box/CMakeLists.txt
- src/box/box.cc 2 additions, 0 deletionssrc/box/box.cc
- src/box/space.c 133 additions, 51 deletionssrc/box/space.c
- src/box/space.h 15 additions, 4 deletionssrc/box/space.h
- src/box/txn.c 38 additions, 7 deletionssrc/box/txn.c
- src/box/txn.h 2 additions, 0 deletionssrc/box/txn.h
- src/box/txn_event_trigger.c 340 additions, 0 deletionssrc/box/txn_event_trigger.c
- src/box/txn_event_trigger.h 100 additions, 0 deletionssrc/box/txn_event_trigger.h
- test/engine-luatest/gh_5717_txn_event_triggers_test.lua 549 additions, 0 deletionstest/engine-luatest/gh_5717_txn_event_triggers_test.lua
Loading
Please register or sign in to comment