MySQL 9.1.0
Source Code Documentation
DestMetadataCacheGroup Class Referencefinal

#include <dest_metadata_cache.h>

Inheritance diagram for DestMetadataCacheGroup:
[legend]

Public Types

enum  ServerRole { Primary , Secondary , PrimaryAndSecondary }
 
- Public Types inherited from RouteDestination
using AddrVector = std::vector< mysql_harness::TCPAddress >
 

Public Member Functions

 DestMetadataCacheGroup (net::io_context &io_ctx_, const std::string &metadata_cache, const routing::RoutingStrategy routing_strategy, const mysqlrouter::URIQuery &query, const Protocol::Type protocol, metadata_cache::MetadataCacheAPIBase *cache_api=metadata_cache::MetadataCacheAPI::instance())
 Constructor. More...
 
 DestMetadataCacheGroup (const DestMetadataCacheGroup &other)=delete
 Copy constructor. More...
 
 DestMetadataCacheGroup (DestMetadataCacheGroup &&)=delete
 Move constructor. More...
 
DestMetadataCacheGroupoperator= (const DestMetadataCacheGroup &)=delete
 Copy assignment. More...
 
DestMetadataCacheGroupoperator= (DestMetadataCacheGroup &&)=delete
 Move assignment. More...
 
 ~DestMetadataCacheGroup () override
 
void add (const std::string &, uint16_t) override
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void add (const mysql_harness::TCPAddress) override
 Adds a destination. More...
 
AddrVector get_destinations () const override
 
bool empty () const noexcept override
 Returns whether there are destination servers. More...
 
void start (const mysql_harness::PluginFuncEnv *env) override
 Start the destination. More...
 
Destinations destinations () override
 get destinations to connect() to. More...
 
mysqlrouter::ServerMode purpose () const override
 
ServerRole server_role () const
 
metadata_cache::MetadataCacheAPIBasecache_api ()
 
std::optional< Destinationsrefresh_destinations (const Destinations &dests) override
 refresh destinations. More...
 
Destinations primary_destinations ()
 
void advance (size_t n)
 advance the current position in the destination by n. More...
 
void handle_sockets_acceptors () override
 Trigger listening socket acceptors state handler based on the destination type. More...
 
routing::RoutingStrategy get_strategy () override
 Return our routing strategy. More...
 
- Public Member Functions inherited from RouteDestination
 RouteDestination (net::io_context &io_ctx, Protocol::Type protocol=Protocol::get_default())
 Default constructor. More...
 
virtual ~RouteDestination ()=default
 Destructor. More...
 
 RouteDestination (const RouteDestination &other)=delete
 
 RouteDestination (RouteDestination &&other)=delete
 
RouteDestinationoperator= (const RouteDestination &other)=delete
 
RouteDestinationoperator= (RouteDestination &&other)=delete
 
virtual void remove (const std::string &address, uint16_t port)
 Removes a destination. More...
 
virtual mysql_harness::TCPAddress get (const std::string &address, uint16_t port)
 Gets destination based on address and port. More...
 
virtual void clear ()
 Removes all destinations. More...
 
size_t size () noexcept
 Gets the number of destinations. More...
 
AddrVector::iterator begin ()
 
AddrVector::const_iterator begin () const
 
AddrVector::iterator end ()
 
AddrVector::const_iterator end () const
 
- Public Member Functions inherited from DestinationNodesStateNotifier
AllowedNodesChangeCallbacksListIterator register_allowed_nodes_change_callback (const AllowedNodesChangedCallback &clb)
 Registers the callback for notification on the change in the state if the destination nodes. More...
 
void unregister_allowed_nodes_change_callback (const AllowedNodesChangeCallbacksListIterator &it)
 Unregisters the callback registered with register_allowed_nodes_change_callback(). More...
 
void register_start_router_socket_acceptor (const StartSocketAcceptorCallback &clb)
 Registers the callback for notification that the routing socket acceptor should accept new connections. More...
 
void unregister_start_router_socket_acceptor ()
 Unregisters the callback registered with register_start_router_socket_acceptor(). More...
 
void register_stop_router_socket_acceptor (const StopSocketAcceptorCallback &clb)
 Registers the callback for notification that the routing socket acceptor should stop accepting new connections. More...
 
void unregister_stop_router_socket_acceptor ()
 Unregisters the callback registered with register_stop_router_socket_acceptor(). More...
 
void register_md_refresh_callback (const MetadataRefreshCallback &callback)
 Registers a callback that is going to be used on metadata refresh. More...
 
void unregister_md_refresh_callback ()
 Unregisters the callback registered with register_md_refresh_callback(). More...
 
void register_query_quarantined_destinations (const QueryQuarantinedDestinationsCallback &clb)
 Registers a callback that could be used for checking if the provided destination candidate is currently quarantined. More...
 
void unregister_query_quarantined_destinations ()
 Unregisters the callback registered with register_query_quarantined_destinations(). More...
 

Private Member Functions

void init ()
 Initializes. More...
 
std::pair< metadata_cache::cluster_nodes_list_t, bool > get_available (const metadata_cache::cluster_nodes_list_t &instances, bool for_new_connections=true) const
 Gets available destinations from Metadata Cache. More...
 
metadata_cache::cluster_nodes_list_t get_available_primaries (const metadata_cache::cluster_nodes_list_t &managed_servers) const
 
Destinations balance (const metadata_cache::cluster_nodes_list_t &all_replicaset_nodes, bool primary_fallback)
 
void on_instances_change (const metadata_cache::ClusterTopology &cluster_topology, const bool md_servers_reachable)
 
void subscribe_for_metadata_cache_changes ()
 
void subscribe_for_acceptor_handler ()
 
void subscribe_for_md_refresh_handler ()
 
void notify_instances_changed (const metadata_cache::ClusterTopology &cluster_topology, const bool md_servers_reachable, const uint64_t) noexcept override
 Callback function that is called when state of cluster is changed. More...
 
bool update_socket_acceptor_state (const metadata_cache::cluster_nodes_list_t &instances) noexcept override
 Callback function that is called when the state of the sockets acceptors is handled during the metadata refresh. More...
 
void on_md_refresh (const bool instances_changed, const metadata_cache::ClusterTopology &cluster_topology) override
 Callback that is going to be used on each metadata refresh. More...
 

Private Attributes

const std::string cache_name_
 The Metadata Cache to use. More...
 
const mysqlrouter::URIQuery uri_query_
 Query part of the URI given as destination in the configuration. More...
 
routing::RoutingStrategy routing_strategy_
 
ServerRole server_role_
 
metadata_cache::MetadataCacheAPIBasecache_api_
 
bool subscribed_for_metadata_cache_changes_ {false}
 
bool disconnect_on_promoted_to_primary_ {false}
 
bool disconnect_on_metadata_unavailable_ {false}
 
size_t start_pos_ {}
 
size_t ro_start_pos_ {}
 
size_t rw_start_pos_ {}
 

Additional Inherited Members

- Protected Attributes inherited from RouteDestination
AddrVector destinations_
 List of destinations. More...
 
std::mutex mutex_update_
 Mutex for updating destinations and iterator. More...
 
net::io_contextio_ctx_
 
Protocol::Type protocol_
 Protocol for the destination. More...
 
- Protected Attributes inherited from DestinationNodesStateNotifier
AllowedNodesChangeCallbacksList allowed_nodes_change_callbacks_
 
MetadataRefreshCallback md_refresh_callback_
 
StartSocketAcceptorCallback start_router_socket_acceptor_callback_
 
StopSocketAcceptorCallback stop_router_socket_acceptor_callback_
 
QueryQuarantinedDestinationsCallback query_quarantined_destinations_callback_
 
std::mutex allowed_nodes_change_callbacks_mtx_
 
std::mutex md_refresh_callback_mtx_
 
std::mutex socket_acceptor_handle_callbacks_mtx
 
std::mutex query_quarantined_destinations_callback_mtx_
 

Member Enumeration Documentation

◆ ServerRole

Enumerator
Primary 
Secondary 
PrimaryAndSecondary 

Constructor & Destructor Documentation

◆ DestMetadataCacheGroup() [1/3]

DestMetadataCacheGroup::DestMetadataCacheGroup ( net::io_context io_ctx_,
const std::string &  metadata_cache,
const routing::RoutingStrategy  routing_strategy,
const mysqlrouter::URIQuery query,
const Protocol::Type  protocol,
metadata_cache::MetadataCacheAPIBase cache_api = metadata_cache::MetadataCacheAPI::instance() 
)

Constructor.

◆ DestMetadataCacheGroup() [2/3]

DestMetadataCacheGroup::DestMetadataCacheGroup ( const DestMetadataCacheGroup other)
delete

Copy constructor.

◆ DestMetadataCacheGroup() [3/3]

DestMetadataCacheGroup::DestMetadataCacheGroup ( DestMetadataCacheGroup &&  )
delete

Move constructor.

◆ ~DestMetadataCacheGroup()

DestMetadataCacheGroup::~DestMetadataCacheGroup ( )
override

Member Function Documentation

◆ add() [1/2]

void DestMetadataCacheGroup::add ( const mysql_harness::TCPAddress  dest)
inlineoverridevirtual

Adds a destination.

Adds a destination using the given address and port number.

Parameters
destdestination address

Reimplemented from RouteDestination.

◆ add() [2/2]

void DestMetadataCacheGroup::add ( const std::string &  address,
uint16_t  port 
)
inlineoverridevirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Reimplemented from RouteDestination.

◆ advance()

void DestMetadataCacheGroup::advance ( size_t  n)

advance the current position in the destination by n.

◆ balance()

Destinations DestMetadataCacheGroup::balance ( const metadata_cache::cluster_nodes_list_t all_replicaset_nodes,
bool  primary_fallback 
)
private

◆ cache_api()

metadata_cache::MetadataCacheAPIBase * DestMetadataCacheGroup::cache_api ( )
inline

◆ destinations()

Destinations DestMetadataCacheGroup::destinations ( )
overridevirtual

get destinations to connect() to.

destinations are in order of preference.

Implements RouteDestination.

◆ empty()

bool DestMetadataCacheGroup::empty ( ) const
inlineoverridevirtualnoexcept

Returns whether there are destination servers.

The empty() method always returns false for Metadata Cache.

Checking whether the Metadata Cache is empty for given destination might be to expensive. We leave this to the get_server() method.

Returns
Always returns False for Metadata Cache destination.

Reimplemented from RouteDestination.

◆ get_available()

std::pair< metadata_cache::cluster_nodes_list_t, bool > DestMetadataCacheGroup::get_available ( const metadata_cache::cluster_nodes_list_t instances,
bool  for_new_connections = true 
) const
private

Gets available destinations from Metadata Cache.

This method gets the destinations using Metadata Cache information. It uses the metadata_cache::get_cluster_nodes() function to get a list of current managed servers. Bool in the returned pair indicates if (in case of the round-robin-with-fallback routing strategy) the returned nodes are the primaries after the fallback (true), regular primaries (false) or secondaries (false).

◆ get_available_primaries()

metadata_cache::cluster_nodes_list_t DestMetadataCacheGroup::get_available_primaries ( const metadata_cache::cluster_nodes_list_t managed_servers) const
private

◆ get_destinations()

DestMetadataCacheGroup::AddrVector DestMetadataCacheGroup::get_destinations ( ) const
overridevirtual

Reimplemented from RouteDestination.

◆ get_strategy()

routing::RoutingStrategy DestMetadataCacheGroup::get_strategy ( )
inlineoverridevirtual

Return our routing strategy.

Implements RouteDestination.

◆ handle_sockets_acceptors()

void DestMetadataCacheGroup::handle_sockets_acceptors ( )
inlineoverridevirtual

Trigger listening socket acceptors state handler based on the destination type.

Reimplemented from RouteDestination.

◆ init()

void DestMetadataCacheGroup::init ( )
private

Initializes.

This method initialized the object. It goes of the URI query information and sets members accordingly.

◆ notify_instances_changed()

void DestMetadataCacheGroup::notify_instances_changed ( const metadata_cache::ClusterTopology cluster_topology,
const bool  md_servers_reachable,
const uint64_t  view_id 
)
overrideprivatevirtualnoexcept

Callback function that is called when state of cluster is changed.

Parameters
cluster_topologycurrent cluster topology
md_servers_reachabletrue if metadata changed, false if metadata unavailable
view_idcurrent metadata view_id in case of ReplicaSet cluster

Implements metadata_cache::ClusterStateListenerInterface.

◆ on_instances_change()

void DestMetadataCacheGroup::on_instances_change ( const metadata_cache::ClusterTopology cluster_topology,
const bool  md_servers_reachable 
)
private

◆ on_md_refresh()

void DestMetadataCacheGroup::on_md_refresh ( const bool  instances_changed,
const metadata_cache::ClusterTopology cluster_topology 
)
overrideprivatevirtual

