Move monitor-dependent code in MariaDBServer to MariaDBMonitor
Removes Monitor-dependency from the MariaDBServer-class.
This commit is contained in:
@ -276,12 +276,67 @@ json_t* MariaDBMonitor::diagnostics_json() const
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to and query/update a server.
|
||||||
|
*
|
||||||
|
* @param server The server to update
|
||||||
|
*/
|
||||||
|
void MariaDBMonitor::update_server(MariaDBServer& server)
|
||||||
|
{
|
||||||
|
MXS_MONITORED_SERVER* mon_srv = server.m_server_base;
|
||||||
|
/* Monitor server if not in maintenance. */
|
||||||
|
bool in_maintenance = server.is_in_maintenance();
|
||||||
|
if (!in_maintenance)
|
||||||
|
{
|
||||||
|
mxs_connect_result_t rval = mon_ping_or_connect_to_db(m_monitor, mon_srv);
|
||||||
|
|
||||||
|
MYSQL* conn = mon_srv->con; // mon_ping_or_connect_to_db() may have reallocated the MYSQL struct.
|
||||||
|
if (mon_connection_is_ok(rval))
|
||||||
|
{
|
||||||
|
server.clear_status(SERVER_AUTH_ERROR);
|
||||||
|
server.set_status(SERVER_RUNNING);
|
||||||
|
|
||||||
|
if (rval == MONITOR_CONN_NEWCONN_OK)
|
||||||
|
{
|
||||||
|
server.update_server_info();
|
||||||
|
}
|
||||||
|
if (should_update_disk_space_status(mon_srv))
|
||||||
|
{
|
||||||
|
update_disk_space_status(mon_srv);
|
||||||
|
}
|
||||||
|
// Query MariaDBServer specific data
|
||||||
|
server.monitor_server();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The current server is not running. Clear all but the stale master bit as it is used to detect
|
||||||
|
* masters that went down but came up. */
|
||||||
|
server.clear_status(~SERVER_WAS_MASTER);
|
||||||
|
auto conn_errno = mysql_errno(conn);
|
||||||
|
if (conn_errno == ER_ACCESS_DENIED_ERROR || conn_errno == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)
|
||||||
|
{
|
||||||
|
server.set_status(SERVER_AUTH_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Log connect failure only once, that is, if server was RUNNING or MAINTENANCE during last
|
||||||
|
* iteration. */
|
||||||
|
if (mon_srv->mon_prev_status & (SERVER_RUNNING | SERVER_MAINT))
|
||||||
|
{
|
||||||
|
mon_log_connect_error(mon_srv, rval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Increase or reset the error count of the server. */
|
||||||
|
bool is_running = server.is_running();
|
||||||
|
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)
|
void MariaDBMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
||||||
{
|
{
|
||||||
auto i = m_server_info.find(monitored_server);
|
// Not used and should not be called. Is there a way to check this "statically" (without
|
||||||
ss_dassert(i != m_server_info.end());
|
// template magic)?
|
||||||
|
ss_dassert(!true);
|
||||||
(*i).second->update_server(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MariaDBMonitor::pre_loop()
|
void MariaDBMonitor::pre_loop()
|
||||||
@ -325,7 +380,7 @@ void MariaDBMonitor::tick()
|
|||||||
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
for (auto iter = m_servers.begin(); iter != m_servers.end(); iter++)
|
||||||
{
|
{
|
||||||
MariaDBServer* server = *iter;
|
MariaDBServer* server = *iter;
|
||||||
update_server_status(server->m_server_base);
|
update_server(*server);
|
||||||
|
|
||||||
if (server->m_server_id != SERVER_ID_UNKNOWN)
|
if (server->m_server_id != SERVER_ID_UNKNOWN)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,8 +26,6 @@ extern const char * const CN_AUTO_FAILOVER;
|
|||||||
extern const char * const CN_PROMOTION_SQL_FILE;
|
extern const char * const CN_PROMOTION_SQL_FILE;
|
||||||
extern const char * const CN_DEMOTION_SQL_FILE;
|
extern const char * const CN_DEMOTION_SQL_FILE;
|
||||||
|
|
||||||
class MariaDBMonitor;
|
|
||||||
|
|
||||||
// Map of base struct to MariaDBServer. Does not own the server objects. May not be needed at the end.
|
// Map of base struct to MariaDBServer. Does not own the server objects. May not be needed at the end.
|
||||||
typedef std::tr1::unordered_map<MXS_MONITORED_SERVER*, MariaDBServer*> ServerInfoMap;
|
typedef std::tr1::unordered_map<MXS_MONITORED_SERVER*, MariaDBServer*> ServerInfoMap;
|
||||||
// Map of server id:s to MariaDBServer. Useful when constructing the replication graph.
|
// Map of server id:s to MariaDBServer. Useful when constructing the replication graph.
|
||||||
@ -99,8 +97,6 @@ public:
|
|||||||
bool manual_rejoin(SERVER* rejoin_server, json_t** output);
|
bool manual_rejoin(SERVER* rejoin_server, json_t** output);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class MariaDBServer;
|
|
||||||
void update_server_status(MXS_MONITORED_SERVER* pMonitored_server);
|
|
||||||
void pre_loop();
|
void pre_loop();
|
||||||
void tick();
|
void tick();
|
||||||
void process_state_changes();
|
void process_state_changes();
|
||||||
@ -166,6 +162,8 @@ private:
|
|||||||
bool set_replication_credentials(const MXS_CONFIG_PARAMETER* params);
|
bool set_replication_credentials(const MXS_CONFIG_PARAMETER* params);
|
||||||
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_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();
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <maxscale/mysql_utils.h>
|
#include <maxscale/mysql_utils.h>
|
||||||
#include <maxscale/thread.h>
|
#include <maxscale/thread.h>
|
||||||
#include "mariadbmon.hh"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
@ -698,65 +697,11 @@ bool MariaDBServer::run_sql_from_file(const string& path, json_t** error_out)
|
|||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MariaDBServer::update_server(MariaDBMonitor& monitor)
|
|
||||||
{
|
|
||||||
/* Monitor current node if not in maintenance. */
|
|
||||||
bool in_maintenance = m_server_base->pending_status & SERVER_MAINT;
|
|
||||||
if (!in_maintenance)
|
|
||||||
{
|
|
||||||
monitor_server(monitor);
|
|
||||||
}
|
|
||||||
/** Increase or reset the error count of the server. */
|
|
||||||
bool is_running = m_server_base->pending_status & SERVER_RUNNING;
|
|
||||||
m_server_base->mon_err_count = (is_running || in_maintenance) ? 0 : m_server_base->mon_err_count + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to and query this server.
|
* Query this server.
|
||||||
*
|
|
||||||
* @param base_monitor The cluster monitor.
|
|
||||||
*/
|
*/
|
||||||
void MariaDBServer::monitor_server(MariaDBMonitor& monitor)
|
void MariaDBServer::monitor_server()
|
||||||
{
|
{
|
||||||
MXS_MONITORED_SERVER* mon_srv = m_server_base;
|
|
||||||
mxs_connect_result_t rval = mon_ping_or_connect_to_db(monitor.m_monitor, mon_srv);
|
|
||||||
|
|
||||||
MYSQL* conn = mon_srv->con; // mon_ping_or_connect_to_db() may have reallocated the MYSQL struct.
|
|
||||||
if (mon_connection_is_ok(rval))
|
|
||||||
{
|
|
||||||
clear_status(SERVER_AUTH_ERROR);
|
|
||||||
set_status(SERVER_RUNNING);
|
|
||||||
|
|
||||||
if (rval == MONITOR_CONN_NEWCONN_OK)
|
|
||||||
{
|
|
||||||
update_server_info();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The current server is not running. Clear all but the stale master bit as it is used to detect
|
|
||||||
* masters that went down but came up. */
|
|
||||||
clear_status(~SERVER_WAS_MASTER);
|
|
||||||
auto conn_errno = mysql_errno(conn);
|
|
||||||
if (conn_errno == ER_ACCESS_DENIED_ERROR || conn_errno == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)
|
|
||||||
{
|
|
||||||
set_status(SERVER_AUTH_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Log connect failure only once, that is, if server was RUNNING or MAINTENANCE during last
|
|
||||||
* iteration. */
|
|
||||||
if (m_server_base->mon_prev_status & (SERVER_RUNNING | SERVER_MAINT))
|
|
||||||
{
|
|
||||||
mon_log_connect_error(mon_srv, rval);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor.should_update_disk_space_status(m_server_base))
|
|
||||||
{
|
|
||||||
monitor.update_disk_space_status(m_server_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
string errmsg;
|
string errmsg;
|
||||||
bool query_ok = false;
|
bool query_ok = false;
|
||||||
/* Query different things depending on server version/type. */
|
/* Query different things depending on server version/type. */
|
||||||
|
|||||||
@ -25,7 +25,6 @@ enum print_repl_warnings_t
|
|||||||
};
|
};
|
||||||
|
|
||||||
class QueryResult;
|
class QueryResult;
|
||||||
class MariaDBMonitor;
|
|
||||||
class MariaDBServer;
|
class MariaDBServer;
|
||||||
// Server pointer array
|
// Server pointer array
|
||||||
typedef std::vector<MariaDBServer*> ServerArray;
|
typedef std::vector<MariaDBServer*> ServerArray;
|
||||||
@ -134,6 +133,9 @@ public:
|
|||||||
NodeData m_node; /**< Replication topology data */
|
NodeData m_node; /**< Replication topology data */
|
||||||
MariaDBServer(MXS_MONITORED_SERVER* monitored_server);
|
MariaDBServer(MXS_MONITORED_SERVER* monitored_server);
|
||||||
|
|
||||||
|
void monitor_server();
|
||||||
|
void update_server_info();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate how many events are left in the relay log.
|
* Calculate how many events are left in the relay log.
|
||||||
*
|
*
|
||||||
@ -328,14 +330,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool run_sql_from_file(const std::string& path, json_t** error_out);
|
bool run_sql_from_file(const std::string& path, json_t** error_out);
|
||||||
|
|
||||||
/**
|
|
||||||
* Query and update information of this server. Sets some values for status bits,
|
|
||||||
* but these may be added or overridden by later methods.
|
|
||||||
*
|
|
||||||
* @param base_monitor The base monitor object monitoring this server. Required for connection settings.
|
|
||||||
*/
|
|
||||||
void update_server(MariaDBMonitor& monitor);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear server pending status flags.
|
* Clear server pending status flags.
|
||||||
*
|
*
|
||||||
@ -351,9 +345,7 @@ public:
|
|||||||
void set_status(uint64_t bits);
|
void set_status(uint64_t bits);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void monitor_server(MariaDBMonitor& monitor);
|
|
||||||
bool update_slave_status(std::string* errmsg_out = NULL);
|
bool update_slave_status(std::string* errmsg_out = NULL);
|
||||||
void update_server_info();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user