MXS-2271 Move connection settings inside settings struct
Since the settings are now protected fields, all related functions were moved inside the monitor class. mon_ping_or_connect_to_db() is now a method of MXS_MONITORED_SERVER. The connection settings class is defined inside the server since that is the class actually using the settings.
This commit is contained in:
@ -154,11 +154,11 @@ bool Clustrix::is_part_of_the_quorum(const SERVER& server, MYSQL* pCon)
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool Clustrix::ping_or_connect_to_hub(const Monitor& mon, SERVER& server, MYSQL** ppCon)
|
||||
bool Clustrix::ping_or_connect_to_hub(const MXS_MONITORED_SERVER::ConnectionSettings& sett, SERVER& server,
|
||||
MYSQL** ppCon)
|
||||
{
|
||||
bool connected = false;
|
||||
|
||||
mxs_connect_result_t rv = mon_ping_or_connect_to_db(mon, server, ppCon);
|
||||
mxs_connect_result_t rv = mon_ping_or_connect_to_db(sett, server, ppCon);
|
||||
|
||||
if (mon_connection_is_ok(rv))
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ inline bool is_part_of_the_quorum(MXS_MONITORED_SERVER& ms)
|
||||
* Ping or create connection to server and check whether it can be used
|
||||
* as hub.
|
||||
*
|
||||
* @param mon The monitor.
|
||||
* @param sett Connection settings
|
||||
* @param server Server object referring to a Clustrix node.
|
||||
* @param ppCon Address of pointer to MYSQL object referring to @server
|
||||
* (@c *ppCon may also be NULL).
|
||||
@ -77,20 +77,21 @@ inline bool is_part_of_the_quorum(MXS_MONITORED_SERVER& ms)
|
||||
*
|
||||
* @note Upon return @c *ppCon will be non-NULL.
|
||||
*/
|
||||
bool ping_or_connect_to_hub(const Monitor& mon, SERVER& server, MYSQL** ppCon);
|
||||
bool ping_or_connect_to_hub(const MXS_MONITORED_SERVER::ConnectionSettings& sett, SERVER& server,
|
||||
MYSQL** ppCon);
|
||||
|
||||
/**
|
||||
* Ping or create connection to server and check whether it can be used
|
||||
* as hub.
|
||||
*
|
||||
* @param mon The monitor.
|
||||
* @param ms Monitored server object referring to a Clustrix node.
|
||||
*
|
||||
* @param sett Connection settings
|
||||
* @return True, if the server can be used as hub, false otherwise.
|
||||
*/
|
||||
inline bool ping_or_connect_to_hub(const Monitor& mon, MXS_MONITORED_SERVER& ms)
|
||||
inline bool ping_or_connect_to_hub(const MXS_MONITORED_SERVER::ConnectionSettings& sett,
|
||||
MXS_MONITORED_SERVER& ms)
|
||||
{
|
||||
return ping_or_connect_to_hub(mon, *ms.server, &ms.con);
|
||||
return ping_or_connect_to_hub(sett, *ms.server, &ms.con);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ void ClustrixMonitor::choose_hub()
|
||||
auto& element = *it;
|
||||
ClustrixNode& node = element.second;
|
||||
|
||||
if (node.can_be_used_as_hub(*this))
|
||||
if (node.can_be_used_as_hub(m_settings.conn_settings))
|
||||
{
|
||||
pHub_con = node.release_connection();
|
||||
pHub_server = node.server();
|
||||
@ -135,7 +135,7 @@ void ClustrixMonitor::choose_hub()
|
||||
|
||||
if (ips.find(ms.server->address) == ips.end())
|
||||
{
|
||||
if (Clustrix::ping_or_connect_to_hub(*this, ms))
|
||||
if (Clustrix::ping_or_connect_to_hub(m_settings.conn_settings, ms))
|
||||
{
|
||||
pHub_con = ms.con;
|
||||
pHub_server = ms.server;
|
||||
@ -339,7 +339,7 @@ void ClustrixMonitor::check_hub()
|
||||
mxb_assert(m_pHub_con);
|
||||
mxb_assert(m_pHub_server);
|
||||
|
||||
if (!Clustrix::ping_or_connect_to_hub(*this, *m_pHub_server, &m_pHub_con))
|
||||
if (!Clustrix::ping_or_connect_to_hub(m_settings.conn_settings, *m_pHub_server, &m_pHub_con))
|
||||
{
|
||||
mysql_close(m_pHub_con);
|
||||
m_pHub_con = nullptr;
|
||||
|
@ -14,11 +14,10 @@
|
||||
#include "clustrixnode.hh"
|
||||
#include "clustrix.hh"
|
||||
|
||||
bool ClustrixNode::can_be_used_as_hub(const Monitor& mon)
|
||||
bool ClustrixNode::can_be_used_as_hub(const MXS_MONITORED_SERVER::ConnectionSettings& sett)
|
||||
{
|
||||
mxb_assert(m_pServer);
|
||||
|
||||
bool rv = Clustrix::ping_or_connect_to_hub(mon, *m_pServer, &m_pCon);
|
||||
bool rv = Clustrix::ping_or_connect_to_hub(sett, *m_pServer, &m_pCon);
|
||||
|
||||
if (!rv)
|
||||
{
|
||||
|
@ -160,7 +160,7 @@ public:
|
||||
m_pServer->is_active = false;
|
||||
}
|
||||
|
||||
bool can_be_used_as_hub(const Monitor& mon);
|
||||
bool can_be_used_as_hub(const MXS_MONITORED_SERVER::ConnectionSettings& sett);
|
||||
|
||||
SERVER* server() const
|
||||
{
|
||||
|
@ -157,8 +157,8 @@ bool MariaDBMonitor::set_replication_credentials(const MXS_CONFIG_PARAMETER* par
|
||||
if (repl_user.empty() && repl_pw.empty())
|
||||
{
|
||||
// No replication credentials defined, use monitor credentials
|
||||
repl_user = m_monitor->user;
|
||||
repl_pw = m_monitor->password;
|
||||
repl_user = m_settings.conn_settings.username;
|
||||
repl_pw = m_settings.conn_settings.password;
|
||||
}
|
||||
|
||||
if (!repl_user.empty() && !repl_pw.empty())
|
||||
@ -345,7 +345,7 @@ json_t* MariaDBMonitor::to_json() const
|
||||
void MariaDBMonitor::update_server(MariaDBServer* server)
|
||||
{
|
||||
MXS_MONITORED_SERVER* mon_srv = server->m_server_base;
|
||||
mxs_connect_result_t conn_status = mon_ping_or_connect_to_db(m_monitor, mon_srv);
|
||||
mxs_connect_result_t conn_status = mon_srv->ping_or_connect(m_settings.conn_settings);
|
||||
MYSQL* conn = mon_srv->con; // mon_ping_or_connect_to_db() may have reallocated the MYSQL struct.
|
||||
|
||||
if (mon_connection_is_ok(conn_status))
|
||||
|
Reference in New Issue
Block a user