-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose on_commit/on_rollback triggers to Lua #857
Comments
This is done. |
Gerold103
added a commit
that referenced
this issue
Aug 16, 2018
On commit/rollback triggers are already implemented within Tarantool internals. The patch just exposes them for Lua. Below the API is described, which deserves an attention though. Closes #857 @TarantoolBot document Title: Document box.on_commit/on_rollback triggers On commit/rollback triggers can be set similar to space:on_replace triggers: box.on_commit/rollback(new_trigger, old_trigger) A trigger can be set only inside an active transaction. When a trigger is called, it takes 1 parameter: an iterator over the transaction statements. box.on_commit(function(iterator) for i, old_tuple, new_tuple, space_id in iterator() do -- Do something with tuples and space ... end end) On each step the iterator returns 4 values: statement number (grows from 1 to statement count), old tuple or nil, new tuple or nil and space id. Old tuple is not nil when the statement updated or deleted the existing tuple. New tuple is not nil when the statement updated or inserted the tuple. The iterator can not be used outside of the trigger. Otherwise it throws an error. On_commit/rollback triggers shall not fail, otherwise Tarantool exits with panic.
Gerold103
added a commit
that referenced
this issue
Aug 17, 2018
On commit/rollback triggers are already implemented within Tarantool internals. The patch just exposes them for Lua. Below the API is described, which deserves an attention though. Closes #857 @TarantoolBot document Title: Document box.on_commit/on_rollback triggers On commit/rollback triggers can be set similar to space:on_replace triggers: box.on_commit/rollback(new_trigger, old_trigger) A trigger can be set only inside an active transaction. When a trigger is called, it takes 1 parameter: an iterator over the transaction statements. box.on_commit/on_rollback(function(iterator) for i, old_tuple, new_tuple, space_id in iterator() do -- Do something with tuples and space ... end end) On each step the iterator returns 4 values: statement number (grows from 1 to statement count), old tuple or nil, new tuple or nil and space id. Old tuple is not nil when the statement updated or deleted the existing tuple. New tuple is not nil when the statement updated or inserted the tuple. Limitations: * the iterator can not be used outside of the trigger. Otherwise it throws an error; * a trigger can not do any database requests (DML, DDL, DQL) - behaviuor is undefined; * on_commit/rollback triggers shall not fail, otherwise Tarantool exits with panic.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We already have on_commit/on_rollback triggers inside the transaction processor, but it's not possible to use them from Lua.
Add an API to set on_commit/on_rollback triggers. (I don't know how it should look like).
If there is no current transaction, throw an error.
The triggers can't throw exceptions, since they happen after-the-fact, so this should be taken into account.
The text was updated successfully, but these errors were encountered: