From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 17 Aug 2018 11:40:44 +0300 From: Vladimir Davydov Subject: Re: [PATCH 1/1] box: expose on_commit/rollback triggers for Lua Message-ID: <20180817084044.bjroy7t2mirkyqn2@esperanza> References: <6aff0ac07499e8d43a0b8cd64edbe1c40a31cbff.1534441147.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6aff0ac07499e8d43a0b8cd64edbe1c40a31cbff.1534441147.git.v.shpilevoy@tarantool.org> To: Vladislav Shpilevoy Cc: tarantool-patches@freelists.org List-ID: 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.