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 B560F21B89 for ; Tue, 11 Dec 2018 08:26:08 -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 Pm5G9A9DoOZg for ; Tue, 11 Dec 2018 08:24:45 -0500 (EST) Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (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 8637721B63 for ; Tue, 11 Dec 2018 08:24:45 -0500 (EST) From: Serge Petrenko Subject: [tarantool-patches] [PATCH v3 0/3] box: implement on_shutdown triggers Date: Tue, 11 Dec 2018 16:24:37 +0300 Message-Id: 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: kostja@tarantool.org Cc: tarantool-patches@freelists.org, Serge Petrenko 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)