Detect manual commands faster

Previous, MariaDBMonitor would wait until the next monitor interval before detecting
a new manual command. The commands are now checked every 100 ms.
This commit is contained in:
Esa Korhonen 2018-11-07 16:56:52 +02:00
parent 8058e46309
commit ecc7442358
4 changed files with 27 additions and 8 deletions

View File

@ -209,6 +209,15 @@ protected:
*/
virtual void process_state_changes();
/**
* Should a monitor tick be ran immediately? The base class version always returns false. A monitor can
* override this to add specific conditions. This function is called every MXS_MON_BASE_INTERVAL_MS
* (100 ms) by the monitor worker thread, which then runs a monitor tick if true is returned.
*
* @return True if tick should be ran
*/
virtual bool immediate_tick_required() const;
MXS_MONITOR* m_monitor; /**< The generic monitor structure. */
MXS_MONITORED_SERVER* m_master; /**< Master server */

View File

@ -2496,7 +2496,7 @@ MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
, m_thread_running(false)
, m_shutdown(0)
, m_checked(false)
, m_loop_called(0)
, m_loop_called(get_time_ms())
{
}
@ -2563,8 +2563,7 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
if (configure(pParams))
{
m_loop_called = 0;
m_loop_called = get_time_ms() - m_monitor->interval; // Next tick should happen immediately.
if (!Worker::start())
{
MXS_ERROR("Failed to start worker for monitor '%s'.", m_monitor->name);
@ -2906,14 +2905,15 @@ bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action)
if (action == Worker::Call::EXECUTE)
{
int64_t now = get_time_ms();
// Enough time has passed,
if ((now - m_loop_called > static_cast<int64_t>(m_monitor->interval))
|| atomic_load_int(&m_monitor->check_maintenance_flag) == MAINTENANCE_FLAG_CHECK)
// or maintenance flag is set,
|| atomic_load_int(&m_monitor->check_maintenance_flag) == MAINTENANCE_FLAG_CHECK
// or a monitor-specific condition is met.
|| immediate_tick_required())
{
m_loop_called = now;
run_one_tick();
now = get_time_ms();
}
@ -2925,7 +2925,6 @@ bool MonitorInstance::call_run_one_tick(Worker::Call::action_t action)
delayed_call(delay, &MonitorInstance::call_run_one_tick, this);
}
return false;
}
@ -2943,4 +2942,9 @@ void MonitorInstance::run_one_tick()
mon_hangup_failed_servers(m_monitor);
store_server_journal(m_monitor, m_master);
}
bool MonitorInstance::immediate_tick_required() const
{
return false;
}
}

View File

@ -757,6 +757,11 @@ bool MariaDBMonitor::execute_manual_command(std::function<void(void)> command, j
return rval;
}
bool MariaDBMonitor::immediate_tick_required() const
{
return m_manual_cmd.command_waiting_exec;
}
bool MariaDBMonitor::run_manual_switchover(SERVER* promotion_server, SERVER* demotion_server,
json_t** error_out)
{

View File

@ -245,6 +245,7 @@ private:
void clear_server_info();
void reset_node_index_info();
bool execute_manual_command(std::function<void ()> command, json_t** error_out);
bool immediate_tick_required() const;
std::string diagnostics_to_string() const;
json_t* to_json() const;