[PATCH 1/1] box: expose on_commit/rollback triggers for Lua

Vladimir Davydov vdavydov.dev at gmail.com
Fri Aug 17 11:40:44 MSK 2018


I haven't looked at the code yet, just skimmed over the commit message,
but already have a couple of questions that I think should be clarified
in the documentation request.

On Thu, Aug 16, 2018 at 08:57:10PM +0300, Vladislav Shpilevoy wrote:
> 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:

>From before_replace/on_replace trigger you can issue DDL statements.
What happens if you try to do the same from on_commit/on_rollback
trigger?

> 
>     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)

OK, on_commit trigger takes committed tuples. What arguments does
on_rollback trigger take?

> 
> 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.



More information about the Tarantool-patches mailing list