From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 5 Mar 2019 13:34:48 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH] box: add on_schema_init trigger Message-ID: <20190305103448.ijwf5c2ig35sdj4u@esperanza> References: <20190302123149.5115-1-sergepetrenko@tarantool.org> <20190305075454.GI21955@chai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190305075454.GI21955@chai> To: Konstantin Osipov Cc: tarantool-patches@freelists.org, Serge Petrenko List-ID: On Tue, Mar 05, 2019 at 10:54:54AM +0300, Konstantin Osipov wrote: > * 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. IMO having on_schema_init defined in schema.cc (we can't move it to box.cc) and declared in box.h would look confusing. > > > +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. Nit: I'd also rename the test from box-tap/ctl_on_schema_init.test.lua to box-tap/on_schema_init.test.lua.