diff --git a/include/maxscale/housekeeper.h b/include/maxscale/housekeeper.h index 46861a382..d5552ab46 100644 --- a/include/maxscale/housekeeper.h +++ b/include/maxscale/housekeeper.h @@ -32,30 +32,6 @@ MXS_BEGIN_DECLS */ 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 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. - */ -bool hkinit(); - -/** - * Start the housekeeper thread - * - * @return True if the housekeeper mechanism was started - */ -bool hkstart(); - -/** - * Waits for the housekeeper thread to finish. - */ -void hkfinish(); - /** * @brief Add a new task * diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 78e46561d..d49d87bc2 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -12,7 +12,6 @@ add_library(maxscale-common SHARED externcmd.cc filter.cc hint.cc - housekeeper.cc httprequest.cc httpresponse.cc json_api.cc diff --git a/server/core/gateway.cc b/server/core/gateway.cc index e40853cfa..d09171a8b 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -2072,13 +2072,6 @@ int main(int argc, char** argv) // Initialize the housekeeper main_worker = new maxscale::MainWorker; - if (!hkinit()) - { - const char* logerr = "Failed to initialize housekeeper"; - print_log_n_stderr(true, true, logerr, logerr, 0); - rc = MAXSCALE_INTERNALERROR; - goto return_main; - } if (!qc_setup(&cnf->qc_cache_properties, cnf->qc_sql_mode, cnf->qc_name, cnf->qc_args)) { @@ -2203,15 +2196,6 @@ int main(int argc, char** argv) goto return_main; } - // Start the housekeeper thread - if (!hkstart()) - { - 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 */ monitor_start_all(); @@ -2290,11 +2274,6 @@ int main(int argc, char** argv) /*< Destroy all monitors */ monitor_destroy_all(); - /*< - * Wait for the housekeeper to finish. - */ - hkfinish(); - /*< * Wait for worker threads to exit. */ diff --git a/server/core/mainworker.cc b/server/core/mainworker.cc index e3f193cb8..744000d5c 100644 --- a/server/core/mainworker.cc +++ b/server/core/mainworker.cc @@ -206,3 +206,33 @@ bool MainWorker::inc_ticks(Worker::Call::action_t action) } } + +extern "C" +{ + +void hktask_add(const char* zName, TASKFN func, void* pData, int frequency) +{ + mxs::MainWorker::get().add_task(zName, func, pData, frequency); +} + +void hktask_remove(const char* zName) +{ + mxs::MainWorker::get().remove_task(zName); +} + +void hkshow_tasks(DCB* pDcb) +{ + mxs::MainWorker::get().show_tasks(pDcb); +} + +json_t* hk_tasks_json(const char* zHost) +{ + return mxs::MainWorker::get().tasks_to_json(zHost); +} + +int64_t mxs_clock() +{ + return mxs::MainWorker::ticks(); +} + +} diff --git a/server/core/test/test_housekeeper.cc b/server/core/test/test_housekeeper.cc index 76b5c5275..ab54e1ec8 100644 --- a/server/core/test/test_housekeeper.cc +++ b/server/core/test/test_housekeeper.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include "test_utils.hh" using namespace std; @@ -92,23 +93,13 @@ int main(int argc, char** argv) init_test_env(); - if (hkinit()) - { - if (hkstart()) - { - rc = test(); - } - else - { - cerr << "Could not start the housekeeper." << endl; - } + maxscale::MainWorker mw; + mw.start(); - hkfinish(); - } - else - { - cerr << "Could not initialize the housekeeper." << endl; - } + rc = test(); + + mw.shutdown(); + mw.join(); return rc; } diff --git a/server/core/test/test_utils.hh b/server/core/test/test_utils.hh index e07e7338f..9a16bde6a 100644 --- a/server/core/test/test_utils.hh +++ b/server/core/test/test_utils.hh @@ -57,7 +57,6 @@ void init_test_env(char* __attribute((unused)) path = nullptr, uint32_t init_typ poll_init(); maxbase::init(); maxscale::RoutingWorker::init(); - hkinit(); set_libdir(MXS_STRDUP(old_libdir.c_str())); preload_module("mariadbclient", "server/modules/protocol/MySQL/mariadbclient/", MODULE_PROTOCOL); diff --git a/server/modules/routing/binlogrouter/test/testbinlog.cc b/server/modules/routing/binlogrouter/test/testbinlog.cc index 6d40e6d6a..c46c52687 100644 --- a/server/modules/routing/binlogrouter/test/testbinlog.cc +++ b/server/modules/routing/binlogrouter/test/testbinlog.cc @@ -32,11 +32,12 @@ #include #include #include +#include #include -#include #include #include #include +#include #include #include "../../../../core/internal/modules.hh" #include "../../../../core/internal/config.hh" @@ -105,8 +106,10 @@ int main(int argc, char** argv) set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/")); load_module("qc_sqlite", MODULE_QUERY_CLASSIFIER); + maxbase::MaxBase initer; + maxscale::MainWorker mw; + mw.start(); qc_init(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL); - hkinit(); CONFIG_CONTEXT ctx {(char*)""}; config_add_defaults(&ctx, get_module("binlogrouter", MODULE_ROUTER)->parameters); @@ -909,6 +912,8 @@ int main(int argc, char** argv) MXS_FREE(inst->password); MXS_FREE(inst->fileroot); MXS_FREE(inst); + mw.shutdown(); + mw.join(); return 0; }