Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: kostja@tarantool.org, tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 1/2] box: implement on_shutdown triggers
Date: Thu, 22 Nov 2018 20:20:54 +0300	[thread overview]
Message-ID: <00e7bd1333fa26130979fd71b1d113c9f37076c4.1542906167.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1542906167.git.sergepetrenko@tarantool.org>
In-Reply-To: <cover.1542906167.git.sergepetrenko@tarantool.org>

From: Konstantin Osipov <kostja@tarantool.org>

@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)

  reply	other threads:[~2018-11-22 17:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 17:20 [tarantool-patches] [PATCH 0/2] " Serge Petrenko
2018-11-22 17:20 ` Serge Petrenko [this message]
2018-11-22 17:20 ` [tarantool-patches] [PATCH 2/2] box: introduce on_shutdown triggers to lua Serge Petrenko
2018-11-23 10:37   ` [tarantool-patches] " Konstantin Osipov

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=00e7bd1333fa26130979fd71b1d113c9f37076c4.1542906167.git.sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/2] 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