MXS-1775 Provide default implementation for MonitorInstance::tick
This commit is contained in:
@ -70,8 +70,13 @@ protected:
|
|||||||
* 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, i.e. call @c update_server_status
|
||||||
* on each server.
|
* on each server.
|
||||||
|
*
|
||||||
|
* The default implementation will:
|
||||||
|
* - Not call @update_server_status for a server that is in maintenance.
|
||||||
|
* - Before calling, update the previous status of the server.
|
||||||
|
* - After the call, update the error count of the server.
|
||||||
*/
|
*/
|
||||||
virtual void tick() = 0;
|
virtual void tick();
|
||||||
|
|
||||||
MXS_MONITOR* m_monitor; /**< The generic monitor structure. */
|
MXS_MONITOR* m_monitor; /**< The generic monitor structure. */
|
||||||
MXS_MONITORED_SERVER* m_master; /**< Master server */
|
MXS_MONITORED_SERVER* m_master; /**< Master server */
|
||||||
|
@ -2635,6 +2635,37 @@ void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MonitorInstance::tick()
|
||||||
|
{
|
||||||
|
for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next)
|
||||||
|
{
|
||||||
|
if (!SERVER_IN_MAINT(pMs->server))
|
||||||
|
{
|
||||||
|
pMs->mon_prev_status = pMs->server->status;
|
||||||
|
pMs->pending_status = pMs->server->status;
|
||||||
|
|
||||||
|
update_server_status(pMs);
|
||||||
|
|
||||||
|
if (mon_status_changed(pMs) || mon_print_fail_status(pMs))
|
||||||
|
{
|
||||||
|
MXS_DEBUG("Backend server [%s]:%d state : %s",
|
||||||
|
pMs->server->address,
|
||||||
|
pMs->server->port,
|
||||||
|
STRSRVSTATUS(pMs->server));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SERVER_IS_DOWN(pMs->server))
|
||||||
|
{
|
||||||
|
pMs->mon_err_count += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pMs->mon_err_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MonitorInstance::main()
|
void MonitorInstance::main()
|
||||||
{
|
{
|
||||||
load_server_journal(m_monitor, &m_master);
|
load_server_journal(m_monitor, &m_master);
|
||||||
|
@ -56,70 +56,58 @@ void AuroraMonitor::destroy()
|
|||||||
*/
|
*/
|
||||||
void AuroraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
void AuroraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
||||||
{
|
{
|
||||||
if (!SERVER_IN_MAINT(monitored_server->server))
|
SERVER temp_server = {};
|
||||||
|
temp_server.status = monitored_server->server->status;
|
||||||
|
server_clear_status_nolock(&temp_server,
|
||||||
|
SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE | SERVER_AUTH_ERROR);
|
||||||
|
|
||||||
|
/** Try to connect to or ping the database */
|
||||||
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
||||||
|
|
||||||
|
if (mon_connection_is_ok(rval))
|
||||||
{
|
{
|
||||||
SERVER temp_server = {};
|
server_set_status_nolock(&temp_server, SERVER_RUNNING);
|
||||||
temp_server.status = monitored_server->server->status;
|
MYSQL_RES *result;
|
||||||
server_clear_status_nolock(&temp_server,
|
|
||||||
SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE | SERVER_AUTH_ERROR);
|
|
||||||
monitored_server->mon_prev_status = monitored_server->server->status;
|
|
||||||
|
|
||||||
/** Try to connect to or ping the database */
|
/** Connection is OK, query for replica status */
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
if (mxs_mysql_query(monitored_server->con, "SELECT @@aurora_server_id, server_id FROM "
|
||||||
|
"information_schema.replica_host_status "
|
||||||
if (mon_connection_is_ok(rval))
|
"WHERE session_id = 'MASTER_SESSION_ID'") == 0 &&
|
||||||
|
(result = mysql_store_result(monitored_server->con)))
|
||||||
{
|
{
|
||||||
server_set_status_nolock(&temp_server, SERVER_RUNNING);
|
ss_dassert(mysql_field_count(monitored_server->con) == 2);
|
||||||
MYSQL_RES *result;
|
MYSQL_ROW row = mysql_fetch_row(result);
|
||||||
|
int status = SERVER_SLAVE;
|
||||||
|
|
||||||
/** Connection is OK, query for replica status */
|
/** The master will return a row with two identical non-NULL fields */
|
||||||
if (mxs_mysql_query(monitored_server->con, "SELECT @@aurora_server_id, server_id FROM "
|
if (row[0] && row[1] && strcmp(row[0], row[1]) == 0)
|
||||||
"information_schema.replica_host_status "
|
|
||||||
"WHERE session_id = 'MASTER_SESSION_ID'") == 0 &&
|
|
||||||
(result = mysql_store_result(monitored_server->con)))
|
|
||||||
{
|
{
|
||||||
ss_dassert(mysql_field_count(monitored_server->con) == 2);
|
status = SERVER_MASTER;
|
||||||
MYSQL_ROW row = mysql_fetch_row(result);
|
|
||||||
int status = SERVER_SLAVE;
|
|
||||||
|
|
||||||
/** The master will return a row with two identical non-NULL fields */
|
|
||||||
if (row[0] && row[1] && strcmp(row[0], row[1]) == 0)
|
|
||||||
{
|
|
||||||
status = SERVER_MASTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
server_set_status_nolock(&temp_server, status);
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mon_report_query_error(monitored_server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server_set_status_nolock(&temp_server, status);
|
||||||
|
mysql_free_result(result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/** Failed to connect to the database */
|
mon_report_query_error(monitored_server);
|
||||||
if (mysql_errno(monitored_server->con) == ER_ACCESS_DENIED_ERROR)
|
}
|
||||||
{
|
}
|
||||||
server_set_status_nolock(&temp_server, SERVER_AUTH_ERROR);
|
else
|
||||||
}
|
{
|
||||||
|
/** Failed to connect to the database */
|
||||||
if (mon_status_changed(monitored_server) && mon_print_fail_status(monitored_server))
|
if (mysql_errno(monitored_server->con) == ER_ACCESS_DENIED_ERROR)
|
||||||
{
|
{
|
||||||
mon_log_connect_error(monitored_server, rval);
|
server_set_status_nolock(&temp_server, SERVER_AUTH_ERROR);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server_transfer_status(monitored_server->server, &temp_server);
|
if (mon_status_changed(monitored_server) && mon_print_fail_status(monitored_server))
|
||||||
|
{
|
||||||
|
mon_log_connect_error(monitored_server, rval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void AuroraMonitor::tick()
|
server_transfer_status(monitored_server->server, &temp_server);
|
||||||
{
|
|
||||||
for (MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers; ptr; ptr = ptr->next)
|
|
||||||
{
|
|
||||||
update_server_status(ptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AuroraMonitor::has_sufficient_permissions() const
|
bool AuroraMonitor::has_sufficient_permissions() const
|
||||||
|
@ -39,5 +39,4 @@ private:
|
|||||||
|
|
||||||
bool has_sufficient_permissions() const;
|
bool has_sufficient_permissions() const;
|
||||||
void configure(const MXS_CONFIG_PARAMETER* params);
|
void configure(const MXS_CONFIG_PARAMETER* params);
|
||||||
void tick();
|
|
||||||
};
|
};
|
||||||
|
@ -266,15 +266,6 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
char *server_string;
|
char *server_string;
|
||||||
|
|
||||||
/* Don't even probe server flagged as in maintenance */
|
|
||||||
if (SERVER_IN_MAINT(monitored_server->server))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store previous status */
|
|
||||||
monitored_server->mon_prev_status = monitored_server->server->status;
|
|
||||||
|
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
||||||
if (!mon_connection_is_ok(rval))
|
if (!mon_connection_is_ok(rval))
|
||||||
{
|
{
|
||||||
@ -445,39 +436,10 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
|
|
||||||
void GaleraMonitor::tick()
|
void GaleraMonitor::tick()
|
||||||
{
|
{
|
||||||
|
MonitorInstance::tick();
|
||||||
|
|
||||||
int is_cluster = 0;
|
int is_cluster = 0;
|
||||||
|
|
||||||
MXS_MONITORED_SERVER* ptr = m_monitor->monitored_servers;
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
ptr->mon_prev_status = ptr->server->status;
|
|
||||||
|
|
||||||
update_server_status(ptr);
|
|
||||||
|
|
||||||
/* Log server status change */
|
|
||||||
if (mon_status_changed(ptr))
|
|
||||||
{
|
|
||||||
MXS_DEBUG("Backend server [%s]:%d state : %s",
|
|
||||||
ptr->server->address,
|
|
||||||
ptr->server->port,
|
|
||||||
STRSRVSTATUS(ptr->server));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SERVER_IS_DOWN(ptr->server))
|
|
||||||
{
|
|
||||||
/** Increase this server'e error count */
|
|
||||||
ptr->mon_err_count += 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/** Reset this server's error count */
|
|
||||||
ptr->mon_err_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to set a Galera cluster based on
|
/* Try to set a Galera cluster based on
|
||||||
* UUID and cluster_size each node reports:
|
* UUID and cluster_size each node reports:
|
||||||
* no multiple clusters UUID are allowed.
|
* no multiple clusters UUID are allowed.
|
||||||
@ -496,7 +458,7 @@ void GaleraMonitor::tick()
|
|||||||
|
|
||||||
m_master = set_cluster_master(m_master, candidate_master, m_disableMasterFailback);
|
m_master = set_cluster_master(m_master, candidate_master, m_disableMasterFailback);
|
||||||
|
|
||||||
ptr = m_monitor->monitored_servers;
|
MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers;
|
||||||
|
|
||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
|
@ -127,15 +127,6 @@ static bool is_slave(MXS_MONITORED_SERVER* server)
|
|||||||
|
|
||||||
void GRMon::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
void GRMon::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
||||||
{
|
{
|
||||||
/* Don't even probe server flagged as in maintenance */
|
|
||||||
if (SERVER_IN_MAINT(monitored_server->server))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store previous status */
|
|
||||||
monitored_server->mon_prev_status = monitored_server->server->status;
|
|
||||||
|
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
||||||
|
|
||||||
if (!mon_connection_is_ok(rval))
|
if (!mon_connection_is_ok(rval))
|
||||||
@ -181,14 +172,6 @@ void GRMon::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRMon::tick()
|
|
||||||
{
|
|
||||||
for (MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers; ptr; ptr = ptr->next)
|
|
||||||
{
|
|
||||||
update_server_status(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The module entry point routine. It is this routine that
|
* The module entry point routine. It is this routine that
|
||||||
* must populate the structure that is referred to as the
|
* must populate the structure that is referred to as the
|
||||||
|
@ -39,5 +39,4 @@ private:
|
|||||||
|
|
||||||
bool has_sufficient_permissions() const;
|
bool has_sufficient_permissions() const;
|
||||||
void configure(const MXS_CONFIG_PARAMETER* params);
|
void configure(const MXS_CONFIG_PARAMETER* params);
|
||||||
void tick();
|
|
||||||
};
|
};
|
||||||
|
@ -153,14 +153,6 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
unsigned long int server_version = 0;
|
unsigned long int server_version = 0;
|
||||||
char *server_string;
|
char *server_string;
|
||||||
|
|
||||||
/* Don't probe servers in maintenance mode */
|
|
||||||
if (SERVER_IN_MAINT(monitored_server->server))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Store previous status */
|
|
||||||
monitored_server->mon_prev_status = monitored_server->server->status;
|
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
||||||
|
|
||||||
if (!mon_connection_is_ok(rval))
|
if (!mon_connection_is_ok(rval))
|
||||||
@ -433,45 +425,14 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
|
|
||||||
void MMMonitor::tick()
|
void MMMonitor::tick()
|
||||||
{
|
{
|
||||||
/* start from the first server in the list */
|
MonitorInstance::tick();
|
||||||
MXS_MONITORED_SERVER* ptr = m_monitor->monitored_servers;
|
|
||||||
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
/* copy server status into monitor pending_status */
|
|
||||||
ptr->pending_status = ptr->server->status;
|
|
||||||
|
|
||||||
/* monitor current node */
|
|
||||||
update_server_status(ptr);
|
|
||||||
|
|
||||||
if (mon_status_changed(ptr) ||
|
|
||||||
mon_print_fail_status(ptr))
|
|
||||||
{
|
|
||||||
MXS_DEBUG("Backend server [%s]:%d state : %s",
|
|
||||||
ptr->server->address,
|
|
||||||
ptr->server->port,
|
|
||||||
STRSRVSTATUS(ptr->server));
|
|
||||||
}
|
|
||||||
if (SERVER_IS_DOWN(ptr->server))
|
|
||||||
{
|
|
||||||
/** Increase this server'e error count */
|
|
||||||
ptr->mon_err_count += 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/** Reset this server's error count */
|
|
||||||
ptr->mon_err_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get Master server pointer */
|
/* Get Master server pointer */
|
||||||
MXS_MONITORED_SERVER *root_master = get_current_master();
|
MXS_MONITORED_SERVER *root_master = get_current_master();
|
||||||
|
|
||||||
/* Update server status from monitor pending status on that server*/
|
/* Update server status from monitor pending status on that server*/
|
||||||
|
|
||||||
ptr = m_monitor->monitored_servers;
|
MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers;
|
||||||
while (ptr)
|
while (ptr)
|
||||||
{
|
{
|
||||||
if (!SERVER_IN_MAINT(ptr->server))
|
if (!SERVER_IN_MAINT(ptr->server))
|
||||||
|
@ -134,12 +134,6 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
int isjoined = 0;
|
int isjoined = 0;
|
||||||
char *server_string;
|
char *server_string;
|
||||||
|
|
||||||
/* Don't even probe server flagged as in maintenance */
|
|
||||||
if (SERVER_IN_MAINT(monitored_server->server))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, monitored_server);
|
||||||
if (!mon_connection_is_ok(rval))
|
if (!mon_connection_is_ok(rval))
|
||||||
{
|
{
|
||||||
@ -236,24 +230,3 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
monitored_server->server->depth = -1;
|
monitored_server->server->depth = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NDBCMonitor::tick()
|
|
||||||
{
|
|
||||||
MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers;
|
|
||||||
while (ptr)
|
|
||||||
{
|
|
||||||
ptr->mon_prev_status = ptr->server->status;
|
|
||||||
update_server_status(ptr);
|
|
||||||
|
|
||||||
if (ptr->server->status != ptr->mon_prev_status ||
|
|
||||||
SERVER_IS_DOWN(ptr->server))
|
|
||||||
{
|
|
||||||
MXS_DEBUG("Backend server [%s]:%d state : %s",
|
|
||||||
ptr->server->address,
|
|
||||||
ptr->server->port,
|
|
||||||
STRSRVSTATUS(ptr->server));
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = ptr->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -41,5 +41,4 @@ private:
|
|||||||
|
|
||||||
bool has_sufficient_permissions() const;
|
bool has_sufficient_permissions() const;
|
||||||
void configure(const MXS_CONFIG_PARAMETER* params);
|
void configure(const MXS_CONFIG_PARAMETER* params);
|
||||||
void tick();
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user