From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Subject: Re: [tarantool-patches] Re: [PATCH 1/1] box: expose on_commit/rollback triggers for Lua References: <6aff0ac07499e8d43a0b8cd64edbe1c40a31cbff.1534441147.git.v.shpilevoy@tarantool.org> <20180817084044.bjroy7t2mirkyqn2@esperanza> From: Vladislav Shpilevoy Message-ID: Date: Fri, 17 Aug 2018 17:45:21 +0300 MIME-Version: 1.0 In-Reply-To: <20180817084044.bjroy7t2mirkyqn2@esperanza> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit To: Vladimir Davydov Cc: tarantool-patches@freelists.org List-ID: For an updated commit message see my response sent to your next email. On 17/08/2018 11:40, Vladimir Davydov wrote: > 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.