[tarantool-patches] [PATCH] box: implement on_shutdown triggers

Konstantin Osipov kostja at tarantool.org
Thu Nov 1 15:53:49 MSK 2018


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




More information about the Tarantool-patches mailing list