[tarantool-patches] [PATCH] box: add on_schema_init trigger

Konstantin Osipov kostja at tarantool.org
Tue Mar 5 10:54:54 MSK 2019


* Serge Petrenko <sergepetrenko at tarantool.org> [19/03/03 23:25]:
> This patch introduces an on_schema_init trigger. The trigger may be set
> before box.cfg() is called and is called during box.cfg() right after
> prototypes of system spaces, such as _space, are created. This allows to
> set triggers on system spaces before any other non-system data is
> recovered. For example, it is possible to set an on_replace trigger on
> _space, which will work even during recovery.
> 
> Part of #3159
> 
> @TarantoolBot document
> Title: document box.ctl.on_schema_init triggers
> on_schema_init triggers are set before the first call to box.cfg() and
> are fired during box.cfg() before user data recovery start.

Please explain in the docbot request why we're adding this with
an example: provide the docs team with a full example how to use
these triggers to easily change space engine type in replication events
or make a space on a replicate "terminate" in replication by
changing its group id to GROUP_LOCAL.

> 
> diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c
> index 7010be138..0767cf476 100644
> --- a/src/box/lua/ctl.c
> +++ b/src/box/lua/ctl.c
> @@ -40,6 +40,7 @@
>  #include "lua/trigger.h"
>  
>  #include "box/box.h"
> +#include "box/schema.h"	/* on_schema_init triggers */


Please move the declaration to a more suitable place (box/box.h?)
to avoid polluting the include list.

> +trig = box.ctl.on_schema_init(testing_trig)
> +test:is(type(trig), 'function', 'on_schema_init trigger set')
> +
> +box.cfg{log = 'tarantool.log'}
> +test:like(str, 'on_schema_init', 'on_schema_init trigger works')
> +str = ''
> +box.schema.space.create("test")
> +-- test that _space.on_replace trigger may be set in on_schema_init
> +test:like(str, '_space:on_replace', 'can set on_replace')
> +test:check()
> +box.space.test:drop()
> +os.exit(0)

Please write a full test for changed storage engine on replica *in
addition to* this unit test. Another test for replica-local spaces
on replica won't hurt.


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov



More information about the Tarantool-patches mailing list