MySQL 8.0.39
Source Code Documentation
|
Information about unreachable destination candidates that is shared between plugin instances. More...
#include <unreachable_destinations_quarantine.h>
Classes | |
struct | Unreachable_destination_candidate |
Class representing a single entry (destination) in quarantined destination set. More... | |
Public Member Functions | |
void | init (std::chrono::seconds quarantine_interval, uint32_t qurantine_threshold) |
Initialize the unreachable destination candidate mechanism. More... | |
void | register_routing_callbacks (QuarantineRoutingCallbacks &&routing_callbacks) |
void | unregister_routing_callbacks () |
void | register_route (const std::string &route_name) |
bool | report_connection_result (const mysql_harness::TCPAddress &dest, bool success) |
Register the connection error or success to a given destination. More... | |
void | remove_destination_candidate_from_quarantine (const mysql_harness::TCPAddress &dest) |
Remove unreachable destination candidate from quarantine. More... | |
bool | is_quarantined (const mysql_harness::TCPAddress &dest) |
Query the quarantined destination candidates set and check if the given destination candidate is quarantined. More... | |
void | refresh_quarantine (const std::string &instance_name, const bool nodes_changed_on_md_refresh, const std::vector< AvailableDestination > &available_destinations) |
Refresh the quarantined destination candidates list on metadata refresh. More... | |
void | stop_quarantine () |
Stop all async operations and clear the quarantine list. More... | |
Private Member Functions | |
void | quarantine_handler (const std::error_code &ec, const mysql_harness::TCPAddress &dest) |
Async handler responsible of periodic checks for destination candidate availability. More... | |
void | add_destination_candidate_to_quarantine (const mysql_harness::TCPAddress &dest) |
void | stop_socket_acceptors_on_all_nodes_quarantined () |
Go through all routing instances and check if there are routing plugins which have all destination candidates added to quarantine, if so lets close the listening socket of such routing instances. More... | |
std::vector< std::string > | get_referencing_routing_instances (const mysql_harness::TCPAddress &destination) |
For a given destination get names of all routing instances that references it. More... | |
void | update_destinations_state (const AllowedNodes &destination_list) |
On metadata refresh we got a destination candidates list that is reported to be available (from the metadata perspective). More... | |
void | drop_stray_destinations (const std::string &instance_name, const AllowedNodes &routing_new_destinations) |
If destination list of a routing instance has changed it is possible that some destinations are no longer referenced by any routing instance. More... | |
Private Attributes | |
std::chrono::milliseconds | kQuarantinedConnectTimeout {1000} |
std::chrono::seconds | quarantine_interval_ {1} |
uint32_t | quarantine_threshold_ {1} |
net::io_context & | io_ctx_ = IoComponent::get_instance().io_context() |
std::mutex | quarantine_mutex_ |
std::vector< std::shared_ptr< Unreachable_destination_candidate > > | quarantined_destination_candidates_ |
std::map< mysql_harness::TCPAddress, uint32_t > | destination_errors_ |
std::mutex | destination_errors_mutex_ |
std::mutex | unreachable_destinations_init_mutex_ |
std::mutex | routing_instances_mutex_ |
std::vector< std::string > | routing_instances_ |
std::atomic< bool > | stopped_ {false} |
std::atomic< size_t > | quarantined_dest_counter_ {0} |
number of quarantined destinations More... | |
std::condition_variable | quarantine_empty_cond_ |
std::mutex | quarantine_empty_cond_m_ |
QuarantineRoutingCallbacks | routing_callbacks_ |
Information about unreachable destination candidates that is shared between plugin instances.
Quarantined destinations will not be used for routing purposes. Each unreachable destination candidate is periodically probed for availability and removed from the unreachable destination candidate set if it became available.
|
private |
|
private |
If destination list of a routing instance has changed it is possible that some destinations are no longer referenced by any routing instance.
In that case we should scan the quarantine list and remove those destinations.
[in] | instance_name | Routing instance name that got destination candidates list update. |
[in] | routing_new_destinations | List of new destination candidates for the given routing instance. |
|
private |
For a given destination get names of all routing instances that references it.
[in] | destination | Destination candidate address. |
void UnreachableDestinationsQuarantine::init | ( | std::chrono::seconds | quarantine_interval, |
uint32_t | qurantine_threshold | ||
) |
Initialize the unreachable destination candidate mechanism.
It will set up:
[in] | quarantine_interval | The interval in seconds used for checking the health (connectivity) of the quarantined destinations. |
[in] | qurantine_threshold | Number of consecutive reported failed connections to the destination until it gets quarantined. |
bool UnreachableDestinationsQuarantine::is_quarantined | ( | const mysql_harness::TCPAddress & | dest | ) |
Query the quarantined destination candidates set and check if the given destination candidate is quarantined.
[in] | dest | Destination candidate address. |
|
private |
Async handler responsible of periodic checks for destination candidate availability.
[in] | ec | Result of async operation. |
[in] | dest | Destination candidate address. |
void UnreachableDestinationsQuarantine::refresh_quarantine | ( | const std::string & | instance_name, |
const bool | nodes_changed_on_md_refresh, | ||
const std::vector< AvailableDestination > & | available_destinations | ||
) |
Refresh the quarantined destination candidates list on metadata refresh.
1) if the destination candidates list got updated we have to go through the quarantined destinations and check if there are still routing plugins that references them. 2) for each destination returned in the metadata (which is available from the md perspective) check if it is still unreachable and should be quarantined.
[in] | instance_name | Routing plugin instance name. |
[in] | nodes_changed_on_md_refresh | Information if the destination candidates have been updated for the given routing plugin. |
[in] | available_destinations | List of destination candidates that are available for the given routing plugin after metadata refresh. |
void UnreachableDestinationsQuarantine::register_route | ( | const std::string & | route_name | ) |
void UnreachableDestinationsQuarantine::register_routing_callbacks | ( | QuarantineRoutingCallbacks && | routing_callbacks | ) |
void UnreachableDestinationsQuarantine::remove_destination_candidate_from_quarantine | ( | const mysql_harness::TCPAddress & | dest | ) |
Remove unreachable destination candidate from quarantine.
[in] | dest | Unreachable destination candidate address. |
bool UnreachableDestinationsQuarantine::report_connection_result | ( | const mysql_harness::TCPAddress & | dest, |
bool | success | ||
) |
Register the connection error or success to a given destination.
If registering a success it will set the number of reported errors to a given connection to 0.
If registering a failure it will increment the number of reported failed connections to the destination. If the number reached the quarantine_threshold the destination will be added to the quarantine. If the destination candidate is not quarantine yet it will starting the async handler for it, otherwise it will just update the referencing plugins list.
[in] | dest | Reported destination address. |
[in] | success | Indicates if the reported connection result is success of failure. |
void UnreachableDestinationsQuarantine::stop_quarantine | ( | ) |
Stop all async operations and clear the quarantine list.
|
private |
Go through all routing instances and check if there are routing plugins which have all destination candidates added to quarantine, if so lets close the listening socket of such routing instances.
void UnreachableDestinationsQuarantine::unregister_routing_callbacks | ( | ) |
|
private |
On metadata refresh we got a destination candidates list that is reported to be available (from the metadata perspective).
Go through this list and check if any of the destination candidate is quarantined, if so verify if it is still unreachable and should be kept in quarantine.
[in] | destination_list | Destination candidates reported to be available. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
number of quarantined destinations
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |