MXS-2424 Refactor for further changes
In subsequent change(s) persisted node information will be used as a last resort to connect to a Clustrix node.
This commit is contained in:
@ -274,62 +274,25 @@ void ClustrixMonitor::choose_hub(Clustrix::Softfailed softfailed)
|
|||||||
{
|
{
|
||||||
mxb_assert(!m_pHub_con);
|
mxb_assert(!m_pHub_con);
|
||||||
|
|
||||||
SERVER* pHub_server = nullptr;
|
|
||||||
MYSQL* pHub_con = nullptr;
|
|
||||||
|
|
||||||
set<string> ips;
|
set<string> ips;
|
||||||
|
|
||||||
// First we check the dynamic servers, in case there are.
|
// First we check the dynamic servers, in case there are,
|
||||||
for (auto it = m_nodes.begin(); !pHub_con && (it != m_nodes.end()); ++it)
|
if (!choose_dynamic_hub(softfailed, ips))
|
||||||
{
|
{
|
||||||
auto& element = *it;
|
// then we check the bootstrap servers, and
|
||||||
ClustrixNode& node = element.second;
|
if (!choose_bootstrap_hub(softfailed, ips))
|
||||||
|
|
||||||
if (node.can_be_used_as_hub(name(), m_settings.conn_settings))
|
|
||||||
{
|
{
|
||||||
pHub_con = node.release_connection();
|
// finally, if all else fails, we check servers that have been persisted.
|
||||||
pHub_server = node.server();
|
// In practise we will only get here at startup (no dynamic servers)
|
||||||
}
|
// if the bootstrap servers cannot be contacted.
|
||||||
|
choose_persisted_hub(softfailed, ips);
|
||||||
ips.insert(node.ip());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pHub_con)
|
|
||||||
{
|
|
||||||
// If that fails, then we check the bootstrap servers, but only if
|
|
||||||
// it was not checked above.
|
|
||||||
|
|
||||||
for (auto it = m_servers.begin(); !pHub_con && (it != m_servers.end()); ++it)
|
|
||||||
{
|
|
||||||
MonitorServer& ms = **it;
|
|
||||||
|
|
||||||
if (ips.find(ms.server->address) == ips.end())
|
|
||||||
{
|
|
||||||
if (Clustrix::ping_or_connect_to_hub(name(), m_settings.conn_settings, softfailed, ms))
|
|
||||||
{
|
|
||||||
pHub_con = ms.con;
|
|
||||||
pHub_server = ms.server;
|
|
||||||
}
|
|
||||||
else if (ms.con)
|
|
||||||
{
|
|
||||||
mysql_close(ms.con);
|
|
||||||
}
|
|
||||||
|
|
||||||
ms.con = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHub_con)
|
if (m_pHub_con)
|
||||||
{
|
{
|
||||||
MXS_NOTICE("%s: Monitoring Clustrix cluster state using node %s:%d.",
|
MXS_NOTICE("%s: Monitoring Clustrix cluster state using node %s:%d.",
|
||||||
name(), pHub_server->address, pHub_server->port);
|
name(), m_pHub_server->address, m_pHub_server->port);
|
||||||
|
|
||||||
m_pHub_con = pHub_con;
|
|
||||||
m_pHub_server = pHub_server;
|
|
||||||
|
|
||||||
mxb_assert(m_pHub_con);
|
|
||||||
mxb_assert(m_pHub_con);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -338,6 +301,56 @@ void ClustrixMonitor::choose_hub(Clustrix::Softfailed softfailed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClustrixMonitor::choose_dynamic_hub(Clustrix::Softfailed softfailed, std::set<string>& ips_checked)
|
||||||
|
{
|
||||||
|
for (auto it = m_nodes.begin(); !m_pHub_con && (it != m_nodes.end()); ++it)
|
||||||
|
{
|
||||||
|
auto& element = *it;
|
||||||
|
ClustrixNode& node = element.second;
|
||||||
|
|
||||||
|
if (node.can_be_used_as_hub(name(), m_settings.conn_settings, softfailed))
|
||||||
|
{
|
||||||
|
m_pHub_con = node.release_connection();
|
||||||
|
m_pHub_server = node.server();
|
||||||
|
}
|
||||||
|
|
||||||
|
ips_checked.insert(node.ip());
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_pHub_con != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClustrixMonitor::choose_bootstrap_hub(Clustrix::Softfailed softfailed, std::set<string>& ips_checked)
|
||||||
|
{
|
||||||
|
for (auto it = m_servers.begin(); !m_pHub_con && (it != m_servers.end()); ++it)
|
||||||
|
{
|
||||||
|
MonitorServer& ms = **it;
|
||||||
|
|
||||||
|
if (ips_checked.find(ms.server->address) == ips_checked.end())
|
||||||
|
{
|
||||||
|
if (Clustrix::ping_or_connect_to_hub(name(), m_settings.conn_settings, softfailed, ms))
|
||||||
|
{
|
||||||
|
m_pHub_con = ms.con;
|
||||||
|
m_pHub_server = ms.server;
|
||||||
|
}
|
||||||
|
else if (ms.con)
|
||||||
|
{
|
||||||
|
mysql_close(ms.con);
|
||||||
|
}
|
||||||
|
|
||||||
|
ms.con = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_pHub_con != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClustrixMonitor::choose_persisted_hub(Clustrix::Softfailed softfailed, std::set<string>& ips_checked)
|
||||||
|
{
|
||||||
|
// TODO: Check persisted servers.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ClustrixMonitor::refresh_nodes()
|
void ClustrixMonitor::refresh_nodes()
|
||||||
{
|
{
|
||||||
mxb_assert(m_pHub_con);
|
mxb_assert(m_pHub_con);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "clustrixmon.hh"
|
#include "clustrixmon.hh"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <maxscale/monitor.hh>
|
#include <maxscale/monitor.hh>
|
||||||
#include <maxbase/http.hh>
|
#include <maxbase/http.hh>
|
||||||
@ -87,6 +88,11 @@ private:
|
|||||||
void check_cluster(Clustrix::Softfailed softfailed);
|
void check_cluster(Clustrix::Softfailed softfailed);
|
||||||
void check_hub(Clustrix::Softfailed softfailed);
|
void check_hub(Clustrix::Softfailed softfailed);
|
||||||
void choose_hub(Clustrix::Softfailed softfailed);
|
void choose_hub(Clustrix::Softfailed softfailed);
|
||||||
|
|
||||||
|
bool choose_dynamic_hub(Clustrix::Softfailed softfailed, std::set<std::string>& ips_checked);
|
||||||
|
bool choose_bootstrap_hub(Clustrix::Softfailed softfailed, std::set<std::string>& ips_checked);
|
||||||
|
bool choose_persisted_hub(Clustrix::Softfailed softfailed, std::set<std::string>& ips_checked);
|
||||||
|
|
||||||
void refresh_nodes();
|
void refresh_nodes();
|
||||||
bool check_cluster_membership(std::map<int, ClustrixMembership>* pMemberships);
|
bool check_cluster_membership(std::map<int, ClustrixMembership>* pMemberships);
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
#include "clustrix.hh"
|
#include "clustrix.hh"
|
||||||
|
|
||||||
bool ClustrixNode::can_be_used_as_hub(const char* zName,
|
bool ClustrixNode::can_be_used_as_hub(const char* zName,
|
||||||
const mxs::MonitorServer::ConnectionSettings& settings)
|
const mxs::MonitorServer::ConnectionSettings& settings,
|
||||||
|
Clustrix::Softfailed softfailed)
|
||||||
{
|
{
|
||||||
mxb_assert(m_pServer);
|
mxb_assert(m_pServer);
|
||||||
bool rv = Clustrix::ping_or_connect_to_hub(zName, settings, Clustrix::Softfailed::REJECT,
|
bool rv = Clustrix::ping_or_connect_to_hub(zName, settings, softfailed, *m_pServer, &m_pCon);
|
||||||
*m_pServer, &m_pCon);
|
|
||||||
|
|
||||||
if (!rv)
|
if (!rv)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool can_be_used_as_hub(const char* zName,
|
bool can_be_used_as_hub(const char* zName,
|
||||||
const mxs::MonitorServer::ConnectionSettings& settings);
|
const mxs::MonitorServer::ConnectionSettings& settings,
|
||||||
|
Clustrix::Softfailed softfailed);
|
||||||
|
|
||||||
SERVER* server() const
|
SERVER* server() const
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user