From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: kostja@tarantool.org, tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] [PATCH v3 3/3] box: introduce on_shutdown triggers to lua
Date: Thu, 27 Dec 2018 16:14:47 +0300 [thread overview]
Message-ID: <20181227131447.mgeedrgtt2bp4f3i@esperanza> (raw)
In-Reply-To: <eb63468f952707beb8d72b0e0c43151c6da95c4e.1544533138.git.sergepetrenko@tarantool.org>
On Tue, Dec 11, 2018 at 04:24:40PM +0300, Serge Petrenko wrote:
> Make it possible to register on_shutdown triggers from lua via
> box.ctl.on_shutdown()
>
> Closes #1607
>
> @TarantoolBot document
> Title: Document box.ctl.on_shutdown triggers
> on_shutdown triggers may be set similar to space:on_replace triggers:
> ```
> box.ctl.on_shutdown(new_trigger, old_trigger)
> ```
> The triggers will be run when tarantool exits due to receiving one of
> the signals: `SIGTERM`, `SIGINT`, `SIGHUP`.
>
> Note that the triggers will not be run if you exit tarantool by typing
> `os.exit()` to the lua console or if tarantool receives a fatal signal:
> `SIGSEGV`, `SIGABORT` or any signal causing immediate program
> termination.
> ---
> src/box/lua/ctl.c | 21 ++++++++++++++++++
> test/box/misc.result | 48 ++++++++++++++++++++++++++++++++++++++++++
> test/box/misc.test.lua | 19 +++++++++++++++++
> 3 files changed, 88 insertions(+)
>
> diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c
> index 9a105ed5c..aa835d6d5 100644
> --- a/src/box/lua/ctl.c
> +++ b/src/box/lua/ctl.c
> @@ -37,6 +37,7 @@
> #include <lualib.h>
>
> #include "lua/utils.h"
> +#include "lua/trigger.h"
>
> #include "box/box.h"
>
> @@ -64,9 +65,29 @@ lbox_ctl_wait_rw(struct lua_State *L)
> return 0;
> }
>
> +/*
> + * This is a placeholder.
> + * We may decide to pass some arguments to on_shutdown triggers.
I don't think so. Let's instead remove this placeholder and add a check
for push_event != NULL to lbox_trigger_run().
> + */
> +static int
> +lbox_push_on_shutdown(struct lua_State *L, void *event)
> +{
> + (void)L;
> + (void)event;
> + return 0;
> +}
> +
> +static int
> +lbox_ctl_on_shutdown(struct lua_State *L)
> +{
> + return lbox_trigger_reset(L, 2, &on_shutdown, lbox_push_on_shutdown,
> + NULL);
> +}
> +
> static const struct luaL_Reg lbox_ctl_lib[] = {
> {"wait_ro", lbox_ctl_wait_ro},
> {"wait_rw", lbox_ctl_wait_rw},
> + {"on_shutdown", lbox_ctl_on_shutdown},
> {NULL, NULL}
> };
>
> diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua
> index cc6cb34fb..f9d0f53f2 100644
> --- a/test/box/misc.test.lua
> +++ b/test/box/misc.test.lua
> @@ -352,3 +352,22 @@ rows == expected_rows
> lsn == expected_lsn
> box.cfg{too_long_threshold = too_long_threshold}
> s:drop()
> +
> +--
> +-- gh-1607: on_shutdown triggers.
> +--
> +f = function() print('on_shutdown 1') end
> +g = function() print('on_shutdown 2') end
> +h = function() print('on_shutdown 3') end
> +-- check that on_shutdown triggers may yield and sleep.
> +fiber = require('fiber')
> +trig = function() fiber.sleep(0.01) fiber.yield() print('on_shutdown 4') end
Let's test something more complicated, e.g. inserting a tuple into
a space.
> +_ = box.ctl.on_shutdown(f)
> +_ = box.ctl.on_shutdown(g)
> +_ = box.ctl.on_shutdown(h, g)
> +_ = box.ctl.on_shutdown(trig)
> +test_run:cmd('restart server default')
> +test_run:grep_log('default', 'on_shutdown 1', nil, {noreset=true})
> +test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true})
> +test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true})
> +test_run:grep_log('default', 'on_shutdown 4', nil, {noreset=true})
prev parent reply other threads:[~2018-12-27 13:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 13:24 [tarantool-patches] [PATCH v3 0/3] box: implement on_shutdown triggers Serge Petrenko
2018-12-11 13:24 ` [tarantool-patches] [PATCH v3 1/3] box: get rid of atexit() for calling cleanup routine Serge Petrenko
2018-12-27 12:43 ` Vladimir Davydov
2018-12-27 12:50 ` Konstantin Osipov
2018-12-27 12:56 ` Vladimir Davydov
2018-12-28 7:43 ` [tarantool-patches] " Konstantin Osipov
2018-12-28 7:58 ` Vladimir Davydov
2018-12-29 13:54 ` Serge Petrenko
2018-12-11 13:24 ` [tarantool-patches] [PATCH v3 2/3] box: implement on_shutdown triggers Serge Petrenko
2018-12-27 13:11 ` Vladimir Davydov
2018-12-11 13:24 ` [tarantool-patches] [PATCH v3 3/3] box: introduce on_shutdown triggers to lua Serge Petrenko
2018-12-27 13:14 ` 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=20181227131447.mgeedrgtt2bp4f3i@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=sergepetrenko@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v3 3/3] box: introduce on_shutdown triggers to lua' \
/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