Move last MariaDB-Monitor settings inside class
This commit is contained in:
@ -626,7 +626,7 @@ uint32_t MariaDBMonitor::do_rejoin(const ServerArray& joinable_servers, json_t**
|
||||
bool op_success = false;
|
||||
// Rejoin doesn't have its own time limit setting. Use switchover time limit for now since
|
||||
// the first phase of standalone rejoin is similar to switchover.
|
||||
maxbase::Duration time_limit((double)m_switchover_timeout);
|
||||
maxbase::Duration time_limit((double)m_settings.switchover_timeout);
|
||||
GeneralOpData general(output, time_limit);
|
||||
|
||||
if (joinable->m_slave_status.empty())
|
||||
@ -1261,7 +1261,7 @@ MariaDBMonitor::select_promotion_target(MariaDBServer* demotion_target, Operatio
|
||||
*/
|
||||
bool MariaDBMonitor::server_is_excluded(const MariaDBServer* server)
|
||||
{
|
||||
for (MariaDBServer* excluded : m_excluded_servers)
|
||||
for (MariaDBServer* excluded : m_settings.excluded_servers)
|
||||
{
|
||||
if (excluded == server)
|
||||
{
|
||||
@ -1444,8 +1444,8 @@ unique_ptr<MariaDBMonitor::FailoverParams> MariaDBMonitor::failover_prepare(Log
|
||||
}
|
||||
else
|
||||
{
|
||||
// The Duration ctor taking a double interprets is as seconds.
|
||||
auto time_limit = maxbase::Duration((double)m_failover_timeout);
|
||||
// The Duration ctor taking a double interprets the value as seconds.
|
||||
auto time_limit = maxbase::Duration((double)m_settings.failover_timeout);
|
||||
bool promoting_to_master = (demotion_target == m_master);
|
||||
ServerOperation promotion(promotion_target, promoting_to_master,
|
||||
demotion_target->m_slave_status, demotion_target->m_enabled_events);
|
||||
@ -1485,7 +1485,7 @@ void MariaDBMonitor::handle_auto_failover()
|
||||
m_warn_master_down = false;
|
||||
}
|
||||
// If master seems to be down, check if slaves are receiving events.
|
||||
else if (m_verify_master_failure
|
||||
else if (m_settings.verify_master_failure
|
||||
&& (connected_slave = slave_receiving_events(m_master, &event_age, &delay_time)) != NULL)
|
||||
{
|
||||
MXS_NOTICE("Slave '%s' is still connected to '%s' and received a new gtid or heartbeat event %.1f "
|
||||
@ -1589,7 +1589,7 @@ void MariaDBMonitor::check_cluster_operations_support()
|
||||
const MariaDBServer* MariaDBMonitor::slave_receiving_events(const MariaDBServer* demotion_target,
|
||||
Duration* event_age_out, Duration* delay_out)
|
||||
{
|
||||
Duration event_timeout(static_cast<double>(m_master_failure_timeout));
|
||||
Duration event_timeout(static_cast<double>(m_settings.master_failure_timeout));
|
||||
auto current_time = maxbase::Clock::now();
|
||||
maxbase::Clock::time_point recent_event_time = current_time - event_timeout;
|
||||
|
||||
@ -1718,7 +1718,7 @@ MariaDBMonitor::switchover_prepare(SERVER* promotion_server, SERVER* demotion_se
|
||||
unique_ptr<SwitchoverParams> rval;
|
||||
if (promotion_target && demotion_target && gtid_ok)
|
||||
{
|
||||
maxbase::Duration time_limit((double)m_switchover_timeout);
|
||||
maxbase::Duration time_limit((double)m_settings.switchover_timeout);
|
||||
bool master_swap = (demotion_target == m_master);
|
||||
ServerOperation promotion(promotion_target, master_swap,
|
||||
demotion_target->m_slave_status, demotion_target->m_enabled_events);
|
||||
|
@ -66,7 +66,10 @@ MariaDBMonitor::MariaDBMonitor(const string& name, const string& module)
|
||||
|
||||
MariaDBMonitor::~MariaDBMonitor()
|
||||
{
|
||||
clear_server_info();
|
||||
for (auto server : m_servers)
|
||||
{
|
||||
delete server;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,17 +78,6 @@ MariaDBMonitor::~MariaDBMonitor()
|
||||
void MariaDBMonitor::reset_server_info()
|
||||
{
|
||||
// If this monitor is being restarted, the server data needs to be freed.
|
||||
clear_server_info();
|
||||
|
||||
// Next, initialize the data.
|
||||
for (auto mon_server : servers())
|
||||
{
|
||||
m_servers.push_back(new MariaDBServer(mon_server, m_servers.size(), m_settings.shared));
|
||||
}
|
||||
}
|
||||
|
||||
void MariaDBMonitor::clear_server_info()
|
||||
{
|
||||
for (auto server : m_servers)
|
||||
{
|
||||
delete server;
|
||||
@ -93,12 +85,17 @@ void MariaDBMonitor::clear_server_info()
|
||||
// All MariaDBServer*:s are now invalid, as well as any dependant data.
|
||||
m_servers.clear();
|
||||
m_servers_by_id.clear();
|
||||
m_excluded_servers.clear();
|
||||
assign_new_master(NULL);
|
||||
m_next_master = NULL;
|
||||
m_master_gtid_domain = GTID_DOMAIN_UNKNOWN;
|
||||
m_external_master_host.clear();
|
||||
m_external_master_port = PORT_UNKNOWN;
|
||||
|
||||
// Next, initialize the data.
|
||||
for (auto mon_server : servers())
|
||||
{
|
||||
m_servers.push_back(new MariaDBServer(mon_server, m_servers.size(), m_settings.shared));
|
||||
}
|
||||
}
|
||||
|
||||
void MariaDBMonitor::reset_node_index_info()
|
||||
@ -219,14 +216,14 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params)
|
||||
m_settings.ignore_external_masters = params->get_bool("ignore_external_masters");
|
||||
m_settings.shared.assume_unique_hostnames = params->get_bool(CN_ASSUME_UNIQUE_HOSTNAMES);
|
||||
m_settings.failcount = params->get_integer(CN_FAILCOUNT);
|
||||
m_failover_timeout = params->get_duration<std::chrono::seconds>(CN_FAILOVER_TIMEOUT).count();
|
||||
m_switchover_timeout = params->get_duration<std::chrono::seconds>(CN_SWITCHOVER_TIMEOUT).count();
|
||||
m_settings.failover_timeout = params->get_duration<std::chrono::seconds>(CN_FAILOVER_TIMEOUT).count();
|
||||
m_settings.switchover_timeout = params->get_duration<std::chrono::seconds>(CN_SWITCHOVER_TIMEOUT).count();
|
||||
m_settings.auto_failover = params->get_bool(CN_AUTO_FAILOVER);
|
||||
m_settings.auto_rejoin = params->get_bool(CN_AUTO_REJOIN);
|
||||
m_settings.enforce_read_only_slaves = params->get_bool(CN_ENFORCE_READONLY);
|
||||
m_settings.enforce_simple_topology = params->get_bool(CN_ENFORCE_SIMPLE_TOPOLOGY);
|
||||
m_verify_master_failure = params->get_bool(CN_VERIFY_MASTER_FAILURE);
|
||||
m_master_failure_timeout = params->get_duration<std::chrono::seconds>(CN_MASTER_FAILURE_TIMEOUT).count();
|
||||
m_settings.verify_master_failure = params->get_bool(CN_VERIFY_MASTER_FAILURE);
|
||||
m_settings.master_failure_timeout = params->get_duration<std::chrono::seconds>(CN_MASTER_FAILURE_TIMEOUT).count();
|
||||
m_settings.shared.promotion_sql_file = params->get_string(CN_PROMOTION_SQL_FILE);
|
||||
m_settings.shared.demotion_sql_file = params->get_string(CN_DEMOTION_SQL_FILE);
|
||||
m_settings.switchover_on_low_disk_space = params->get_bool(CN_SWITCHOVER_ON_LOW_DISK_SPACE);
|
||||
@ -234,11 +231,12 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params)
|
||||
m_settings.shared.handle_event_scheduler = params->get_bool(CN_HANDLE_EVENTS);
|
||||
m_settings.shared.replication_ssl = params->get_bool(CN_REPLICATION_MASTER_SSL);
|
||||
|
||||
m_settings.excluded_servers.clear();
|
||||
|
||||
/* Reset all monitored state info. The server dependent values must be reset as servers could have been
|
||||
* added, removed and modified. */
|
||||
reset_server_info();
|
||||
|
||||
m_excluded_servers.clear();
|
||||
bool settings_ok = true;
|
||||
bool list_error = false;
|
||||
auto excluded = get_monitored_serverlist(CN_NO_PROMOTE_SERVERS, &list_error);
|
||||
@ -250,7 +248,7 @@ bool MariaDBMonitor::configure(const MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
for (auto elem : excluded)
|
||||
{
|
||||
m_excluded_servers.push_back(get_server(elem));
|
||||
m_settings.excluded_servers.push_back(get_server(elem));
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,16 +322,16 @@ string MariaDBMonitor::diagnostics_to_string() const
|
||||
};
|
||||
rval += string_printf("Automatic failover: %s\n", bool_to_zstr(m_settings.auto_failover));
|
||||
rval += string_printf("Failcount: %i\n", m_settings.failcount);
|
||||
rval += string_printf("Failover timeout: %u\n", m_failover_timeout);
|
||||
rval += string_printf("Switchover timeout: %u\n", m_switchover_timeout);
|
||||
rval += string_printf("Failover timeout: %u\n", m_settings.failover_timeout);
|
||||
rval += string_printf("Switchover timeout: %u\n", m_settings.switchover_timeout);
|
||||
rval += string_printf("Automatic rejoin: %s\n", bool_to_zstr(m_settings.auto_rejoin));
|
||||
rval += string_printf("Enforce read-only: %s\n", bool_to_zstr(m_settings.enforce_read_only_slaves));
|
||||
rval += string_printf("Enforce simple topology: %s\n", bool_to_zstr(m_settings.enforce_simple_topology));
|
||||
rval += string_printf("Detect stale master: %s\n", bool_to_zstr(m_settings.detect_stale_master));
|
||||
if (m_excluded_servers.size() > 0)
|
||||
if (!m_settings.excluded_servers.empty())
|
||||
{
|
||||
rval += string_printf("Non-promotable servers (failover): ");
|
||||
rval += string_printf("%s\n", monitored_servers_to_string(m_excluded_servers).c_str());
|
||||
rval += string_printf("%s\n", monitored_servers_to_string(m_settings.excluded_servers).c_str());
|
||||
}
|
||||
|
||||
rval += string_printf("\nServer information:\n-------------------\n\n");
|
||||
|
@ -197,6 +197,16 @@ private:
|
||||
std::string m_external_master_host; /* External master host, for fail/switchover */
|
||||
int m_external_master_port = PORT_UNKNOWN; /* External master port */
|
||||
|
||||
// Fields controlling logging of various events. TODO: Check these
|
||||
bool m_log_no_master {true}; /* Should it be logged that there is no master? */
|
||||
bool m_warn_current_master_invalid {true}; /* Print warning if current master is not valid? */
|
||||
bool m_warn_cannot_find_master {true}; /* Print warning if a master cannot be found? */
|
||||
bool m_warn_master_down {true}; /* Print warning that failover may happen soon? */
|
||||
bool m_warn_failover_precond {true}; /* Print failover preconditions error message? */
|
||||
bool m_warn_switchover_precond {true}; /* Print switchover preconditions error message? */
|
||||
bool m_warn_cannot_rejoin {true}; /* Print warning if auto_rejoin fails because of invalid
|
||||
* gtid:s? */
|
||||
|
||||
// MariaDB-Monitor specific settings. These are only written to when configuring the monitor.
|
||||
class Settings
|
||||
{
|
||||
@ -229,35 +239,26 @@ private:
|
||||
bool enforce_simple_topology {false}; /* Can the monitor assume and enforce a simple, 1-master
|
||||
* and N slaves topology? Also allows unsafe failover */
|
||||
|
||||
SharedSettings shared; /* Settings required by MariaDBServer objects */
|
||||
// Cluster operations additional settings
|
||||
int failover_timeout {10}; /* Time limit in seconds for failover */
|
||||
int switchover_timeout {10}; /* Time limit in seconds for switchover */
|
||||
bool verify_master_failure {true}; /* Is master failure is verified via slaves? */
|
||||
int master_failure_timeout {10}; /* Master failure verification (via slaves) time in seconds */
|
||||
|
||||
ServerArray excluded_servers; /* Servers which cannot be autoselected when deciding which
|
||||
* slave to promote during failover switchover. */
|
||||
|
||||
SharedSettings shared; /* Settings required by MariaDBServer objects */
|
||||
};
|
||||
|
||||
Settings m_settings;
|
||||
|
||||
// Cluster operations additional settings
|
||||
uint32_t m_failover_timeout = 10; /* Time limit in seconds for failover */
|
||||
uint32_t m_switchover_timeout = 10; /* Time limit in seconds for switchover */
|
||||
bool m_verify_master_failure = true; /* Is master failure is verified via slaves? */
|
||||
int m_master_failure_timeout = 10; /* Master failure verification (via slaves) time in seconds */
|
||||
ServerArray m_excluded_servers; /* Servers which cannot be autoselected when deciding which
|
||||
* slave to promote during failover switchover. */
|
||||
|
||||
// Fields controlling logging of various events. TODO: Check these
|
||||
bool m_log_no_master = true; /* Should it be logged that there is no master? */
|
||||
bool m_warn_current_master_invalid = true; /* Print warning if current master is not valid? */
|
||||
bool m_warn_cannot_find_master = true; /* Print warning if a master cannot be found? */
|
||||
bool m_warn_master_down = true; /* Print warning that failover may happen soon? */
|
||||
bool m_warn_failover_precond = true; /* Print failover preconditions error message? */
|
||||
bool m_warn_switchover_precond = true; /* Print switchover preconditions error message? */
|
||||
bool m_warn_cannot_rejoin = true; /* Print warning if auto_rejoin fails because of invalid
|
||||
* gtid:s? */
|
||||
|
||||
// Base methods
|
||||
MariaDBMonitor(const std::string& name, const std::string& module);
|
||||
bool configure(const MXS_CONFIG_PARAMETER* params) override;
|
||||
bool set_replication_credentials(const MXS_CONFIG_PARAMETER* params);
|
||||
void reset_server_info();
|
||||
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;
|
||||
|
Reference in New Issue
Block a user