forked from codership/galera
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-26851 Add interface to monitor connections in Galera
- Loading branch information
1 parent
3f19350
commit 0981e0c
Showing
13 changed files
with
219 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ Authors from Codership Oy: | |
* Daniele Sciascia <[email protected]>, Codership Oy | ||
* Philip Stoev <[email protected]>, Codership Oy | ||
* Mario Karuza <[email protected]>, Codership Oy | ||
* Jan Lindström <[email protected]>, Codership Oy | ||
[Codership employees, add name and email/username above this line, but leave this line intact] | ||
|
||
Other contributors: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright (C) 2010-2021 Codership Oy <[email protected]> | ||
// Copyright (C) 2010-2024 Codership Oy <[email protected]> | ||
// | ||
|
||
#include "wsrep_api.h" | ||
|
@@ -23,6 +23,7 @@ | |
#include "gu_event_service.hpp" | ||
#include "wsrep_config_service.h" | ||
#include "wsrep_node_isolation.h" | ||
#include "wsrep_connection_monitor_service.h" | ||
|
||
#include <cassert> | ||
|
||
|
@@ -1941,4 +1942,14 @@ wsrep_node_isolation_mode_set_v1(enum wsrep_node_isolation_mode mode) | |
return WSREP_NODE_ISOLATION_SUCCESS; | ||
} | ||
|
||
extern "C" | ||
int wsrep_init_connection_monitor_service_v1(wsrep_connection_monitor_service_v1_t *connection_monitor_service) | ||
{ | ||
return gu::init_connection_monitor_service_v1(connection_monitor_service); | ||
} | ||
|
||
extern "C" void wsrep_deinit_connection_monitor_service_v1() | ||
{ | ||
gu::deinit_connection_monitor_service_v1(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright (C) 2014-2020 Codership Oy <[email protected]> | ||
// Copyright (C) 2014-2024 Codership Oy <[email protected]> | ||
// | ||
|
||
#include "gu_config.hpp" | ||
|
@@ -53,6 +53,8 @@ static wsrep_tls_service_v1_t* gu_tls_service(0); | |
|
||
static wsrep_allowlist_service_v1_t* gu_allowlist_service(0); | ||
|
||
static wsrep_connection_monitor_service_v1_t* gu_connection_monitor_service(0); | ||
|
||
// | ||
// AsioIpAddress wrapper | ||
// | ||
|
@@ -955,3 +957,100 @@ void gu::deinit_allowlist_service_v1() | |
std::atomic<enum wsrep_node_isolation_mode> gu::gu_asio_node_isolation_mode{ | ||
WSREP_NODE_ISOLATION_NOT_ISOLATED | ||
}; | ||
|
||
// | ||
// ConnectionMonitor | ||
// | ||
|
||
static std::mutex gu_connection_monitor_service_init_mutex; | ||
static size_t gu_connection_monitor_service_usage; | ||
|
||
int gu::init_connection_monitor_service_v1(wsrep_connection_monitor_service_v1_t* connection_monitor) | ||
{ | ||
log_info << "init_connection_monitor_service_v1"; | ||
std::lock_guard<std::mutex> lock(gu_connection_monitor_service_init_mutex); | ||
++gu_connection_monitor_service_usage; | ||
if (gu_connection_monitor_service) | ||
{ | ||
assert(gu_connection_monitor_service == connection_monitor); | ||
return 0; | ||
} | ||
gu_connection_monitor_service = connection_monitor; | ||
return 0; | ||
} | ||
|
||
void gu::deinit_connection_monitor_service_v1() | ||
{ | ||
log_info << "deinit_connection_monitor_service_v1"; | ||
std::lock_guard<std::mutex> lock(gu_connection_monitor_service_init_mutex); | ||
assert(gu_connection_monitor_service_usage > 0); | ||
--gu_connection_monitor_service_usage; | ||
if (gu_connection_monitor_service_usage == 0) | ||
gu_connection_monitor_service = 0; | ||
} | ||
|
||
void gu::connection_monitor_connect(wsrep_connection_key_t id, | ||
const std::string& scheme, | ||
const std::string& local_addr, | ||
const std::string& remote_uuid, | ||
const std::string& remote_addr) | ||
{ | ||
if (gu_connection_monitor_service == nullptr) | ||
{ | ||
return; // No action | ||
} | ||
|
||
// tcp://127.0.0.1:19006 --> 127.0.0.1:19006 | ||
std::string ra = remote_addr.substr(6, remote_addr.length()); | ||
std::string la = local_addr.substr(6, local_addr.length()); | ||
|
||
wsrep_buf_t const remote = {remote_uuid.c_str(), remote_uuid.length() }; | ||
wsrep_buf_t const lscheme = {scheme.c_str(), scheme.length() }; | ||
wsrep_buf_t const raddr = {ra.c_str(), ra.length() }; | ||
wsrep_buf_t const laddr = {la.c_str(), la.length() }; | ||
|
||
gu_connection_monitor_service->connection_monitor_connect_cb( | ||
gu_connection_monitor_service->context, | ||
id, | ||
&lscheme, | ||
&laddr, | ||
&remote, | ||
&raddr); | ||
} | ||
|
||
void gu::connection_monitor_disconnect(wsrep_connection_key_t id) | ||
{ | ||
if (gu_connection_monitor_service == nullptr) | ||
{ | ||
return; // No action | ||
} | ||
|
||
gu_connection_monitor_service->connection_monitor_disconnect_cb( | ||
gu_connection_monitor_service->context, | ||
id); | ||
} | ||
|
||
void gu::connection_monitor_ssl_info(wsrep_connection_key_t id, | ||
const std::string& chipher, | ||
const std::string& issuer, | ||
const std::string& subject, | ||
const std::string& version) | ||
{ | ||
if (gu_connection_monitor_service == nullptr) | ||
{ | ||
return; // No action | ||
} | ||
|
||
wsrep_buf_t const ch = {chipher.c_str(), chipher.length() }; | ||
wsrep_buf_t const iss = {issuer.c_str(), issuer.length() }; | ||
wsrep_buf_t const sub = {subject.c_str(), subject.length() }; | ||
wsrep_buf_t const vers = {version.c_str(), version.length() }; | ||
|
||
gu_connection_monitor_service->connection_monitor_ssl_info_cb( | ||
gu_connection_monitor_service->context, | ||
id, | ||
&ch, | ||
&iss, | ||
&sub, | ||
&vers); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2009-2019 Codership Oy <[email protected]> | ||
* Copyright (C) 2009-2024 Codership Oy <[email protected]> | ||
*/ | ||
|
||
#include "gmcast.hpp" | ||
|
@@ -584,6 +584,14 @@ void gcomm::GMCast::gmcast_connect(const std::string& remote_addr) | |
segment_, | ||
group_name_); | ||
|
||
std::ostringstream os; | ||
os << peer->remote_uuid().full_str(); | ||
gu::connection_monitor_connect((wsrep_connection_key_t)tp->id(), | ||
get_scheme(pnet_, use_ssl_, dynamic_socket_), | ||
peer->local_addr(), | ||
os.str(), | ||
remote_addr); | ||
|
||
std::pair<ProtoMap::iterator, bool> ret = | ||
proto_map_->insert(std::make_pair(tp->id(), peer)); | ||
|
||
|
@@ -676,6 +684,14 @@ void gcomm::GMCast::handle_established(Proto* est) | |
// UUID checks are handled during protocol handshake | ||
assert(est->remote_uuid() != uuid()); | ||
|
||
std::ostringstream os; | ||
os << est->remote_uuid().full_str(); | ||
gu::connection_monitor_connect((wsrep_connection_key_t)est->socket()->id(), | ||
get_scheme(pnet_, use_ssl_, dynamic_socket_), | ||
est->local_addr(), | ||
os.str(), | ||
est->remote_addr()); | ||
|
||
if (is_evicted(est->remote_uuid())) | ||
{ | ||
log_warn << "Closing connection to evicted node " << est->remote_uuid(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2009-2019 Codership Oy <[email protected]> | ||
* Copyright (C) 2009-2024 Codership Oy <[email protected]> | ||
*/ | ||
|
||
#ifndef GCOMM_GMCAST_PROTO_HPP | ||
|
@@ -150,6 +150,7 @@ class gcomm::gmcast::Proto | |
SocketPtr socket() const { return tp_; } | ||
|
||
const std::string& remote_addr() const { return remote_addr_; } | ||
const std::string& local_addr() const { return local_addr_; } | ||
const std::string& mcast_addr() const { return mcast_addr_; } | ||
const LinkMap& link_map() const { return link_map_; } | ||
|
||
|
Oops, something went wrong.