[tarantool-patches] [PATCH v3 0/3] box: implement on_shutdown triggers

Serge Petrenko sergepetrenko at tarantool.org
Tue Dec 11 16:24:37 MSK 2018


This patchset adds on_shutdown triggers which can be registered from lua 
via box.ctl.on_shutdown() and are run on tarantool shutdown.

Issue: https://github.com/tarantool/tarantool/issues/1607
Branch: https://github.com/tarantool/tarantool/tree/sp/gh-1607-on-exit-triggers

Changes in v2: 
  - added 3rd patch which passes signals to triggers.
  - run on_shutdown triggers even if box is not configured.
  - add a documentation request to the 3rd patch.

Changes in v3: 
  - remove the patch which passes signals to the trigger, since
    the triggers are not run on fatal signals at all, and doing
    this for SIGTERM or SIGINT is not of much use.
  - Add a new patch which moves tarantool_free() from atexit()
    to end of main(). Only close the journal and restore terminal state
    (if needed) in atexit handlers. Also in signal handler create
    a new fiber which breaks the event loop. on_shutdown triggers will
    be run from this fiber before ev loop break.
  - add tests that on_shutdown triggers can yield to the third patch.

AFAICS now there are no limitations on what can be done in on_shutdown
triggers: you may sleep, yield, perform DML/DDL requests.

First patch moves tarantool_free() from atexit() to end of main(),
alters signal handler for SIGINT, SIGHUP, SIGTERM to create a new fiber
which can be used to do some work on shutdown (run on_shutdown triggers)
and then break the event loop.
As mentioned above, the only things still done in atexit() are stopping
WAL thread and 

Second patch was originally made by Kostja and implemented on_shutdown
triggers. I altered it a bit so that on_shutdown triggers are run from
a fiber before event loop break, this allows us to yield in on_shutdown
triggers and to use box library.

Third patch expands box.ctl interface by introducing box.ctl.on_shutdown()
function to register on_shutdown triggers from lua.

Konstantin Osipov (1):
  box: implement on_shutdown triggers

Serge Petrenko (2):
  box: get rid of atexit() for calling cleanup routine
  box: introduce on_shutdown triggers to lua

 src/box/box.cc         | 16 +++++++++
 src/box/box.h          | 18 ++++++++++
 src/box/lua/ctl.c      | 21 ++++++++++++
 src/main.cc            | 75 ++++++++++++++++++++++++++++++++++--------
 test/box/misc.result   | 48 +++++++++++++++++++++++++++
 test/box/misc.test.lua | 19 +++++++++++
 6 files changed, 183 insertions(+), 14 deletions(-)

-- 
2.17.2 (Apple Git-113)





More information about the Tarantool-patches mailing list