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
Showing
- src/box/alter.cc 1 addition, 0 deletionssrc/box/alter.cc
- src/box/errcode.h 1 addition, 1 deletionsrc/box/errcode.h
- src/box/lua/sequence.c 1 addition, 1 deletionsrc/box/lua/sequence.c
- src/box/lua/session.c 4 additions, 4 deletionssrc/box/lua/session.c
- src/box/lua/space.cc 55 additions, 2 deletionssrc/box/lua/space.cc
- src/box/request.c 46 additions, 0 deletionssrc/box/request.c
- src/box/request.h 17 additions, 0 deletionssrc/box/request.h
- src/box/space.c 211 additions, 3 deletionssrc/box/space.c
- src/box/space.h 2 additions, 0 deletionssrc/box/space.h
- src/box/tuple.c 1 addition, 5 deletionssrc/box/tuple.c
- src/box/tuple.h 6 additions, 0 deletionssrc/box/tuple.h
- src/lua/trigger.c 15 additions, 3 deletionssrc/lua/trigger.c
- src/lua/trigger.h 12 additions, 3 deletionssrc/lua/trigger.h
- src/lua/utils.h 17 additions, 0 deletionssrc/lua/utils.h
- test/box/before_replace.result 614 additions, 0 deletionstest/box/before_replace.result
- test/box/before_replace.test.lua 207 additions, 0 deletionstest/box/before_replace.test.lua
- test/box/misc.result 29 additions, 28 deletionstest/box/misc.result
- test/replication/before_replace.result 211 additions, 0 deletionstest/replication/before_replace.result
- test/replication/before_replace.test.lua 71 additions, 0 deletionstest/replication/before_replace.test.lua
- test/replication/suite.ini 1 addition, 1 deletiontest/replication/suite.ini
Loading
Please register or sign in to comment