-
Vladimir Davydov authored
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
Vladimir Davydov authoredTo 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
request.h 2.94 KiB