Skip to content
Snippets Groups Projects
Commit 5a27b737 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Konstantin Osipov
Browse files

Introduce BEFORE trigger

To register a BEFORE trigger for a space, call space:before_replace()
function. Similarly to space:on_replace(), this function takes a new
trigger callback as the first argument and a function to remove from
the registered trigger list as the second optional argument.

Trigger callbacks are executed from space_execute_dml(), right before
passing down a request to the engine implementation, but after resolving
the space sequence. Just like on_replace, a before_replace callback is
passed old and new tuples, but it can also return a tuple or nil, which
will affect the current statement as follows:

 - If a callback function returns the old tuple, the statement is
   ignored and IPROTO_NOP is written to xlog to bump LSN.

 - If a callback function returns the new tuple or doesn't return
   anything, the statement is executed as is.

 - If a callback function returns nil, the statement is turned into
   DELETE.

 - If a callback function returns a tuple, the statement is turned
   into REPLACE for this tuple.

Other return values result in ER_BEFORE_REPLACE_RET error.

Note, the trigger must not change the primary key of the old tuple,
because that would require splitting the resulting statement into two -
DELETE and REPLACE.

The new trigger can be used to resolve asynchronous replication
conflicts as illustrated by replication/before_replace test.

Closes #2993
parent b73030f2
No related branches found
No related tags found
Loading
Showing
with 1522 additions and 51 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment