Format routers and monitors

This commit is contained in:
Markus Mäkelä
2019-05-09 11:05:34 +03:00
parent 6625c1296b
commit 418ccf861d
42 changed files with 358 additions and 340 deletions

View File

@ -21,11 +21,10 @@ namespace
{
const char CN_DYNAMIC[] = "dynamic";
const char CN_NORMAL[] = "normal";
const char CN_QUORUM[] = "quorum";
const char CN_STATIC[] = "static";
const char CN_NORMAL[] = "normal";
const char CN_QUORUM[] = "quorum";
const char CN_STATIC[] = "static";
const char CN_UNKNOWN[] = "unknown";
}
std::string Clustrix::to_string(Clustrix::Status status)

View File

@ -120,5 +120,4 @@ inline bool ping_or_connect_to_hub(const char* zName,
{
return ping_or_connect_to_hub(zName, settings, softfailed, *ms.server, &ms.con);
}
}

View File

@ -76,7 +76,7 @@ private:
int m_instance;
};
inline std::ostream& operator << (std::ostream& out, const ClustrixMembership& x)
inline std::ostream& operator<<(std::ostream& out, const ClustrixMembership& x)
{
x.print(out);
return out;

View File

@ -42,7 +42,6 @@ bool handle_unsoftfail(const MODULECMD_ARG* args, json_t** error_out)
return pMon->unsoftfail(pServer, error_out);
}
}
/**

View File

@ -17,18 +17,18 @@
#include <maxscale/ccdefs.hh>
#include <maxbase/log.hh>
#define CLUSTER_MONITOR_INTERVAL_NAME "cluster_monitor_interval"
#define CLUSTER_MONITOR_INTERVAL_NAME "cluster_monitor_interval"
const long DEFAULT_CLUSTER_MONITOR_INTERVAL_VALUE = 60000;
#define DEFAULT_CLUSTER_MONITOR_INTERVAL_ZVALUE "60000"
#define DEFAULT_CLUSTER_MONITOR_INTERVAL_ZVALUE "60000"
#define HEALTH_CHECK_THRESHOLD_NAME "health_check_threshold"
const long DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE = 2;
#define DEFAULT_HEALTH_CHECK_THRESHOLD_ZVALUE "2"
#define HEALTH_CHECK_THRESHOLD_NAME "health_check_threshold"
const long DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE = 2;
#define DEFAULT_HEALTH_CHECK_THRESHOLD_ZVALUE "2"
#define DYNAMIC_NODE_DETECTION_NAME "dynamic_node_detection"
const bool DEFAULT_DYNAMIC_NODE_DETECTION_VALUE = true;
#define DEFAULT_DYNAMIC_NODE_DETECTION_ZVALUE "true"
#define DYNAMIC_NODE_DETECTION_NAME "dynamic_node_detection"
const bool DEFAULT_DYNAMIC_NODE_DETECTION_VALUE = true;
#define DEFAULT_DYNAMIC_NODE_DETECTION_ZVALUE "true"
#define HEALTH_CHECK_PORT_NAME "health_check_port"
const long DEFAULT_HEALTH_CHECK_PORT_VALUE = 3581;
#define DEFAULT_HEALTH_CHECK_PORT_ZVALUE "3581"
#define HEALTH_CHECK_PORT_NAME "health_check_port"
const long DEFAULT_HEALTH_CHECK_PORT_VALUE = 3581;
#define DEFAULT_HEALTH_CHECK_PORT_ZVALUE "3581"

View File

@ -76,7 +76,7 @@ static const char SQL_DN_SELECT[] =
"SELECT ip, mysql_port FROM dynamic_nodes";
using HostPortPair = std::pair<std::string, int>;
using HostPortPair = std::pair<std::string, int>;
using HostPortPairs = std::vector<HostPortPair>;
// sqlite3 callback.
@ -93,7 +93,6 @@ int select_cb(void* pData, int nColumns, char** ppColumn, char** ppNames)
return 0;
}
}
namespace
@ -150,7 +149,6 @@ sqlite3* open_or_create_db(const std::string& path)
return pDb;
}
}
ClustrixMonitor::ClustrixMonitor(const string& name, const string& module, sqlite3* pDb)
@ -164,7 +162,7 @@ ClustrixMonitor::~ClustrixMonitor()
sqlite3_close_v2(m_pDb);
}
//static
// static
ClustrixMonitor* ClustrixMonitor::create(const string& name, const string& module)
{
string path = get_datadir();
@ -224,9 +222,9 @@ bool ClustrixMonitor::softfail(SERVER* pServer, json_t** ppError)
if (is_running())
{
call([this, pServer, ppError, &rv]() {
rv = perform_softfail(pServer, ppError);
},
EXECUTE_QUEUED);
rv = perform_softfail(pServer, ppError);
},
EXECUTE_QUEUED);
}
else
{
@ -246,9 +244,9 @@ bool ClustrixMonitor::unsoftfail(SERVER* pServer, json_t** ppError)
if (is_running())
{
call([this, pServer, ppError, &rv]() {
rv = perform_unsoftfail(pServer, ppError);
},
EXECUTE_QUEUED);
rv = perform_unsoftfail(pServer, ppError);
},
EXECUTE_QUEUED);
}
else
{
@ -317,17 +315,17 @@ void ClustrixMonitor::tick()
case http::Async::ERROR:
MXS_WARNING("%s: Health check round ended with general error.", name());
make_health_check();
break;
make_health_check();
break;
case http::Async::READY:
update_server_statuses();
if (!m_health_urls.empty())
{
make_health_check();
}
break;
make_health_check();
}
break;
}
flush_server_status();
@ -903,7 +901,7 @@ bool ClustrixMonitor::check_cluster_membership(MYSQL* pHub_con,
else
{
MXS_ERROR("%s: Could not execute '%s' on %s: %s",
name(), ZQUERY, mysql_get_host_info(pHub_con), mysql_error(pHub_con));
name(), ZQUERY, mysql_get_host_info(pHub_con), mysql_error(pHub_con));
}
return rv;
@ -949,7 +947,7 @@ void ClustrixMonitor::update_server_statuses()
pMs->stash_current_status();
auto it = find_if(m_nodes_by_id.begin(), m_nodes_by_id.end(),
[pMs](const std::pair<int,ClustrixNode>& element) -> bool {
[pMs](const std::pair<int, ClustrixNode>& element) -> bool {
const ClustrixNode& info = element.second;
return pMs->server->address == info.ip();
});
@ -983,16 +981,16 @@ void ClustrixMonitor::make_health_check()
switch (m_http.status())
{
case http::Async::PENDING:
initiate_delayed_http_check();
break;
initiate_delayed_http_check();
break;
case http::Async::ERROR:
MXS_ERROR("%s: Could not initiate health check.", name());
break;
MXS_ERROR("%s: Could not initiate health check.", name());
break;
case http::Async::READY:
MXS_INFO("%s: Health check available immediately.", name());
break;
MXS_INFO("%s: Health check available immediately.", name());
break;
}
}
@ -1035,7 +1033,7 @@ bool ClustrixMonitor::check_http(Call::action_t action)
for (const auto& result : results)
{
bool running = (result.code == 200); // HTTP OK
bool running = (result.code == 200); // HTTP OK
ClustrixNode& node = it->second;
@ -1126,7 +1124,7 @@ bool ClustrixMonitor::perform_operation(Operation operation,
if (m_pHub_con)
{
auto it = find_if(m_nodes_by_id.begin(), m_nodes_by_id.end(),
[pServer] (const std::pair<int, ClustrixNode>& element) {
[pServer](const std::pair<int, ClustrixNode>& element) {
return element.second.server() == pServer;
});
@ -1137,7 +1135,8 @@ bool ClustrixMonitor::perform_operation(Operation operation,
const char ZQUERY_FORMAT[] = "ALTER CLUSTER %s %d";
int id = node.id();
char zQuery[sizeof(ZQUERY_FORMAT) + sizeof(ZUNSOFTFAIL) + UINTLEN(id)]; // ZUNSOFTFAIL is longer
// ZUNSOFTFAIL is longer
char zQuery[sizeof(ZQUERY_FORMAT) + sizeof(ZUNSOFTFAIL) + UINTLEN(id)];
sprintf(zQuery, ZQUERY_FORMAT, zOperation, id);

View File

@ -21,8 +21,8 @@
#include "clustrixmembership.hh"
#include "clustrixnode.hh"
class ClustrixMonitor : public maxscale::MonitorWorker,
private ClustrixNode::Persister
class ClustrixMonitor : public maxscale::MonitorWorker
, private ClustrixNode::Persister
{
ClustrixMonitor(const ClustrixMonitor&) = delete;
ClustrixMonitor& operator=(const ClustrixMonitor&) = delete;
@ -36,7 +36,7 @@ public:
, m_dynamic_node_detection(DEFAULT_DYNAMIC_NODE_DETECTION_VALUE)
, m_health_check_port(DEFAULT_HEALTH_CHECK_PORT_VALUE)
{
};
}
long cluster_monitor_interval() const
{
@ -179,9 +179,9 @@ private:
std::map<int, ClustrixNode> m_nodes_by_id;
std::vector<std::string> m_health_urls;
mxb::http::Async m_http;
uint32_t m_delayed_http_check_id { 0 };
long m_last_cluster_check { 0 };
SERVER* m_pHub_server { nullptr };
MYSQL* m_pHub_con { nullptr };
sqlite3* m_pDb { nullptr };
uint32_t m_delayed_http_check_id {0};
long m_last_cluster_check {0};
SERVER* m_pHub_server {nullptr};
MYSQL* m_pHub_con {nullptr};
sqlite3* m_pDb {nullptr};
};

View File

@ -110,7 +110,7 @@ public:
bool is_running() const
{
return m_nRunning > 0;
return m_nRunning > 0;
}
void set_running(bool running, approach_t approach = APPROACH_DEFAULT)
@ -231,15 +231,15 @@ private:
Clustrix::SubState m_substate;
int m_instance;
std::string m_ip;
int m_mysql_port { DEFAULT_MYSQL_PORT };
int m_health_port { DEFAULT_HEALTH_PORT };
int m_health_check_threshold { DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE };
int m_nRunning { 0 };
SERVER* m_pServer { nullptr };
MYSQL* m_pCon { nullptr };
int m_mysql_port {DEFAULT_MYSQL_PORT};
int m_health_port {DEFAULT_HEALTH_PORT};
int m_health_check_threshold {DEFAULT_HEALTH_CHECK_THRESHOLD_VALUE};
int m_nRunning {0};
SERVER* m_pServer {nullptr};
MYSQL* m_pCon {nullptr};
};
inline std::ostream& operator << (std::ostream& out, const ClustrixNode& x)
inline std::ostream& operator<<(std::ostream& out, const ClustrixNode& x)
{
x.print(out);
return out;