Skip to content
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

Closed
kostja opened this issue Jun 3, 2015 · 1 comment
Closed

Expose on_commit/on_rollback triggers to Lua #857

kostja opened this issue Jun 3, 2015 · 1 comment
Assignees
Labels
feature A new functionality good first issue Good for newcomers
Milestone

Comments

@kostja
Copy link
Contributor

kostja commented Jun 3, 2015

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.

@kostja kostja added this to the 1.6.7 milestone Aug 12, 2015
@kostja kostja modified the milestones: 1.6.7, 1.7 Aug 31, 2015
@kostja kostja added feature A new functionality b2b labels Aug 31, 2015
@kostja
Copy link
Contributor Author

kostja commented Oct 27, 2017

This is done.

@kostja kostja closed this as completed Oct 27, 2017
@kostja kostja removed this from the wishlist milestone Oct 27, 2017
@kostja kostja reopened this Oct 27, 2017
@kostja kostja added this to the wishlist milestone Oct 27, 2017
@kostja kostja added good first issue Good for newcomers and removed b2b labels Feb 7, 2018
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 Gerold103 modified the milestones: wishlist, 1.10.2 Aug 16, 2018
@Gerold103 Gerold103 self-assigned this Aug 16, 2018
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.
@locker locker closed this as completed in a49c8c0 Aug 17, 2018
@kyukhin kyukhin added the tmp label Oct 9, 2018
@locker locker removed the tmp label Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new functionality good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants