MXS-1929: Split housekeeper initialization
The initialization and starting of the housekeeper is now done separately. This allows housekeeper tasks to be created when the services are being created while still preventing the execution of the task before the startup is complete.
This commit is contained in:
parent
843b8d92eb
commit
a553ddba6e
@ -44,6 +44,13 @@ typedef bool (*TASKFN)(void *data);
|
||||
*/
|
||||
bool hkinit();
|
||||
|
||||
/**
|
||||
* Start the housekeeper thread
|
||||
*
|
||||
* @return True if the housekeeper mechanism was started
|
||||
*/
|
||||
bool hkstart();
|
||||
|
||||
/**
|
||||
* Waits for the housekeeper thread to finish.
|
||||
*/
|
||||
|
@ -1969,6 +1969,15 @@ int main(int argc, char **argv)
|
||||
goto return_main;
|
||||
}
|
||||
|
||||
// Initialize the housekeeper
|
||||
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 (!config_load(cnf_file_path))
|
||||
{
|
||||
const char* fprerr =
|
||||
@ -2071,7 +2080,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// Start the housekeeper thread
|
||||
if (!hkinit())
|
||||
if (!hkstart())
|
||||
{
|
||||
const char* logerr = "Failed to start housekeeper thread.";
|
||||
print_log_n_stderr(true, true, logerr, logerr, 0);
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
Housekeeper();
|
||||
|
||||
static bool init();
|
||||
static bool start();
|
||||
void stop();
|
||||
void run();
|
||||
void add(const Task& task);
|
||||
@ -130,11 +131,16 @@ Housekeeper::Housekeeper():
|
||||
}
|
||||
|
||||
bool Housekeeper::init()
|
||||
{
|
||||
hk = new (std::nothrow) Housekeeper;
|
||||
return hk != nullptr;
|
||||
}
|
||||
|
||||
bool Housekeeper::start()
|
||||
{
|
||||
struct hkinit_result res;
|
||||
sem_init(&res.sem, 0, 0);
|
||||
res.ok = false;
|
||||
hk = new (std::nothrow) Housekeeper;
|
||||
|
||||
if (hk && thread_start(&hk->m_thread, hkthread, &res, 0) != NULL)
|
||||
{
|
||||
@ -148,7 +154,6 @@ bool Housekeeper::init()
|
||||
sem_destroy(&res.sem);
|
||||
return res.ok;
|
||||
}
|
||||
|
||||
void Housekeeper::run()
|
||||
{
|
||||
while (is_running())
|
||||
@ -288,6 +293,11 @@ bool hkinit()
|
||||
return Housekeeper::init();
|
||||
}
|
||||
|
||||
bool hkstart()
|
||||
{
|
||||
return Housekeeper::start();
|
||||
}
|
||||
|
||||
void hkfinish()
|
||||
{
|
||||
if (hk)
|
||||
|
Loading…
x
Reference in New Issue
Block a user