[tarantool-patches] [PATCH v2 1/3] box: implement on_shutdown triggers

Serge Petrenko sergepetrenko at tarantool.org
Mon Nov 26 17:25:04 MSK 2018


From: Konstantin Osipov <kostja at 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 |  8 ++++++++
 src/box/box.h  | 11 +++++++++++
 src/main.cc    |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/src/box/box.cc b/src/box/box.cc
index 7a1171c62..72049fabf 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,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 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)





More information about the Tarantool-patches mailing list