MXS-2218 Implement housekeeper in terms of MainWorker
This commit is contained in:
parent
026bf747e6
commit
6ba2cb61df
@ -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
|
||||
*
|
||||
|
@ -12,7 +12,6 @@ add_library(maxscale-common SHARED
|
||||
externcmd.cc
|
||||
filter.cc
|
||||
hint.cc
|
||||
housekeeper.cc
|
||||
httprequest.cc
|
||||
httpresponse.cc
|
||||
json_api.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.
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -32,11 +32,12 @@
|
||||
#include <maxscale/server.hh>
|
||||
#include <maxscale/router.hh>
|
||||
#include <maxbase/atomic.h>
|
||||
#include <maxbase/maxbase.hh>
|
||||
#include <maxscale/dcb.hh>
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <time.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/mainworker.hh>
|
||||
#include <maxscale/utils.hh>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user