Skip to content
Snippets Groups Projects
Commit fa0a31b5 authored by Andrey Saranchin's avatar Andrey Saranchin Committed by Aleksandr Lyapunov
Browse files

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
parent 2822177f
No related branches found
No related tags found
Loading
Showing
with 764 additions and 130 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