MXS-1775 Introduce maxscale::MonitorInstance

- All monitors (but MariaDBMon for the time being) inherit
  from that.
- All common member variables moved to that class. Still
  manipulated in derived classes.

In subsequent commits common functionality will be moved to
that class.
This commit is contained in:
Johan Wikman 2018-05-16 10:58:17 +03:00
parent 787a0b50ef
commit 3c277f4e5e
12 changed files with 56 additions and 73 deletions

View File

@ -14,10 +14,31 @@
#include <maxscale/cppdefs.hh>
#include <maxscale/monitor.h>
#include <maxscale/thread.h>
namespace maxscale
{
class MonitorInstance : public MXS_MONITOR_INSTANCE
{
public:
MonitorInstance(const MonitorInstance&) = delete;
MonitorInstance& operator = (const MonitorInstance&) = delete;
virtual ~MonitorInstance();
protected:
MonitorInstance(MXS_MONITOR* pMonitor);
int m_status; /**< The current status of the monitor. */
THREAD m_thread; /**< The thread handle of the monitoring thread. */
MXS_MONITOR* m_monitor; /**< The generic monitor structure. */
int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */
char* m_script; /**< Launchable script. */
uint64_t m_events; /**< Enabled monitor events. */
bool m_checked; /**< Whether server access has been checked. */
};
/**
* The purpose of the template MonitorApi is to provide an implementation
* of the monitor C-API. The template is instantiated with a class that

View File

@ -14,7 +14,7 @@
/**
* @file monitor.c - The monitor module management routines
*/
#include <maxscale/monitor.h>
#include <maxscale/monitor.hh>
#include <fcntl.h>
#include <stdio.h>
@ -2502,3 +2502,24 @@ int mon_config_get_servers(const MXS_CONFIG_PARAMETER* params, const char* key,
}
return found;
}
namespace maxscale
{
MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
: m_status(0)
, m_thread(0)
, m_monitor(pMonitor)
, m_shutdown(0)
, m_script(NULL)
, m_events(0)
{
}
MonitorInstance::~MonitorInstance()
{
ss_dassert(!m_thread);
ss_dassert(!m_script);
}
}

View File

@ -26,19 +26,12 @@
AuroraMonitor::AuroraMonitor(MXS_MONITOR* monitor)
: m_shutdown(false)
, m_thread(0)
, m_script(NULL)
, m_events(0)
, m_monitor(monitor)
, m_checked(false)
: maxscale::MonitorInstance(monitor)
{
}
AuroraMonitor::~AuroraMonitor()
{
ss_dassert(!m_thread);
ss_dassert(!m_script);
}
//static

View File

@ -20,7 +20,7 @@
* @file auroramon.hh - The Aurora monitor
*/
class AuroraMonitor : public MXS_MONITOR_INSTANCE
class AuroraMonitor : public maxscale::MonitorInstance
{
public:
AuroraMonitor(const AuroraMonitor&) = delete;
@ -34,13 +34,6 @@ public:
json_t* diagnostics_json() const;
private:
bool m_shutdown; /**< True if the monitor is stopped */
THREAD m_thread; /**< Monitor thread */
char* m_script; /**< Launchable script */
uint64_t m_events; /**< Enabled monitor events */
MXS_MONITOR* m_monitor; /**< Pointer to generic monitor structure */
bool m_checked; /**< Whether server access has been checked */
AuroraMonitor(MXS_MONITOR* monitor);
~AuroraMonitor();

View File

@ -100,22 +100,16 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
GaleraMonitor::GaleraMonitor(MXS_MONITOR *mon)
: m_thread(0)
, m_shutdown(0)
, m_status(0)
: maxscale::MonitorInstance(mon)
, m_id(MXS_MONITOR_DEFAULT_ID)
, m_disableMasterFailback(0)
, m_availableWhenDonor(0)
, m_disableMasterRoleSetting(0)
, m_master(NULL)
, m_script(NULL)
, m_root_node_as_master(false)
, m_use_priority(false)
, m_events(0)
, m_set_donor_nodes(false)
, m_galera_nodes_info(NULL)
, m_monitor(mon)
, m_checked(false)
{
HASHTABLE *nodes_info = hashtable_alloc(MAX_NUM_SLAVES,
hashtable_item_strhash,

View File

@ -52,7 +52,7 @@ typedef struct galera_cluster_info
} GALERA_CLUSTER_INFO;
class GaleraMonitor : public MXS_MONITOR_INSTANCE
class GaleraMonitor : public maxscale::MonitorInstance
{
public:
GaleraMonitor(const GaleraMonitor&) = delete;
@ -66,25 +66,18 @@ public:
json_t* diagnostics_json() const;
private:
THREAD m_thread; /**< Monitor thread */
int m_shutdown; /**< Flag to shutdown the monitor thread */
int m_status; /**< Monitor status */
unsigned long m_id; /**< Monitor ID */
int m_disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int m_availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
bool m_disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
MXS_MONITORED_SERVER *m_master; /**< Master server for MySQL Master/Slave replication */
char* m_script; /**< Launchable script */
bool m_root_node_as_master; /**< Whether we require that the Master should
* have a wsrep_local_index of 0 */
bool m_use_priority; /**< Use server priorities */
uint64_t m_events; /**< Enabled monitor events */
bool m_set_donor_nodes; /**< set the wrep_sst_donor variable with an
* ordered list of nodes */
HASHTABLE *m_galera_nodes_info; /**< Contains Galera Cluster variables of all nodes */
GALERA_CLUSTER_INFO m_cluster_info; /**< Contains Galera cluster info */
MXS_MONITOR* m_monitor; /**< Pointer to generic monitor structure */
bool m_checked; /**< Whether server access has been checked */
GaleraMonitor(MXS_MONITOR* monitor);
~GaleraMonitor();

View File

@ -26,12 +26,10 @@
#include <mysqld_error.h>
GRMon::GRMon(MXS_MONITOR* monitor):
m_shutdown(0),
m_master(NULL),
m_script(NULL),
m_events(0),
m_monitor(monitor)
GRMon::GRMon(MXS_MONITOR* monitor)
: MonitorInstance(monitor)
, m_master(NULL)
, m_script(NULL)
{
}

View File

@ -20,7 +20,7 @@
* @file grmon.hh A MySQL Group Replication cluster monitor
*/
class GRMon : public MXS_MONITOR_INSTANCE
class GRMon : public maxscale::MonitorInstance
{
public:
GRMon(const GRMon&) = delete;
@ -34,12 +34,8 @@ public:
json_t* diagnostics_json() const;
private:
THREAD m_thread; /**< Monitor thread */
int m_shutdown; /**< Flag to shutdown the monitor thread */
MXS_MONITORED_SERVER* m_master; /**< The master server */
std::string m_script;
uint64_t m_events; /**< Enabled events */
MXS_MONITOR* m_monitor;
GRMon(MXS_MONITOR* monitor);
~GRMon();

View File

@ -85,16 +85,10 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
/*lint +e14 */
MMMonitor::MMMonitor(MXS_MONITOR *monitor)
: m_thread(0)
, m_shutdown(0)
, m_status(0)
: maxscale::MonitorInstance(monitor)
, m_id(MXS_MONITOR_DEFAULT_ID)
, m_detectStaleMaster(false)
, m_master(NULL)
, m_script(NULL)
, m_events(0)
, m_monitor(monitor)
, m_checked(false)
{
}

View File

@ -20,7 +20,7 @@
* @file mmmon.hh - The Multi-Master monitor
*/
class MMMonitor : public MXS_MONITOR_INSTANCE
class MMMonitor : public maxscale::MonitorInstance
{
public:
MMMonitor(const MMMonitor&) = delete;
@ -34,16 +34,9 @@ public:
json_t* diagnostics_json() const;
private:
THREAD m_thread; /**< Monitor thread */
int m_shutdown; /**< Flag to shutdown the monitor thread */
int m_status; /**< Monitor status */
unsigned long m_id; /**< Monitor ID */
int m_detectStaleMaster; /**< Monitor flag for Stale Master detection */
MXS_MONITORED_SERVER *m_master; /**< Master server for Master/Slave replication */
char* m_script; /**< Script to call when state changes occur on servers */
uint64_t m_events; /**< enabled events */
MXS_MONITOR* m_monitor; /**< Pointer to generic monitor structure */
bool m_checked; /**< Whether server access has been checked */
MMMonitor(MXS_MONITOR* monitor);
~MMMonitor();

View File

@ -71,15 +71,9 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
NDBCMonitor::NDBCMonitor(MXS_MONITOR *monitor)
: m_thread(0)
: maxscale::MonitorInstance(monitor)
, m_id(MXS_MONITOR_DEFAULT_ID)
, m_events(0)
, m_shutdown(0)
, m_status(0)
, m_master(NULL)
, m_script(NULL)
, m_monitor(NULL)
, m_checked(false)
{
}

View File

@ -20,7 +20,7 @@
* @file ndbcclustermon.hh A NDBC cluster monitor
*/
class NDBCMonitor : public MXS_MONITOR_INSTANCE
class NDBCMonitor : public maxscale::MonitorInstance
{
public:
NDBCMonitor(const NDBCMonitor&) = delete;
@ -34,15 +34,8 @@ public:
json_t* diagnostics_json() const;
private:
THREAD m_thread; /**< Monitor thread */
unsigned long m_id; /**< Monitor ID */
uint64_t m_events; /**< enabled events */
int m_shutdown; /**< Flag to shutdown the monitor thread */
int m_status; /**< Monitor status */
MXS_MONITORED_SERVER *m_master; /**< Master server for MySQL Master/Slave replication */
char* m_script; /**< Script to call when state changes occur on servers */
MXS_MONITOR* m_monitor; /**< Pointer to generic monitor structure */
bool m_checked; /**< Whether server access has been checked */
NDBCMonitor(MXS_MONITOR* monitor);
~NDBCMonitor();