space: move all space triggers to the trigger registry
The patch moves space triggers to trigger registry. Triggers for each space are stored in two events: event, associated with space by name, and event, associated with space by id. For example, if we have a space named 'test' with id = 512, its on_replace trigger will be stored in 'box.space[512].on_replace' and 'box.space.test.on_replace' events. When space triggers are fired, triggers, associated by id, are called first. Since the triggers are moved to trigger registry, space trigger API is slightly changed - it is populated with optional third argument (trigger name) and its key-value variant. One of the main advantages of using trigger registry is setting triggers before box.cfg{}, but it would not be used for before_replace triggers since they can change tuples on recovery, and most of the time the user does not need it. To solve this problem, we decided to disable space triggers on recovery. However, ability to change tuples during recovery is necessary (for example, to be able to override engine on replica), that is why the patch introduces recovery triggers for spaces - they are fired only on recovery. Similar to regular triggers, recovery triggers for each space are stored in two events. Recovery version of before_replace triggers for space 'test' with id 512 are stored in 'box.space[512].before_recovery_replace' and 'box.space.test.before_recovery_replace'. Triggers on_replace have their recovery version as well. Recovery triggers receive 2 arguments in addition to its regular versions - xrow header and xrow body of type MsgPack object. Both MsgPacks are maps with integer keys. Since regular and recovery triggers cannot be used at the same time, we store them at the same pointer in space - it refers to recovery triggers on recovery and to regular ones when recovery is over. To update the triggers, helper space_on_final_recovery_complete is used. However, it is not fired after bootstrap of a new master, and triggers of all spaces, created during bootstrap, would not be updated - a new helper space_on_bootstrap_complete is introduced. There is another, more serious, breakage of backward compatibility. All triggers were stored in the space - it means that after the space is renamed it still has all its triggers, and when the space is dropped, all the triggers are removed. This patch moves triggers of space to trigger registry, which is just a key-value storage of triggers. That is why space do not own its triggers anymore - it just takes triggers from trigger registry. So, when the space is renamed, all the triggers, associated by id, are still associated with the space, but not the triggers associated by name - the space will fire triggers from an event, associated with a space by its new name. In order to relieve the pain of broken compatibility, all the triggers, which are set with an old API, are set to an event, associated by id. Also, when one sets a space trigger with an old API, it is set to both regular version of trigger and a recovery one if recovery has not been finished yet. For example, s:before_replace(foo) will set a trigger to both 'box.space[512].before_replace' and 'box.space[512].before_recovery_replace' events before recovery is finished and to the first event only after recovery. Along the way, fixed an assertion that failed when before_replace changed new tuple on recovery from snapshot. Also, message of error ER_BEFORE_REPLACE_RET is changed. The type of value, returned by before_replace triggers was in the message before, but new triggers are called with a func_apapter, which does not allow to get a type of returned value, so the type was removed from the message. Part of #8657 Closes #8859 Closes #9127 NO_CHANGELOG=later NO_DOC=later
Showing
- src/box/errcode.h 1 addition, 1 deletionsrc/box/errcode.h
- src/box/lua/space.cc 35 additions, 90 deletionssrc/box/lua/space.cc
- src/box/memtx_engine.cc 7 additions, 0 deletionssrc/box/memtx_engine.cc
- src/box/memtx_space.c 7 additions, 1 deletionsrc/box/memtx_space.c
- src/box/memtx_tx.c 2 additions, 2 deletionssrc/box/memtx_tx.c
- src/box/space.c 278 additions, 9 deletionssrc/box/space.c
- src/box/space.h 57 additions, 0 deletionssrc/box/space.h
- src/box/txn.c 2 additions, 2 deletionssrc/box/txn.c
- src/box/vinyl.c 3 additions, 3 deletionssrc/box/vinyl.c
- test/box-luatest/gh_4264_recursive_trigger_test.lua 2 additions, 0 deletionstest/box-luatest/gh_4264_recursive_trigger_test.lua
- test/box-luatest/gh_6150_memtx_tx_memory_monitoring_test.lua 1 addition, 1 deletiontest/box-luatest/gh_6150_memtx_tx_memory_monitoring_test.lua
- test/box-luatest/gh_8027_txn_handle_abort_in_trigger_test.lua 9 additions, 5 deletions.../box-luatest/gh_8027_txn_handle_abort_in_trigger_test.lua
- test/box-luatest/triggers_old_api_test.lua 9 additions, 0 deletionstest/box-luatest/triggers_old_api_test.lua
- test/box/before_replace.result 11 additions, 2 deletionstest/box/before_replace.result
- test/box/before_replace.test.lua 4 additions, 1 deletiontest/box/before_replace.test.lua
- test/box/on_replace.result 30 additions, 6 deletionstest/box/on_replace.result
- test/box/on_replace.test.lua 13 additions, 5 deletionstest/box/on_replace.test.lua
- test/box/push.result 7 additions, 1 deletiontest/box/push.result
- test/box/push.test.lua 3 additions, 1 deletiontest/box/push.test.lua
- test/engine-luatest/space_triggers_test.lua 283 additions, 0 deletionstest/engine-luatest/space_triggers_test.lua
Loading
Please register or sign in to comment