From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 5 Mar 2019 10:54:54 +0300 From: Konstantin Osipov Subject: Re: [tarantool-patches] [PATCH] box: add on_schema_init trigger Message-ID: <20190305075454.GI21955@chai> References: <20190302123149.5115-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190302123149.5115-1-sergepetrenko@tarantool.org> To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com, Serge Petrenko List-ID: * Serge Petrenko [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