MySQL 9.1.0
Source Code Documentation
UnreachableDestinationsQuarantine Class Reference

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_contextio_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_
 

Detailed Description

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.

Member Function Documentation

◆ add_destination_candidate_to_quarantine()

void UnreachableDestinationsQuarantine::add_destination_candidate_to_quarantine ( const mysql_harness::TCPAddress dest)
private

◆ drop_stray_destinations()

void UnreachableDestinationsQuarantine::drop_stray_destinations ( const std::string &  instance_name,
const AllowedNodes routing_new_destinations 
)
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.

Parameters
[in]instance_nameRouting instance name that got destination candidates list update.
[in]routing_new_destinationsList of new destination candidates for the given routing instance.

◆ get_referencing_routing_instances()

std::vector< std::string > UnreachableDestinationsQuarantine::get_referencing_routing_instances ( const mysql_harness::TCPAddress destination)
private

For a given destination get names of all routing instances that references it.

Parameters
[in]destinationDestination candidate address.
Returns
List of referencing routing instance names

◆ init()

void UnreachableDestinationsQuarantine::init ( std::chrono::seconds  quarantine_interval,
uint32_t  qurantine_threshold 
)

Initialize the unreachable destination candidate mechanism.

It will set up:

  • routing plugin instances callbacks used for probing/updating the unreachable destinations
  • harness context variable used for starting/stopping the routing listening sockets
  • quarantine_refresh_interval Used for unreachable destination candidates availability checks.
    Parameters
    [in]quarantine_intervalThe interval in seconds used for checking the health (connectivity) of the quarantined destinations.
    [in]qurantine_thresholdNumber of consecutive reported failed connections to the destination until it gets quarantined.

◆ is_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.

Parameters
[in]destDestination candidate address.
Returns
true if the destination candidate is quarantined, false otherwise.

◆ quarantine_handler()

void UnreachableDestinationsQuarantine::quarantine_handler ( const std::error_code &  ec,
const mysql_harness::TCPAddress dest 
)
private

Async handler responsible of periodic checks for destination candidate availability.

Parameters
[in]ecResult of async operation.
[in]destDestination candidate address.

◆ refresh_quarantine()

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.

Parameters
[in]instance_nameRouting plugin instance name.
[in]nodes_changed_on_md_refreshInformation if the destination candidates have been updated for the given routing plugin.
[in]available_destinationsList of destination candidates that are available for the given routing plugin after metadata refresh.

◆ register_route()

void UnreachableDestinationsQuarantine::register_route ( const std::string &  route_name)

◆ register_routing_callbacks()

void UnreachableDestinationsQuarantine::register_routing_callbacks ( QuarantineRoutingCallbacks &&  routing_callbacks)

◆ remove_destination_candidate_from_quarantine()

void UnreachableDestinationsQuarantine::remove_destination_candidate_from_quarantine ( const mysql_harness::TCPAddress dest)

Remove unreachable destination candidate from quarantine.

Parameters
[in]destUnreachable destination candidate address.

◆ report_connection_result()

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.

Parameters
[in]destReported destination address.
[in]successIndicates if the reported connection result is success of failure.
Returns
true if the destination got added to the quarantine, false otherwise

◆ stop_quarantine()

void UnreachableDestinationsQuarantine::stop_quarantine ( )

Stop all async operations and clear the quarantine list.

◆ stop_socket_acceptors_on_all_nodes_quarantined()

void UnreachableDestinationsQuarantine::stop_socket_acceptors_on_all_nodes_quarantined ( )
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.

◆ unregister_routing_callbacks()

void UnreachableDestinationsQuarantine::unregister_routing_callbacks ( )

◆ update_destinations_state()

void UnreachableDestinationsQuarantine::update_destinations_state ( const AllowedNodes destination_list)
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.

Parameters
[in]destination_listDestination candidates reported to be available.

Member Data Documentation

◆ destination_errors_

std::map<mysql_harness::TCPAddress, uint32_t> UnreachableDestinationsQuarantine::destination_errors_
private

◆ destination_errors_mutex_

std::mutex UnreachableDestinationsQuarantine::destination_errors_mutex_
private

◆ io_ctx_

net::io_context& UnreachableDestinationsQuarantine::io_ctx_ = IoComponent::get_instance().io_context()
private

◆ kQuarantinedConnectTimeout

std::chrono::milliseconds UnreachableDestinationsQuarantine::kQuarantinedConnectTimeout {1000}
private

◆ quarantine_empty_cond_

std::condition_variable UnreachableDestinationsQuarantine::quarantine_empty_cond_
private

◆ quarantine_empty_cond_m_

std::mutex UnreachableDestinationsQuarantine::quarantine_empty_cond_m_
private

◆ quarantine_interval_

std::chrono::seconds UnreachableDestinationsQuarantine::quarantine_interval_ {1}
private

◆ quarantine_mutex_

std::mutex UnreachableDestinationsQuarantine::quarantine_mutex_
private

◆ quarantine_threshold_

uint32_t UnreachableDestinationsQuarantine::quarantine_threshold_ {1}
private

◆ quarantined_dest_counter_

std::atomic<size_t> UnreachableDestinationsQuarantine::quarantined_dest_counter_ {0}
private

number of quarantined destinations

◆ quarantined_destination_candidates_

std::vector<std::shared_ptr<Unreachable_destination_candidate> > UnreachableDestinationsQuarantine::quarantined_destination_candidates_
private

◆ routing_callbacks_

QuarantineRoutingCallbacks UnreachableDestinationsQuarantine::routing_callbacks_
private

◆ routing_instances_

std::vector<std::string> UnreachableDestinationsQuarantine::routing_instances_
private

◆ routing_instances_mutex_

std::mutex UnreachableDestinationsQuarantine::routing_instances_mutex_
private

◆ stopped_

std::atomic<bool> UnreachableDestinationsQuarantine::stopped_ {false}
private

◆ unreachable_destinations_init_mutex_

std::mutex UnreachableDestinationsQuarantine::unreachable_destinations_init_mutex_
private

The documentation for this class was generated from the following files: