Move items from MonitorWorker to MonitorWorkerSimple

MonitorWorker only enforces the use of a worker thread but otherwise
does not define how the monitor is implemented.
This commit is contained in:
Esa Korhonen 2019-04-11 15:20:05 +03:00
parent 2bc0b9c875
commit 75c0ac5323
4 changed files with 50 additions and 22 deletions

View File

@ -761,8 +761,6 @@ protected:
*/
virtual bool immediate_tick_required() const;
MonitorServer* m_master; /**< Master server */
private:
std::atomic<bool> m_thread_running; /**< Thread state. Only visible inside MonitorInstance. */
int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */
@ -811,11 +809,16 @@ protected:
*/
virtual void post_tick();
MonitorServer* m_master {nullptr}; /**< Master server */
private:
/**
* @brief Monitor the servers
*
* This function is called once per monitor round and will for each server:
* This function is called once per monitor round. It does the following:
* - Perform any maintenance or drain state changes requested by user
*
* -Then, for each server:
*
* - Do nothing, if the server is in maintenance.
* - Store the previous status of the server.
@ -826,8 +829,17 @@ private:
* If there is not, the pending status will be updated accordingly and
* @c update_server_status() will *not* be called.
* - After the call, update the error count of the server if it is down.
*
* - Flush states for all servers
* - Launch monitor scripts for events
* - Hangup failed servers
* - Store monitor journal
*/
void tick(); // final
void tick() final;
void pre_loop() final;
void post_loop() final;
};
/**

View File

@ -2280,7 +2280,6 @@ bool Monitor::check_disk_space_this_tick()
MonitorWorker::MonitorWorker(const string& name, const string& module)
: Monitor(name, module)
, m_master(NULL)
, m_thread_running(false)
, m_shutdown(0)
, m_checked(false)
@ -2354,7 +2353,6 @@ bool MonitorWorker::start()
bool started = false;
if (m_checked)
{
m_master = NULL;
m_loop_called = get_time_ms() - m_settings.interval; // Next tick should happen immediately.
if (!Worker::start())
{
@ -2545,6 +2543,18 @@ void MonitorWorker::flush_server_status()
}
}
void MonitorWorkerSimple::pre_loop()
{
m_master = nullptr;
load_server_journal(&m_master);
// Add another overridable function for derived classes (e.g. pre_loop_monsimple) if required.
}
void MonitorWorkerSimple::post_loop()
{
}
void MonitorWorkerSimple::pre_tick()
{
}
@ -2555,6 +2565,7 @@ void MonitorWorkerSimple::post_tick()
void MonitorWorkerSimple::tick()
{
check_maintenance_requests();
pre_tick();
const bool should_update_disk_space = check_disk_space_this_tick();
@ -2628,6 +2639,11 @@ void MonitorWorkerSimple::tick()
}
post_tick();
flush_server_status();
process_state_changes();
hangup_failed_servers();
store_server_journal(m_master);
}
void MonitorWorker::pre_loop()
@ -2654,7 +2670,6 @@ bool MonitorWorker::pre_run()
m_thread_running.store(true, std::memory_order_release);
m_semaphore.post();
load_server_journal(&m_master);
pre_loop();
delayed_call(1, &MonitorWorker::call_run_one_tick, this);
}
@ -2707,17 +2722,8 @@ bool MonitorWorker::call_run_one_tick(Worker::Call::action_t action)
void MonitorWorker::run_one_tick()
{
check_maintenance_requests();
tick();
mxb::atomic::add(&m_ticks, 1, mxb::atomic::RELAXED);
flush_server_status();
process_state_changes();
hangup_failed_servers();
store_server_journal(m_master);
}
bool MonitorWorker::immediate_tick_required() const

View File

@ -248,6 +248,7 @@ void ClustrixMonitor::server_removed(SERVER* pServer)
void ClustrixMonitor::pre_loop()
{
load_server_journal(nullptr);
if (m_config.dynamic_node_detection())
{
// At startup we accept softfailed nodes in an attempt to be able to
@ -275,6 +276,7 @@ void ClustrixMonitor::post_loop()
void ClustrixMonitor::tick()
{
check_maintenance_requests();
if (m_config.dynamic_node_detection() && should_check_cluster())
{
check_cluster(Clustrix::Softfailed::REJECT);
@ -300,6 +302,11 @@ void ClustrixMonitor::tick()
}
break;
}
flush_server_status();
process_state_changes();
hangup_failed_servers();
store_server_journal(nullptr);
}
void ClustrixMonitor::choose_hub(Clustrix::Softfailed softfailed)

View File

@ -350,9 +350,10 @@ json_t* MariaDBMonitor::to_json() const
void MariaDBMonitor::pre_loop()
{
// MonitorInstance reads the journal and has the last known master in its m_master member variable.
// Read the journal and the last known master.
// Write the corresponding MariaDBServer into the class-specific m_master variable.
auto journal_master = MonitorWorker::m_master;
MonitorServer* journal_master = nullptr;
load_server_journal(&journal_master);
if (journal_master)
{
// This is somewhat questionable, as the journal only contains status bits but no actual topology
@ -375,6 +376,8 @@ void MariaDBMonitor::pre_loop()
void MariaDBMonitor::tick()
{
check_maintenance_requests();
/* Update MonitorServer->pending_status. This is where the monitor loop writes it's findings.
* Also, backup current status so that it can be compared to any deduced state. */
for (auto srv : m_servers)
@ -463,10 +466,10 @@ void MariaDBMonitor::tick()
log_master_changes();
// Before exiting, we need to store the current master into the m_master
// member variable of MonitorInstance so that the right server will be
// stored to the journal.
MonitorWorker::m_master = m_master ? m_master->m_server_base : NULL;
flush_server_status();
process_state_changes();
hangup_failed_servers();
store_server_journal(m_master ? m_master->m_server_base : nullptr);
}
void MariaDBMonitor::process_state_changes()