Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: kostja@tarantool.org, tarantool-patches@freelists.org
Subject: Re: [PATCH v2] box: add on_schema_init trigger
Date: Wed, 6 Mar 2019 19:41:47 +0300	[thread overview]
Message-ID: <20190306164147.cxm6crj5mx6kfja7@esperanza> (raw)
In-Reply-To: <20190305155309.32516-1-sergepetrenko@tarantool.org>

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'))

      parent reply	other threads:[~2019-03-06 16:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05 15:53 Serge Petrenko
2019-03-05 18:59 ` Konstantin Osipov
2019-03-06 16:43   ` Vladimir Davydov
2019-03-05 19:00 ` Konstantin Osipov
2019-03-06 16:41 ` Vladimir Davydov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190306164147.cxm6crj5mx6kfja7@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v2] box: add on_schema_init trigger' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox