From ecc744235815cf5269cf07335ecb964375c6e8e7 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 7 Nov 2018 16:56:52 +0200 Subject: [PATCH] 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. --- include/maxscale/monitor.hh | 9 +++++++++ server/core/monitor.cc | 20 +++++++++++-------- .../modules/monitor/mariadbmon/mariadbmon.cc | 5 +++++ .../modules/monitor/mariadbmon/mariadbmon.hh | 1 + 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 65525aef1..5359b09b4 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -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 */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index d0d4d185c..2c9ce9237 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -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(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; +} } diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index d21420c76..09a3bbcd6 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -757,6 +757,11 @@ bool MariaDBMonitor::execute_manual_command(std::function 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) { diff --git a/server/modules/monitor/mariadbmon/mariadbmon.hh b/server/modules/monitor/mariadbmon/mariadbmon.hh index a4d49fa80..9cf58696a 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.hh +++ b/server/modules/monitor/mariadbmon/mariadbmon.hh @@ -245,6 +245,7 @@ private: void clear_server_info(); void reset_node_index_info(); bool execute_manual_command(std::function command, json_t** error_out); + bool immediate_tick_required() const; std::string diagnostics_to_string() const; json_t* to_json() const;