MXS-1775 Rearrange for moving main loop to MonitorInstance
This is another step in the process for moving the main loop from MariaDBMonitor to MonitorInstance.
This commit is contained in:
@ -56,6 +56,7 @@ MariaDBMonitor::MariaDBMonitor(MXS_MONITOR* monitor)
|
||||
, m_external_master_port(PORT_UNKNOWN)
|
||||
, m_cluster_modified(true)
|
||||
, m_warn_set_standalone_master(true)
|
||||
, m_log_no_master(true)
|
||||
{}
|
||||
|
||||
MariaDBMonitor::~MariaDBMonitor()
|
||||
@ -280,12 +281,11 @@ void MariaDBMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server
|
||||
(*i).second->update_server(m_monitor);
|
||||
}
|
||||
|
||||
void MariaDBMonitor::main()
|
||||
void MariaDBMonitor::pre_loop()
|
||||
{
|
||||
MariaDBServer* root_master = NULL;
|
||||
int log_no_master = 1;
|
||||
MonitorInstance::pre_loop();
|
||||
|
||||
load_journal();
|
||||
m_master = MonitorInstance::m_master ? get_server_info(MonitorInstance::m_master) : NULL;
|
||||
|
||||
if (m_detect_replication_lag)
|
||||
{
|
||||
@ -302,6 +302,13 @@ void MariaDBMonitor::main()
|
||||
(*iter)->m_server_base->con = NULL;
|
||||
}
|
||||
|
||||
m_log_no_master = true;
|
||||
}
|
||||
|
||||
void MariaDBMonitor::main()
|
||||
{
|
||||
pre_loop();
|
||||
|
||||
while (!should_shutdown())
|
||||
{
|
||||
atomic_add_uint64(&m_monitor->ticks, 1);
|
||||
@ -335,7 +342,7 @@ void MariaDBMonitor::main()
|
||||
}
|
||||
|
||||
// Use the information to find the so far best master server.
|
||||
root_master = find_root_master();
|
||||
MariaDBServer* root_master = find_root_master();
|
||||
|
||||
if (m_master != NULL && m_master->is_master())
|
||||
{
|
||||
@ -425,7 +432,7 @@ void MariaDBMonitor::main()
|
||||
}
|
||||
|
||||
/* log master detection failure of first master becomes available after failure */
|
||||
log_master_changes(root_master, &log_no_master);
|
||||
log_master_changes(root_master);
|
||||
|
||||
// Do not auto-join servers on this monitor loop if a failover (or any other cluster modification)
|
||||
// has been performed, as server states have not been updated yet. It will happen next iteration.
|
||||
@ -537,7 +544,7 @@ void MariaDBMonitor::measure_replication_lag(MariaDBServer* root_master)
|
||||
}
|
||||
}
|
||||
|
||||
void MariaDBMonitor::log_master_changes(MariaDBServer* root_master_server, int* log_no_master)
|
||||
void MariaDBMonitor::log_master_changes(MariaDBServer* root_master_server)
|
||||
{
|
||||
MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->m_server_base : NULL;
|
||||
if (root_master && mon_status_changed(root_master) &&
|
||||
@ -559,14 +566,14 @@ void MariaDBMonitor::log_master_changes(MariaDBServer* root_master_server, int*
|
||||
root_master->server->address,
|
||||
root_master->server->port);
|
||||
}
|
||||
*log_no_master = 1;
|
||||
m_log_no_master = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!root_master && *log_no_master)
|
||||
if (!root_master && m_log_no_master)
|
||||
{
|
||||
MXS_ERROR("No Master can be determined");
|
||||
*log_no_master = 0;
|
||||
m_log_no_master = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -857,17 +864,6 @@ void MariaDBMonitor::disable_setting(const char* setting)
|
||||
monitor_add_parameters(m_monitor, &p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads saved server states. Should only be called once at the beginning of the main loop after server
|
||||
* creation.
|
||||
*/
|
||||
void MariaDBMonitor::load_journal()
|
||||
{
|
||||
MXS_MONITORED_SERVER* master_output = NULL;
|
||||
load_server_journal(m_monitor, &master_output);
|
||||
m_master = master_output ? get_server_info(master_output) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check sql text file parameters. A parameter should either be empty or a valid file which can be opened.
|
||||
*
|
||||
|
@ -100,6 +100,7 @@ public:
|
||||
|
||||
protected:
|
||||
void update_server_status(MXS_MONITORED_SERVER* pMonitored_server);
|
||||
void pre_loop();
|
||||
void main();
|
||||
|
||||
private:
|
||||
@ -146,6 +147,7 @@ private:
|
||||
std::string m_script; /**< Script to call when state changes occur on servers */
|
||||
uint64_t m_events; /**< enabled events */
|
||||
bool m_warn_set_standalone_master; /**< Log a warning when setting standalone master */
|
||||
bool m_log_no_master; /**< Should it be logged that there is no master */
|
||||
|
||||
enum slave_down_setting_t
|
||||
{
|
||||
@ -171,7 +173,7 @@ private:
|
||||
bool standalone_master_required();
|
||||
bool set_standalone_master();
|
||||
void assign_relay_master(MariaDBServer& serv_info);
|
||||
void log_master_changes(MariaDBServer* root_master, int* log_no_master);
|
||||
void log_master_changes(MariaDBServer* root_master);
|
||||
void update_gtid_domain();
|
||||
void update_external_master();
|
||||
void set_master_heartbeat(MariaDBServer*);
|
||||
@ -229,7 +231,6 @@ private:
|
||||
|
||||
// Other methods
|
||||
void disable_setting(const char* setting);
|
||||
void load_journal();
|
||||
bool check_sql_files();
|
||||
void enforce_read_only_on_slaves();
|
||||
};
|
||||
|
Reference in New Issue
Block a user