MXS-2218 Implement housekeeper in terms of MainWorker

This commit is contained in:
Johan Wikman
2019-01-08 10:23:16 +02:00
parent 026bf747e6
commit 6ba2cb61df
7 changed files with 44 additions and 65 deletions

View File

@ -12,7 +12,6 @@ add_library(maxscale-common SHARED
externcmd.cc
filter.cc
hint.cc
housekeeper.cc
httprequest.cc
httpresponse.cc
json_api.cc

View File

@ -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.
*/

View File

@ -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();
}
}

View File

@ -15,6 +15,7 @@
#include <iostream>
#include <maxbase/log.hh>
#include <maxscale/housekeeper.h>
#include <maxscale/mainworker.hh>
#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;
}

View File

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