Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop MainWorker after RoutingWorkers
This allows normal operation during the shutdown. This fixes the problem
where mxs_clock would not get updated after the shutdown was initiated.
  • Loading branch information
markus456 committed Jul 17, 2020
1 parent ba1079e commit 23fbcca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/maxscale/mainworker.hh
Expand Up @@ -140,6 +140,9 @@ private:
bool balance_workers_dc(Worker::Call::action_t action);
void order_balancing_dc();

// Waits until all RoutingWorkers have stopped and then stops the MainWorker
bool wait_for_shutdown(Worker::Call::action_t action);

std::map<std::string, Task> m_tasks_by_name;
IndexedStorage m_storage;
uint32_t m_rebalancing_dc {0};
Expand Down
5 changes: 5 additions & 0 deletions include/maxscale/routingworker.hh
Expand Up @@ -262,6 +262,11 @@ public:
*/
static void join_workers();

/**
* Check if all workers have finished shutting down
*/
static bool shutdown_complete();

/**
* Posts a task to all workers for execution.
*
Expand Down
18 changes: 16 additions & 2 deletions server/core/mainworker.cc
Expand Up @@ -312,12 +312,26 @@ void MainWorker::start_shutdown()
// will exit the event loop.
mxs::RoutingWorker::start_shutdown();

// Stop the MainWorker now that shutdown has been started
MainWorker::get()->shutdown();
// Wait until RoutingWorkers have stopped before proceeding with MainWorker shudown
auto self = MainWorker::get();
self->delayed_call(100, &MainWorker::wait_for_shutdown, self);
};

MainWorker::get()->execute(func, EXECUTE_QUEUED);
}

bool MainWorker::wait_for_shutdown(Call::action_t action)
{
if (action == Call::EXECUTE)
{
if (RoutingWorker::shutdown_complete())
{
shutdown();
}
}

return true;
}
}

extern "C"
Expand Down
19 changes: 19 additions & 0 deletions server/core/routingworker.cc
Expand Up @@ -407,6 +407,25 @@ void RoutingWorker::join_workers()
this_unit.running = false;
}

// static
bool RoutingWorker::shutdown_complete()
{
bool rval = true;

for (int i = this_unit.id_min_worker; i <= this_unit.id_max_worker; i++)
{
RoutingWorker* pWorker = this_unit.ppWorkers[i];
mxb_assert(pWorker);

if (pWorker->state() != Worker::FINISHED && pWorker->state() != Worker::STOPPED)
{
rval = false;
}
}

return rval;
}

RoutingWorker::SessionsById& RoutingWorker::session_registry()
{
return m_sessions;
Expand Down

0 comments on commit 23fbcca

Please sign in to comment.