MXS-1775 Flush pending status to servers using common code

This commit is contained in:
Johan Wikman
2018-05-25 09:09:21 +03:00
parent 15b1c270a3
commit 0833db8a48
7 changed files with 40 additions and 27 deletions

View File

@ -64,6 +64,15 @@ protected:
*/
virtual void configure(const MXS_CONFIG_PARAMETER* pParams);
/**
* @brief Flush pending server status to each server.
*
* This function is expected to flush the pending status to each server.
* The default implementation simply copies monitored_server->pending_status
* to server->status.
*/
virtual void flush_server_status();
/**
* @brief Monitor the servers
*
@ -71,15 +80,18 @@ protected:
* implementation should probe all servers, i.e. call @c update_server_status
* on each server.
*
* The default implementation will:
* - Not call @c update_server_status for a server that is in maintenance.
* - Before calling, update the previous status of the server.
* - Before calling, update the pending status of the monitored server object
* to the status of the corresponing server object.
* - Ensure that there is a connection to the server. If that fails, then
* 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.
* 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();

View File

@ -2635,6 +2635,17 @@ void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams)
{
}
void MonitorInstance::flush_server_status()
{
for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next)
{
if (!SERVER_IN_MAINT(pMs->server))
{
pMs->server->status = pMs->pending_status;
}
}
}
void MonitorInstance::tick()
{
for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next)
@ -2672,13 +2683,18 @@ void MonitorInstance::tick()
}
}
#if defined(SS_DEBUG)
if (mon_status_changed(pMs) || mon_print_fail_status(pMs))
{
// The current status is still in pMs->pending_status.
SERVER server = {};
server.status = pMs->pending_status;
MXS_DEBUG("Backend server [%s]:%d state : %s",
pMs->server->address,
pMs->server->port,
STRSRVSTATUS(pMs->server));
STRSRVSTATUS(&server));
}
#endif
if (SERVER_IS_DOWN(pMs->server))
{
@ -2690,6 +2706,8 @@ void MonitorInstance::tick()
}
}
}
flush_server_status();
}
void MonitorInstance::main()

View File

@ -83,8 +83,6 @@ void AuroraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
{
mon_report_query_error(monitored_server);
}
monitored_server->server->status = monitored_server->pending_status;
}
bool AuroraMonitor::has_sufficient_permissions() const

View File

@ -492,14 +492,6 @@ void GaleraMonitor::tick()
{
update_sst_donor_nodes(is_cluster);
}
ptr = m_monitor->monitored_servers;
while (ptr)
{
ptr->server->status = ptr->pending_status;
ptr = ptr->next;
}
}
/**

View File

@ -142,8 +142,6 @@ void GRMon::update_server_status(MXS_MONITORED_SERVER* monitored_server)
monitor_clear_pending_status(monitored_server, SERVER_SLAVE);
monitor_clear_pending_status(monitored_server, SERVER_MASTER);
}
monitored_server->server->status = monitored_server->pending_status;
}
/**

View File

@ -419,10 +419,7 @@ void MMMonitor::tick()
/* Set the STALE bit for this server in server struct */
monitor_set_pending_status(ptr, SERVER_STALE_STATUS);
}
ptr->server->status = ptr->pending_status;
}
ptr = ptr->next;
}
}

View File

@ -206,6 +206,4 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
monitor_clear_pending_status(monitored_server, SERVER_NDB);
monitored_server->server->depth = -1;
}
monitored_server->server->status = monitored_server->pending_status;
}