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 8167C2FEBC for ; Thu, 22 Nov 2018 12:21:18 -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 3kZ4t08x1J2r for ; Thu, 22 Nov 2018 12:21:18 -0500 (EST) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (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 3B2372FEA4 for ; Thu, 22 Nov 2018 12:21:18 -0500 (EST) From: Serge Petrenko Subject: [tarantool-patches] [PATCH 1/2] box: implement on_shutdown triggers Date: Thu, 22 Nov 2018 20:20:54 +0300 Message-Id: <00e7bd1333fa26130979fd71b1d113c9f37076c4.1542906167.git.sergepetrenko@tarantool.org> In-Reply-To: References: In-Reply-To: References: 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, tarantool-patches@freelists.org From: Konstantin Osipov @sergepetrenko: Factor out running on_shutdown triggers from box_free() into a separate function. In tarantool_free() run on_shutdown triggers before coio_shutdown(), but leave box_free() after coio_shutdown(). Otherwise tarantool hangs on shutdown occasionally. --- src/box/box.cc | 10 ++++++++++ src/box/box.h | 11 +++++++++++ src/main.cc | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/box/box.cc b/src/box/box.cc index 7a1171c62..d8be85b3a 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); @@ -1645,6 +1647,14 @@ box_set_replicaset_uuid(const struct tt_uuid *replicaset_uuid) diag_raise(); } +void +box_run_on_shutdown_triggers(void) +{ + if (is_box_configured) { + trigger_run(&on_shutdown, NULL); + } +} + void box_free(void) { diff --git a/src/box/box.h b/src/box/box.h index 9f5b3acbd..e2c3aad9e 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -63,6 +63,11 @@ struct vclock; */ extern const struct vclock *box_vclock; +struct trigger; + +/** Invoked on box shutdown. */ +extern struct rlist on_shutdown; + /* * Initialize box library * @throws C++ exception @@ -76,6 +81,12 @@ box_init(void); void box_free(void); +/** + * Run on_shutdown triggers. + */ +void +box_run_on_shutdown_triggers(void); + /** * Load configuration for box library. * Panics on error. diff --git a/src/main.cc b/src/main.cc index a36a2b0d0..987c53834 100644 --- a/src/main.cc +++ b/src/main.cc @@ -544,6 +544,8 @@ tarantool_free(void) if (!cord_is_main()) return; + box_run_on_shutdown_triggers(); + /* Shutdown worker pool. Waits until threads terminate. */ coio_shutdown(); -- 2.17.2 (Apple Git-113)