MXS-1775 Make MariaDBMon non-dependent on stop() return value
To align it with the behavour or MonitorInstance::stop()
This commit is contained in:
@ -42,6 +42,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
int32_t state() const;
|
int32_t state() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find out whether the monitor is running.
|
||||||
|
*
|
||||||
|
* @return True, if the monitor is running, false otherwise.
|
||||||
|
*
|
||||||
|
* @see state().
|
||||||
|
*/
|
||||||
|
bool is_running() const
|
||||||
|
{
|
||||||
|
return state() == MXS_MONITOR_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Starts the monitor.
|
* @brief Starts the monitor.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -25,9 +25,10 @@ static void print_redirect_errors(MariaDBServer* first_server, const ServerArray
|
|||||||
|
|
||||||
bool MariaDBMonitor::manual_switchover(SERVER* new_master, SERVER* current_master, json_t** error_out)
|
bool MariaDBMonitor::manual_switchover(SERVER* new_master, SERVER* current_master, json_t** error_out)
|
||||||
{
|
{
|
||||||
bool stopped = stop();
|
bool running = is_running();
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
|
stop();
|
||||||
MXS_NOTICE("Stopped the monitor %s for the duration of switchover.", m_monitor_base->name);
|
MXS_NOTICE("Stopped the monitor %s for the duration of switchover.", m_monitor_base->name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -69,7 +70,7 @@ bool MariaDBMonitor::manual_switchover(SERVER* new_master, SERVER* current_maste
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
// TODO: What if this fails?
|
// TODO: What if this fails?
|
||||||
start(m_monitor_base->parameters);
|
start(m_monitor_base->parameters);
|
||||||
@ -79,9 +80,10 @@ bool MariaDBMonitor::manual_switchover(SERVER* new_master, SERVER* current_maste
|
|||||||
|
|
||||||
bool MariaDBMonitor::manual_failover(json_t** output)
|
bool MariaDBMonitor::manual_failover(json_t** output)
|
||||||
{
|
{
|
||||||
bool stopped = stop();
|
bool running = is_running();
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
|
stop();
|
||||||
MXS_NOTICE("Stopped monitor %s for the duration of failover.", m_monitor_base->name);
|
MXS_NOTICE("Stopped monitor %s for the duration of failover.", m_monitor_base->name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -104,7 +106,7 @@ bool MariaDBMonitor::manual_failover(json_t** output)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
// TODO: What if this fails?
|
// TODO: What if this fails?
|
||||||
start(m_monitor_base->parameters);
|
start(m_monitor_base->parameters);
|
||||||
@ -114,9 +116,10 @@ bool MariaDBMonitor::manual_failover(json_t** output)
|
|||||||
|
|
||||||
bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_server, json_t** output)
|
bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_server, json_t** output)
|
||||||
{
|
{
|
||||||
bool stopped = stop();
|
bool running = is_running();
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
|
stop();
|
||||||
MXS_NOTICE("Stopped monitor %s for the duration of rejoin.", m_monitor_base->name);
|
MXS_NOTICE("Stopped monitor %s for the duration of rejoin.", m_monitor_base->name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -178,7 +181,7 @@ bool MariaDBMonitor::manual_rejoin(SERVER* rejoin_server, json_t** output)
|
|||||||
PRINT_MXS_JSON_ERROR(output, BAD_CLUSTER, m_monitor_base->name);
|
PRINT_MXS_JSON_ERROR(output, BAD_CLUSTER, m_monitor_base->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stopped)
|
if (running)
|
||||||
{
|
{
|
||||||
// TODO: What if this fails?
|
// TODO: What if this fails?
|
||||||
start(m_monitor_base->parameters);
|
start(m_monitor_base->parameters);
|
||||||
|
|||||||
@ -55,6 +55,7 @@ MariaDBMonitor::MariaDBMonitor(MXS_MONITOR* monitor_base)
|
|||||||
: m_monitor_base(monitor_base)
|
: m_monitor_base(monitor_base)
|
||||||
, m_id(config_get_global_options()->id)
|
, m_id(config_get_global_options()->id)
|
||||||
, m_shutdown(false)
|
, m_shutdown(false)
|
||||||
|
, m_state(MXS_MONITOR_STOPPED)
|
||||||
, m_master_gtid_domain(GTID_DOMAIN_UNKNOWN)
|
, m_master_gtid_domain(GTID_DOMAIN_UNKNOWN)
|
||||||
, m_external_master_port(PORT_UNKNOWN)
|
, m_external_master_port(PORT_UNKNOWN)
|
||||||
, m_cluster_modified(true)
|
, m_cluster_modified(true)
|
||||||
@ -66,6 +67,11 @@ MariaDBMonitor::~MariaDBMonitor()
|
|||||||
clear_server_info();
|
clear_server_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t MariaDBMonitor::state() const
|
||||||
|
{
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset and initialize server arrays and related data.
|
* Reset and initialize server arrays and related data.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -44,6 +44,32 @@ public:
|
|||||||
|
|
||||||
~MariaDBMonitor();
|
~MariaDBMonitor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Current state of the monitor.
|
||||||
|
*
|
||||||
|
* Note that in principle the state of the monitor may already have
|
||||||
|
* changed when the current state is returned. The state can be fully
|
||||||
|
* trusted only if it is asked in a context when it is know nobody else
|
||||||
|
* can affect it.
|
||||||
|
*
|
||||||
|
* @return @c MXS_MONITOR_RUNNING if the monitor is running,
|
||||||
|
* @c MXS_MONITOR_STOPPING if the monitor is stopping, and
|
||||||
|
* @c MXS_MONITOR_STOPPED of the monitor is stopped.
|
||||||
|
*/
|
||||||
|
int32_t state() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find out whether the monitor is running.
|
||||||
|
*
|
||||||
|
* @return True, if the monitor is running, false otherwise.
|
||||||
|
*
|
||||||
|
* @see state().
|
||||||
|
*/
|
||||||
|
bool is_running() const
|
||||||
|
{
|
||||||
|
return state() == MXS_MONITOR_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print diagnostics.
|
* Print diagnostics.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user