From ce98831908d2d6bb647f88d347df0330f1b2228d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 24 Apr 2018 10:23:32 +0300 Subject: [PATCH] Start housekeeper before services The housekeeper needs to be initialized before services are started. --- include/maxscale/housekeeper.h | 4 +++- server/core/gateway.cc | 20 +++++++++----------- server/core/housekeeper.cc | 5 +++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/maxscale/housekeeper.h b/include/maxscale/housekeeper.h index f86f51a84..432ad2c46 100644 --- a/include/maxscale/housekeeper.h +++ b/include/maxscale/housekeeper.h @@ -36,7 +36,9 @@ typedef bool (*TASKFN)(void *data); * Initialises the housekeeper mechanism. * * A call to any of the other housekeeper functions can be made only if - * this function returns successfully. + * this function returns successfully. This function must be called after all + * module level initialization is done but before any monitors or services are + * started. * * @return True if the housekeeper mechanism was initialized, false otherwise. */ diff --git a/server/core/gateway.cc b/server/core/gateway.cc index b6f661efc..1fd56b78c 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -2142,6 +2142,15 @@ int main(int argc, char **argv) goto return_main; } + // Start the housekeeper thread + if (!hkinit()) + { + const char* logerr = "Failed to start housekeeper thread."; + print_log_n_stderr(true, true, logerr, logerr, 0); + rc = MAXSCALE_INTERNALERROR; + goto return_main; + } + /** Start all monitors */ monitorStartAll(); @@ -2176,17 +2185,6 @@ int main(int argc, char **argv) goto return_main; } - /* - * Start the housekeeper thread - */ - if (!hkinit()) - { - const char* logerr = "Failed to start housekeeper thread."; - print_log_n_stderr(true, true, logerr, logerr, 0); - rc = MAXSCALE_INTERNALERROR; - goto return_main; - } - /*< * Start the routing workers running in their own thread. */ diff --git a/server/core/housekeeper.cc b/server/core/housekeeper.cc index efb11d914..047dd2447 100644 --- a/server/core/housekeeper.cc +++ b/server/core/housekeeper.cc @@ -256,12 +256,14 @@ json_t* Housekeeper::tasks_json(const char* host) void hktask_add(const char *name, TASKFN func, void *data, int frequency) { + ss_dassert(hk); Task task(name, func, data, frequency); hk->add(task); } void hktask_remove(const char *name) { + ss_dassert(hk); hk->remove(name); } @@ -293,6 +295,7 @@ bool hkinit() void hkshutdown() { + ss_dassert(hk); hk->stop(); } @@ -306,10 +309,12 @@ void hkfinish() void hkshow_tasks(DCB *pDcb) { + ss_dassert(hk); hk->print_tasks(pDcb); } json_t* hk_tasks_json(const char* host) { + ss_dassert(hk); return hk->tasks_json(host); }