From: Serge Petrenko <sergepetrenko@tarantool.org>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH v3 2/3] box: implement on_shutdown triggers
Date: Tue, 11 Dec 2018 16:24:39 +0300 [thread overview]
Message-ID: <33b51ca5edbeb8bce134d62bff83e02faaa936e9.1544533138.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1544533138.git.sergepetrenko@tarantool.org>
In-Reply-To: <cover.1544533138.git.sergepetrenko@tarantool.org>
From: Konstantin Osipov <kostja@tarantool.org>
@sergepetrenko:
Instead of running on_shutdown trigggers in box_free() execute them in a
fiber which breaks event loop before the break.
In tarantool_free() move box_free() back after coio_shutdown().
Otherwise tarantool hangs on shutdown occasionally.
Part of #1607
---
src/box/box.cc | 8 ++++++++
src/box/box.h | 11 +++++++++++
src/main.cc | 16 ++++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/src/box/box.cc b/src/box/box.cc
index 9642364f6..72119eca1 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -79,6 +79,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);
@@ -1671,6 +1673,12 @@ box_set_replicaset_uuid(const struct tt_uuid *replicaset_uuid)
diag_raise();
}
+void
+box_run_on_shutdown_triggers(void)
+{
+ trigger_run(&on_shutdown, NULL);
+}
+
void
box_free(void)
{
diff --git a/src/box/box.h b/src/box/box.h
index cb9a512be..e9c14e5cf 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -64,6 +64,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
@@ -84,6 +89,12 @@ box_free(void);
void
box_shutdown_wal(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 2240c564a..8bcc785d5 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -124,6 +124,11 @@ static int
on_exit_f(va_list ap)
{
(void) ap;
+ /*
+ * run on_shutdown triggers before event loop break,
+ * so that we are able to yield in them.
+ */
+ box_run_on_shutdown_triggers();
/* Terminate the main event loop. */
ev_break(loop(), EVBREAK_ALL);
return 0;
@@ -132,6 +137,17 @@ on_exit_f(va_list ap)
void
tarantool_exit(void)
{
+ static volatile sig_atomic_t num_calls = 0;
+ /*
+ * We are already running on_shutdown triggers,
+ * and will exit as soon as they'll finish.
+ * Do not execute them twice.
+ */
+ if (num_calls > 0)
+ return;
+
+ ++num_calls;
+
struct fiber *f = fiber_new("on_shutdown", on_exit_f);
if (f == NULL) {
say_warn("failed to allocate a fiber to run shutdown routines.");
--
2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2018-12-11 13:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 13:24 [tarantool-patches] [PATCH v3 0/3] " Serge Petrenko
2018-12-11 13:24 ` [tarantool-patches] [PATCH v3 1/3] box: get rid of atexit() for calling cleanup routine Serge Petrenko
2018-12-27 12:43 ` Vladimir Davydov
2018-12-27 12:50 ` Konstantin Osipov
2018-12-27 12:56 ` Vladimir Davydov
2018-12-28 7:43 ` [tarantool-patches] " Konstantin Osipov
2018-12-28 7:58 ` Vladimir Davydov
2018-12-29 13:54 ` Serge Petrenko
2018-12-11 13:24 ` Serge Petrenko [this message]
2018-12-27 13:11 ` [tarantool-patches] [PATCH v3 2/3] box: implement on_shutdown triggers Vladimir Davydov
2018-12-11 13:24 ` [tarantool-patches] [PATCH v3 3/3] box: introduce on_shutdown triggers to lua Serge Petrenko
2018-12-27 13:14 ` Vladimir Davydov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33b51ca5edbeb8bce134d62bff83e02faaa936e9.1544533138.git.sergepetrenko@tarantool.org \
--to=sergepetrenko@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v3 2/3] box: implement on_shutdown triggers' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox