MXS-1775 Add MonitorInstanceSimple class
MonitorInstanceSimple is intended for simple monitors that probe servers in a straightforward fashion. More complex monitors can be derived directly from MonitorInstance.
This commit is contained in:
@ -168,14 +168,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual bool has_sufficient_permissions() const;
|
virtual bool has_sufficient_permissions() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Update server information
|
|
||||||
*
|
|
||||||
* The implementation should probe the server in question and update
|
|
||||||
* the server status bits.
|
|
||||||
*/
|
|
||||||
virtual void update_server_status(MXS_MONITORED_SERVER* pMonitored_server) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Flush pending server status to each server.
|
* @brief Flush pending server status to each server.
|
||||||
*
|
*
|
||||||
@ -189,23 +181,9 @@ protected:
|
|||||||
* @brief Monitor the servers
|
* @brief Monitor the servers
|
||||||
*
|
*
|
||||||
* This function is called once per monitor round, and the concrete
|
* This function is called once per monitor round, and the concrete
|
||||||
* implementation should probe all servers, i.e. call @c update_server_status
|
* implementation should probe all servers and set server status bits.
|
||||||
* on each server.
|
|
||||||
*
|
|
||||||
* The default implementation will for each server:
|
|
||||||
* - Do nothing, if the server is in maintenance.
|
|
||||||
* - Before calling, store the previous status of the server.
|
|
||||||
* - Before calling, set the pending status of the monitored server object
|
|
||||||
* to the status of the corresponding server object.
|
|
||||||
* - Ensure that there is a connection to the server.
|
|
||||||
* If there is, @c update_server_status is called.
|
|
||||||
* If there is not, the pending status will be updated accordingly and
|
|
||||||
* @c update_server_status will *not* be called.
|
|
||||||
* - After the call, update the error count of the server if it is down.
|
|
||||||
*
|
|
||||||
* Finally, it will call @c flush_server_status.
|
|
||||||
*/
|
*/
|
||||||
virtual void tick();
|
virtual void tick() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called before the monitor loop is started
|
* @brief Called before the monitor loop is started
|
||||||
@ -244,6 +222,59 @@ private:
|
|||||||
static void main(void* pArg);
|
static void main(void* pArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MonitorInstanceSimple : public MonitorInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MonitorInstanceSimple(const MonitorInstanceSimple&) = delete;
|
||||||
|
MonitorInstanceSimple& operator = (const MonitorInstanceSimple&) = delete;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MonitorInstanceSimple(MXS_MONITOR* pMonitor)
|
||||||
|
: MonitorInstance(pMonitor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Update server information
|
||||||
|
*
|
||||||
|
* The implementation should probe the server in question and update
|
||||||
|
* the server status bits.
|
||||||
|
*/
|
||||||
|
virtual void update_server_status(MXS_MONITORED_SERVER* pMonitored_server) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called right at the beginning of @c tick().
|
||||||
|
*
|
||||||
|
* The default implementation does nothing.
|
||||||
|
*/
|
||||||
|
virtual void pre_tick();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Called right before the end of @c tick().
|
||||||
|
*
|
||||||
|
* The default implementation does nothing.
|
||||||
|
*/
|
||||||
|
virtual void post_tick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Monitor the servers
|
||||||
|
*
|
||||||
|
* This function is called once per monitor round and will for each server:
|
||||||
|
*
|
||||||
|
* - Do nothing, if the server is in maintenance.
|
||||||
|
* - Store the previous status of the server.
|
||||||
|
* - Set the pending status of the monitored server object
|
||||||
|
* to the status of the corresponding server object.
|
||||||
|
* - Ensure that there is a connection to the server.
|
||||||
|
* If there is, @c update_server_status() is called.
|
||||||
|
* If there is not, the pending status will be updated accordingly and
|
||||||
|
* @c update_server_status() will *not* be called.
|
||||||
|
* - After the call, update the error count of the server if it is down.
|
||||||
|
*/
|
||||||
|
void tick(); // final
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The purpose of the template MonitorApi is to provide an implementation
|
* The purpose of the template MonitorApi is to provide an implementation
|
||||||
* of the monitor C-API. The template is instantiated with a class that
|
* of the monitor C-API. The template is instantiated with a class that
|
||||||
|
|||||||
@ -2827,8 +2827,18 @@ void MonitorInstance::flush_server_status()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonitorInstance::tick()
|
void MonitorInstanceSimple::pre_tick()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MonitorInstanceSimple::post_tick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MonitorInstanceSimple::tick()
|
||||||
|
{
|
||||||
|
pre_tick();
|
||||||
|
|
||||||
for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next)
|
for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next)
|
||||||
{
|
{
|
||||||
if (!SERVER_IN_MAINT(pMs->server))
|
if (!SERVER_IN_MAINT(pMs->server))
|
||||||
@ -2892,6 +2902,8 @@ void MonitorInstance::tick()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonitorInstance::pre_loop()
|
void MonitorInstance::pre_loop()
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
|
|
||||||
AuroraMonitor::AuroraMonitor(MXS_MONITOR* monitor)
|
AuroraMonitor::AuroraMonitor(MXS_MONITOR* monitor)
|
||||||
: maxscale::MonitorInstance(monitor)
|
: maxscale::MonitorInstanceSimple(monitor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* @file auroramon.hh - The Aurora monitor
|
* @file auroramon.hh - The Aurora monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AuroraMonitor : public maxscale::MonitorInstance
|
class AuroraMonitor : public maxscale::MonitorInstanceSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AuroraMonitor(const AuroraMonitor&) = delete;
|
AuroraMonitor(const AuroraMonitor&) = delete;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ static void nodeval_free(GALERA_NODE_INFO *);
|
|||||||
static bool using_xtrabackup(MXS_MONITORED_SERVER *database, const char* server_string);
|
static bool using_xtrabackup(MXS_MONITORED_SERVER *database, const char* server_string);
|
||||||
|
|
||||||
GaleraMonitor::GaleraMonitor(MXS_MONITOR *mon)
|
GaleraMonitor::GaleraMonitor(MXS_MONITOR *mon)
|
||||||
: maxscale::MonitorInstance(mon)
|
: maxscale::MonitorInstanceSimple(mon)
|
||||||
, m_id(MXS_MONITOR_DEFAULT_ID)
|
, m_id(MXS_MONITOR_DEFAULT_ID)
|
||||||
, m_disableMasterFailback(0)
|
, m_disableMasterFailback(0)
|
||||||
, m_availableWhenDonor(0)
|
, m_availableWhenDonor(0)
|
||||||
@ -293,10 +293,8 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GaleraMonitor::tick()
|
void GaleraMonitor::post_tick()
|
||||||
{
|
{
|
||||||
MonitorInstance::tick();
|
|
||||||
|
|
||||||
int is_cluster = 0;
|
int is_cluster = 0;
|
||||||
|
|
||||||
/* Try to set a Galera cluster based on
|
/* Try to set a Galera cluster based on
|
||||||
|
|||||||
@ -52,7 +52,7 @@ typedef struct galera_cluster_info
|
|||||||
} GALERA_CLUSTER_INFO;
|
} GALERA_CLUSTER_INFO;
|
||||||
|
|
||||||
|
|
||||||
class GaleraMonitor : public maxscale::MonitorInstance
|
class GaleraMonitor : public maxscale::MonitorInstanceSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GaleraMonitor(const GaleraMonitor&) = delete;
|
GaleraMonitor(const GaleraMonitor&) = delete;
|
||||||
@ -67,7 +67,7 @@ protected:
|
|||||||
bool 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 post_tick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long m_id; /**< Monitor ID */
|
unsigned long m_id; /**< Monitor ID */
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
|
|
||||||
GRMon::GRMon(MXS_MONITOR* monitor)
|
GRMon::GRMon(MXS_MONITOR* monitor)
|
||||||
: MonitorInstance(monitor)
|
: MonitorInstanceSimple(monitor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* @file grmon.hh A MySQL Group Replication cluster monitor
|
* @file grmon.hh A MySQL Group Replication cluster monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GRMon : public maxscale::MonitorInstance
|
class GRMon : public maxscale::MonitorInstanceSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GRMon(const GRMon&) = delete;
|
GRMon(const GRMon&) = delete;
|
||||||
|
|||||||
@ -332,13 +332,6 @@ void MariaDBMonitor::update_server(MariaDBServer& server)
|
|||||||
mon_srv->mon_err_count = (is_running || in_maintenance) ? 0 : mon_srv->mon_err_count + 1;
|
mon_srv->mon_err_count = (is_running || in_maintenance) ? 0 : mon_srv->mon_err_count + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MariaDBMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|
||||||
{
|
|
||||||
// Not used and should not be called. Is there a way to check this "statically" (without
|
|
||||||
// template magic)?
|
|
||||||
ss_dassert(!true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MariaDBMonitor::pre_loop()
|
void MariaDBMonitor::pre_loop()
|
||||||
{
|
{
|
||||||
// MonitorInstance loaded from the journal the current master into its
|
// MonitorInstance loaded from the journal the current master into its
|
||||||
|
|||||||
@ -163,7 +163,6 @@ private:
|
|||||||
MariaDBServer* get_server_info(MXS_MONITORED_SERVER* db);
|
MariaDBServer* get_server_info(MXS_MONITORED_SERVER* db);
|
||||||
MariaDBServer* get_server(int64_t id);
|
MariaDBServer* get_server(int64_t id);
|
||||||
void update_server(MariaDBServer& server);
|
void update_server(MariaDBServer& server);
|
||||||
void update_server_status(MXS_MONITORED_SERVER* pMonitored_server); // Not used
|
|
||||||
|
|
||||||
// Cluster discovery and status assignment methods
|
// Cluster discovery and status assignment methods
|
||||||
MariaDBServer* find_root_master();
|
MariaDBServer* find_root_master();
|
||||||
|
|||||||
@ -36,7 +36,7 @@ static void detectStaleMaster(void *, int);
|
|||||||
static bool isMySQLEvent(mxs_monitor_event_t event);
|
static bool isMySQLEvent(mxs_monitor_event_t event);
|
||||||
|
|
||||||
MMMonitor::MMMonitor(MXS_MONITOR *monitor)
|
MMMonitor::MMMonitor(MXS_MONITOR *monitor)
|
||||||
: maxscale::MonitorInstance(monitor)
|
: maxscale::MonitorInstanceSimple(monitor)
|
||||||
, m_id(MXS_MONITOR_DEFAULT_ID)
|
, m_id(MXS_MONITOR_DEFAULT_ID)
|
||||||
, m_detectStaleMaster(false)
|
, m_detectStaleMaster(false)
|
||||||
{
|
{
|
||||||
@ -318,10 +318,8 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMMonitor::tick()
|
void MMMonitor::post_tick()
|
||||||
{
|
{
|
||||||
MonitorInstance::tick();
|
|
||||||
|
|
||||||
/* Get Master server pointer */
|
/* Get Master server pointer */
|
||||||
MXS_MONITORED_SERVER *root_master = get_current_master();
|
MXS_MONITORED_SERVER *root_master = get_current_master();
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* @file mmmon.hh - The Multi-Master monitor
|
* @file mmmon.hh - The Multi-Master monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class MMMonitor : public maxscale::MonitorInstance
|
class MMMonitor : public maxscale::MonitorInstanceSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MMMonitor(const MMMonitor&) = delete;
|
MMMonitor(const MMMonitor&) = delete;
|
||||||
@ -35,7 +35,7 @@ protected:
|
|||||||
bool 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 post_tick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long m_id; /**< Monitor ID */
|
unsigned long m_id; /**< Monitor ID */
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
NDBCMonitor::NDBCMonitor(MXS_MONITOR *monitor)
|
NDBCMonitor::NDBCMonitor(MXS_MONITOR *monitor)
|
||||||
: maxscale::MonitorInstance(monitor)
|
: maxscale::MonitorInstanceSimple(monitor)
|
||||||
, m_id(MXS_MONITOR_DEFAULT_ID)
|
, m_id(MXS_MONITOR_DEFAULT_ID)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* @file ndbcclustermon.hh A NDBC cluster monitor
|
* @file ndbcclustermon.hh A NDBC cluster monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class NDBCMonitor : public maxscale::MonitorInstance
|
class NDBCMonitor : public maxscale::MonitorInstanceSimple
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NDBCMonitor(const NDBCMonitor&) = delete;
|
NDBCMonitor(const NDBCMonitor&) = delete;
|
||||||
|
|||||||
Reference in New Issue
Block a user