Callback that is going to be used on each metadata refresh.

Parameters
[in]instances_changedInforms if the cluster topology has changed since last md refresh.
[in]cluster_topologycurrent cluster topology

Implements metadata_cache::MetadataRefreshListenerInterface.

◆ operator=() [1/2]

DestMetadataCacheGroup & DestMetadataCacheGroup::operator= ( const DestMetadataCacheGroup )
delete

Copy assignment.

◆ operator=() [2/2]

DestMetadataCacheGroup & DestMetadataCacheGroup::operator= ( DestMetadataCacheGroup &&  )
delete

Move assignment.

◆ primary_destinations()

Destinations DestMetadataCacheGroup::primary_destinations ( )

◆ purpose()

mysqlrouter::ServerMode DestMetadataCacheGroup::purpose ( ) const
inlineoverridevirtual

Reimplemented from RouteDestination.

◆ refresh_destinations()

std::optional< Destinations > DestMetadataCacheGroup::refresh_destinations ( const Destinations dests)
overridevirtual

refresh destinations.

should be called after connecting to all destinations failed.

Parameters
destsprevious destinations.
Returns
new destinations, if there are any.

Reimplemented from RouteDestination.

◆ server_role()

ServerRole DestMetadataCacheGroup::server_role ( ) const
inline

◆ start()

void DestMetadataCacheGroup::start ( const mysql_harness::PluginFuncEnv env)
overridevirtual

Start the destination.

It also overwrites parent class' RouteDestination::start(), which launches Quarantine. For Metadata Cache routing, we don't need it.

Parameters
envpointer to the PluginFuncEnv object

Reimplemented from RouteDestination.

◆ subscribe_for_acceptor_handler()

void DestMetadataCacheGroup::subscribe_for_acceptor_handler ( )
private

◆ subscribe_for_md_refresh_handler()

void DestMetadataCacheGroup::subscribe_for_md_refresh_handler ( )
private

◆ subscribe_for_metadata_cache_changes()

void DestMetadataCacheGroup::subscribe_for_metadata_cache_changes ( )
private

◆ update_socket_acceptor_state()

bool DestMetadataCacheGroup::update_socket_acceptor_state ( const metadata_cache::cluster_nodes_list_t instances)
overrideprivatevirtualnoexcept

Callback function that is called when the state of the sockets acceptors is handled during the metadata refresh.

Parameters
instanceslist of the current cluster nodes

Implements metadata_cache::AcceptorUpdateHandlerInterface.

Member Data Documentation

◆ cache_api_

metadata_cache::MetadataCacheAPIBase* DestMetadataCacheGroup::cache_api_
private

◆ cache_name_

const std::string DestMetadataCacheGroup::cache_name_
private

The Metadata Cache to use.

cache_name_ is the the section key in the configuration of Metadata Cache.

For example, given following Metadata Cache configuration, cache_name_ will be set to "ham":

[metadata_cache.ham]
host = metadata.example.com

◆ disconnect_on_metadata_unavailable_

bool DestMetadataCacheGroup::disconnect_on_metadata_unavailable_ {false}
private

◆ disconnect_on_promoted_to_primary_

bool DestMetadataCacheGroup::disconnect_on_promoted_to_primary_ {false}
private

◆ ro_start_pos_

size_t DestMetadataCacheGroup::ro_start_pos_ {}
private

◆ routing_strategy_

routing::RoutingStrategy DestMetadataCacheGroup::routing_strategy_
private

◆ rw_start_pos_

size_t DestMetadataCacheGroup::rw_start_pos_ {}
private

◆ server_role_

ServerRole DestMetadataCacheGroup::server_role_
private

◆ start_pos_

size_t DestMetadataCacheGroup::start_pos_ {}
private

◆ subscribed_for_metadata_cache_changes_

bool DestMetadataCacheGroup::subscribed_for_metadata_cache_changes_ {false}
private

◆ uri_query_

const mysqlrouter::URIQuery DestMetadataCacheGroup::uri_query_
private

Query part of the URI given as destination in the configuration.

For example, given following Metadata Cache configuration:

[routing:metadata_read_only]
..
destination =

metadata_cache:///cluster_name/replicaset_name?role=PRIMARY_AND_SECONDARY

The 'role' is part of uri_query_.


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