MXS-1775 Change MonitorInstance::configure() prototype

Now return boolean, to allow derived class to signal a failure
to configure.
This commit is contained in:
Johan Wikman
2018-05-25 14:06:06 +03:00
parent 0783af88ed
commit 9b7e37e112
12 changed files with 45 additions and 32 deletions

View File

@ -80,9 +80,13 @@ protected:
* *
* When the monitor is started, this function will be called in order * When the monitor is started, this function will be called in order
* to allow the concrete implementation to configure itself from * to allow the concrete implementation to configure itself from
* configuration parameters. The default implementation does nothing. * configuration parameters. The default implementation returns true.
*
* @return True, if the monitor could be configured, false otherwise.
*
* @note If false is returned, then the monitor will not be started.
*/ */
virtual void configure(const MXS_CONFIG_PARAMETER* pParams); virtual bool configure(const MXS_CONFIG_PARAMETER* pParams);
/** /**
* @brief Check whether the monitor has sufficient rights * @brief Check whether the monitor has sufficient rights

View File

@ -2599,26 +2599,27 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
m_events = config_get_enum(pParams, "events", mxs_monitor_event_enum_values); m_events = config_get_enum(pParams, "events", mxs_monitor_event_enum_values);
m_master = NULL; m_master = NULL;
configure(pParams); if (configure(pParams))
if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL)
{ {
MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL)
}
else
{
// Ok, so the thread started. Let's wait until we can be certain the
// state has been updated.
m_semaphore.wait();
started = (atomic_load_int32(&m_status) == MXS_MONITOR_RUNNING);
if (!started)
{ {
// Ok, so the initialization failed and the thread will exit. MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name);
// We need to wait on it so that the thread resources will not leak. }
thread_wait(m_thread); else
m_thread = 0; {
// Ok, so the thread started. Let's wait until we can be certain the
// state has been updated.
m_semaphore.wait();
started = (atomic_load_int32(&m_status) == MXS_MONITOR_RUNNING);
if (!started)
{
// Ok, so the initialization failed and the thread will exit.
// We need to wait on it so that the thread resources will not leak.
thread_wait(m_thread);
m_thread = 0;
}
} }
} }
} }
@ -2626,13 +2627,14 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
return started; return started;
} }
bool MonitorInstance::has_sufficient_permissions() const bool MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams)
{ {
return true; return true;
} }
void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams) bool MonitorInstance::has_sufficient_permissions() const
{ {
return true;
} }
void MonitorInstance::flush_server_status() void MonitorInstance::flush_server_status()

View File

@ -49,8 +49,9 @@ json_t* AuroraMonitor::diagnostics_json() const
return NULL; return NULL;
} }
void AuroraMonitor::configure(const MXS_CONFIG_PARAMETER* params) bool AuroraMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{ {
return true;
} }
bool AuroraMonitor::has_sufficient_permissions() const bool AuroraMonitor::has_sufficient_permissions() const

View File

@ -32,7 +32,7 @@ public:
json_t* diagnostics_json() const; json_t* diagnostics_json() const;
protected: protected:
void configure(const MXS_CONFIG_PARAMETER* params); bool configure(const MXS_CONFIG_PARAMETER* params);
bool has_sufficient_permissions() const; bool has_sufficient_permissions() const;
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);

View File

@ -130,7 +130,7 @@ json_t* GaleraMonitor::diagnostics_json() const
return rval; return rval;
} }
void GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params) bool GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{ {
m_disableMasterFailback = config_get_bool(params, "disable_master_failback"); m_disableMasterFailback = config_get_bool(params, "disable_master_failback");
m_availableWhenDonor = config_get_bool(params, "available_when_donor"); m_availableWhenDonor = config_get_bool(params, "available_when_donor");
@ -142,6 +142,8 @@ void GaleraMonitor::configure(const MXS_CONFIG_PARAMETER* params)
/* Reset all data in the hashtable */ /* Reset all data in the hashtable */
reset_cluster_info(); reset_cluster_info();
return true;
} }
bool GaleraMonitor::has_sufficient_permissions() const bool GaleraMonitor::has_sufficient_permissions() const

View File

@ -64,7 +64,7 @@ public:
json_t* diagnostics_json() const; json_t* diagnostics_json() const;
protected: protected:
void configure(const MXS_CONFIG_PARAMETER* param); bool configure(const MXS_CONFIG_PARAMETER* param);
bool has_sufficient_permissions() const; bool has_sufficient_permissions() const;
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);
void tick(); void tick();

View File

@ -49,8 +49,9 @@ json_t* GRMon::diagnostics_json() const
return NULL; return NULL;
} }
void GRMon::configure(const MXS_CONFIG_PARAMETER* params) bool GRMon::configure(const MXS_CONFIG_PARAMETER* params)
{ {
return true;
} }
bool GRMon::has_sufficient_permissions() const bool GRMon::has_sufficient_permissions() const

View File

@ -32,7 +32,7 @@ public:
json_t* diagnostics_json() const; json_t* diagnostics_json() const;
protected: protected:
void configure(const MXS_CONFIG_PARAMETER* params); bool configure(const MXS_CONFIG_PARAMETER* params);
bool has_sufficient_permissions() const; bool has_sufficient_permissions() const;
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);

View File

@ -64,9 +64,11 @@ json_t* MMMonitor::diagnostics_json() const
return rval; return rval;
} }
void MMMonitor::configure(const MXS_CONFIG_PARAMETER* params) bool MMMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{ {
m_detectStaleMaster = config_get_bool(params, "detect_stale_master"); m_detectStaleMaster = config_get_bool(params, "detect_stale_master");
return true;
} }
bool MMMonitor::has_sufficient_permissions() const bool MMMonitor::has_sufficient_permissions() const

View File

@ -32,7 +32,7 @@ public:
json_t* diagnostics_json() const; json_t* diagnostics_json() const;
protected: protected:
void configure(const MXS_CONFIG_PARAMETER* params); bool configure(const MXS_CONFIG_PARAMETER* params);
bool has_sufficient_permissions() const; bool has_sufficient_permissions() const;
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);
void tick(); void tick();

View File

@ -47,8 +47,9 @@ json_t* NDBCMonitor::diagnostics_json() const
return NULL; return NULL;
} }
void NDBCMonitor::configure(const MXS_CONFIG_PARAMETER* params) bool NDBCMonitor::configure(const MXS_CONFIG_PARAMETER* params)
{ {
return true;
} }
bool NDBCMonitor::has_sufficient_permissions() const bool NDBCMonitor::has_sufficient_permissions() const

View File

@ -32,7 +32,7 @@ public:
json_t* diagnostics_json() const; json_t* diagnostics_json() const;
protected: protected:
void configure(const MXS_CONFIG_PARAMETER* params); bool configure(const MXS_CONFIG_PARAMETER* params);
bool has_sufficient_permissions() const; bool has_sufficient_permissions() const;
void update_server_status(MXS_MONITORED_SERVER* monitored_server); void update_server_status(MXS_MONITORED_SERVER* monitored_server);