From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7A0642CEF1 for ; Fri, 23 Nov 2018 05:37:07 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZK0Na5fyi8oK for ; Fri, 23 Nov 2018 05:37:07 -0500 (EST) Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 3799D2CDE9 for ; Fri, 23 Nov 2018 05:37:07 -0500 (EST) Date: Fri, 23 Nov 2018 13:37:04 +0300 From: Konstantin Osipov Subject: [tarantool-patches] Re: [PATCH 2/2] box: introduce on_shutdown triggers to lua Message-ID: <20181123103704.GB10757@chai> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Serge Petrenko * Serge Petrenko [18/11/22 20:21]: > Make it possible to register on_shutdown triggers from lua via > box.ctl.on_shutdown() OK, this is a nice step forward, can we add shutdown reason to the event and marshal it to Lua? Why are you calling the trigger only in case box is configured? Why should it matter? The ticket is missing a docbot plea. What if on_shutdown trigger yields? We either should document that it can't yield or test that it can yield. Besides, it can do some very nasty things, like use 'box', or sockets, or seep. We should (if possible) test and document what it can and cannot do. > > Part of #1607 > --- > src/box/lua/ctl.c | 21 +++++++++++++++++++++ > test/box/misc.result | 34 ++++++++++++++++++++++++++++++++++ > test/box/misc.test.lua | 14 ++++++++++++++ > 3 files changed, 69 insertions(+) > > diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c > index 9a105ed5c..dad39515c 100644 > --- a/src/box/lua/ctl.c > +++ b/src/box/lua/ctl.c > @@ -37,6 +37,7 @@ > #include > > #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. It will be used when we decide to pass > + * a signal which caused termination to the trigger. > + */ > +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.result b/test/box/misc.result > index 4ee4797d0..fd55b8cf1 100644 > --- a/test/box/misc.result > +++ b/test/box/misc.result > @@ -1205,3 +1205,37 @@ 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 > +--- > +... > +_ = box.ctl.on_shutdown(f) > +--- > +... > +_ = box.ctl.on_shutdown(g) > +--- > +... > +_ = box.ctl.on_shutdown(h, g) > +--- > +... > +test_run:cmd('restart server default') > +test_run:grep_log('default', 'on_shutdown 1', nil, {noreset=true}) > +--- > +- on_shutdown 1 > +... > +test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true}) > +--- > +- null > +... > +test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true}) > +--- > +- on_shutdown 3 > +... > diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua > index ee81c7be1..a4b38b403 100644 > --- a/test/box/misc.test.lua > +++ b/test/box/misc.test.lua > @@ -342,3 +342,17 @@ 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 > +_ = box.ctl.on_shutdown(f) > +_ = box.ctl.on_shutdown(g) > +_ = box.ctl.on_shutdown(h, g) > +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}) > -- > 2.17.2 (Apple Git-113) > -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov