MXS-1775 Expose the state of the monitor

This commit is contained in:
Johan Wikman
2018-05-28 10:17:30 +03:00
parent ebcb807438
commit a55019774d
2 changed files with 27 additions and 9 deletions

View File

@ -28,6 +28,20 @@ public:
virtual ~MonitorInstance();
/**
* @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 known that 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 Starts the monitor.
*
@ -143,7 +157,7 @@ protected:
MXS_MONITORED_SERVER* m_master; /**< Master server */
private:
int32_t m_status; /**< The current status of the monitor. */
int32_t m_state; /**< The current state of the monitor. */
THREAD m_thread; /**< The thread handle of the monitoring thread. */
int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */
bool m_checked; /**< Whether server access has been checked. */

View File

@ -2546,7 +2546,7 @@ namespace maxscale
MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
: m_monitor(pMonitor)
, m_master(NULL)
, m_status(MXS_MONITOR_STOPPED)
, m_state(MXS_MONITOR_STOPPED)
, m_thread(0)
, m_shutdown(0)
, m_checked(false)
@ -2559,15 +2559,21 @@ MonitorInstance::~MonitorInstance()
ss_dassert(!m_thread);
}
int32_t MonitorInstance::state() const
{
return atomic_load_int32(&m_state);
}
void MonitorInstance::stop()
{
// This is always called in single-thread context.
ss_dassert(m_thread);
ss_dassert(m_status == MXS_MONITOR_RUNNING);
ss_dassert(m_state == MXS_MONITOR_RUNNING);
atomic_store_int32(&m_status, MXS_MONITOR_STOPPING);
atomic_store_int32(&m_state, MXS_MONITOR_STOPPING);
atomic_store_int32(&m_shutdown, 1);
thread_wait(m_thread);
atomic_store_int32(&m_state, MXS_MONITOR_STOPPED);
m_thread = 0;
m_shutdown = 0;
@ -2616,7 +2622,7 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
ss_dassert(!m_shutdown);
ss_dassert(!m_thread);
ss_dassert(m_status == MXS_MONITOR_STOPPED);
ss_dassert(m_state == MXS_MONITOR_STOPPED);
if (!m_checked)
{
@ -2648,7 +2654,7 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams)
// state has been updated.
m_semaphore.wait();
started = (atomic_load_int32(&m_status) == MXS_MONITOR_RUNNING);
started = (atomic_load_int32(&m_state) == MXS_MONITOR_RUNNING);
if (!started)
{
@ -2793,13 +2799,11 @@ void MonitorInstance::main(void* pArg)
if (mysql_thread_init() == 0)
{
atomic_store_int32(&pThis->m_status, MXS_MONITOR_RUNNING);
atomic_store_int32(&pThis->m_state, MXS_MONITOR_RUNNING);
pThis->m_semaphore.post();
pThis->main();
atomic_store_int32(&pThis->m_status, MXS_MONITOR_STOPPED);
mysql_thread_end();
}
else