From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 6 Mar 2019 19:41:47 +0300 From: Vladimir Davydov Subject: Re: [PATCH v2] box: add on_schema_init trigger Message-ID: <20190306164147.cxm6crj5mx6kfja7@esperanza> References: <20190305155309.32516-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190305155309.32516-1-sergepetrenko@tarantool.org> To: Serge Petrenko Cc: kostja@tarantool.org, tarantool-patches@freelists.org List-ID: On Tue, Mar 05, 2019 at 06:53:09PM +0300, Serge Petrenko wrote: > If you want to change space's `space_name` storage engine to `vinyl` > , you may say: > ``` > function trig(old, new) > if new[3] == 'space_name' and new[4] ~= 'vinyl' then > return box.tuple.new{new[1], new[2], new[3], 'vinyl', > new[5], new[6], new[7]} > end > end > ``` You could use new:update{{'=', 4, 'vinyl'}} instead. > diff --git a/src/box/box.h b/src/box/box.h > index 53d88ab71..ea6a11aee 100644 > --- a/src/box/box.h > +++ b/src/box/box.h > @@ -67,6 +67,8 @@ extern const struct vclock *box_vclock; > /** Invoked on box shutdown. */ > extern struct rlist box_on_shutdown; > > +/** Triggers invoked after schema initialization. */ > +extern struct rlist on_schema_init; I moved it back to schema.h (Kostja agreed that it'd be better). Pushed to 2.1 with the following changes: diff --git a/src/box/box.h b/src/box/box.h index ea6a11ae..53d88ab7 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -67,8 +67,6 @@ extern const struct vclock *box_vclock; /** Invoked on box shutdown. */ extern struct rlist box_on_shutdown; -/** Triggers invoked after schema initialization. */ -extern struct rlist on_schema_init; /* * Initialize box library * @throws C++ exception diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c index f90a9a97..85ed30c5 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" static int lbox_ctl_wait_ro(struct lua_State *L) diff --git a/src/box/schema.cc b/src/box/schema.cc index f0fccf7f..74d70d8d 100644 --- a/src/box/schema.cc +++ b/src/box/schema.cc @@ -70,7 +70,6 @@ uint32_t schema_version = 0; uint32_t space_cache_version = 0; struct rlist on_schema_init = RLIST_HEAD_INITIALIZER(on_schema_init); - struct rlist on_alter_space = RLIST_HEAD_INITIALIZER(on_alter_space); struct rlist on_alter_sequence = RLIST_HEAD_INITIALIZER(on_alter_sequence); diff --git a/src/box/schema.h b/src/box/schema.h index f3df08b4..6f9a9611 100644 --- a/src/box/schema.h +++ b/src/box/schema.h @@ -44,6 +44,9 @@ extern "C" { extern uint32_t schema_version; extern uint32_t space_cache_version; +/** Triggers invoked after schema initialization. */ +extern struct rlist on_schema_init; + /** * Lock of schema modification */ diff --git a/test/replication/replica_on_schema_init.lua b/test/replication/replica_on_schema_init.lua index 66323775..8a221681 100644 --- a/test/replication/replica_on_schema_init.lua +++ b/test/replication/replica_on_schema_init.lua @@ -2,13 +2,13 @@ function trig_local(old, new) if new and new[3] == 'test_local' and new[6]['group_id'] ~= 1 then - return box.tuple.new({new[1],new[2],new[3],new[4],new[5],{group_id=1},new[7]}) + return new:update{{'=', 6, {group_id = 1}}} end end function trig_engine(old, new) if new and new[3] == 'test_engine' and new[4] ~= 'vinyl' then - return box.tuple.new({new[1],new[2],new[3],'vinyl',new[5],new[6],new[7]}) + return new:update{{'=', 4, 'vinyl'}} end end @@ -20,9 +20,6 @@ end) box.cfg({ listen = os.getenv("LISTEN"), replication = os.getenv("MASTER"), - memtx_memory = 107374182, - replication_timeout = 0.1, - replication_connect_timeout = 0.5, }) require('console').listen(os.getenv('ADMIN'))