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 0E4422F148 for ; Thu, 1 Nov 2018 08:53:55 -0400 (EDT) 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 w9dXaP4zIlP5 for ; Thu, 1 Nov 2018 08:53:54 -0400 (EDT) Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (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 534122EF61 for ; Thu, 1 Nov 2018 08:53:54 -0400 (EDT) Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1gICTv-0006ld-G3 for tarantool-patches@freelists.org; Thu, 01 Nov 2018 15:53:51 +0300 Date: Thu, 1 Nov 2018 15:53:49 +0300 From: Konstantin Osipov Subject: [tarantool-patches] [PATCH] box: implement on_shutdown triggers Message-ID: <20181101125349.GA28060@chai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 https://github.com/tarantool/tarantool/issues/3159 https://github.com/tarantool/tarantool/tree/kostja/gh-3159-on-ctl --- src/box/box.cc | 3 +++ src/box/box.h | 3 +++ src/main.cc | 7 +++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index c4b4fb499..aefc02e81 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -78,6 +78,8 @@ static char status[64] = "unknown"; /** box.stat rmean */ struct rmean *rmean_box; +struct rlist on_shutdown = RLIST_HEAD_INITIALIZER(on_shutdown); + static void title(const char *new_status) { snprintf(status, sizeof(status), "%s", new_status); @@ -1653,6 +1655,7 @@ box_free(void) * initialized */ if (is_box_configured) { + trigger_run(&on_shutdown, NULL); #if 0 session_free(); user_cache_free(); diff --git a/src/box/box.h b/src/box/box.h index 9f5b3acbd..3db82d2bf 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -63,6 +63,9 @@ struct vclock; */ extern const struct vclock *box_vclock; +/** Invoked on box shutdown. */ +extern struct rlist on_shutdown; + /* * Initialize box library * @throws C++ exception diff --git a/src/main.cc b/src/main.cc index a36a2b0d0..dca7f1269 100644 --- a/src/main.cc +++ b/src/main.cc @@ -543,12 +543,15 @@ tarantool_free(void) */ if (!cord_is_main()) return; + /* + * Free the box first as it uses core infrastructure such + * as cbus, trigger and diag during shutdown. + */ + box_free(); /* Shutdown worker pool. Waits until threads terminate. */ coio_shutdown(); - box_free(); - title_free(main_argc, main_argv); /* unlink pidfile. */ -- 2.17.1 -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov