MySQL 8.4.2
Source Code Documentation
|
#include <dest_metadata_cache.h>
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... | |
DestMetadataCacheGroup & | operator= (const DestMetadataCacheGroup &)=delete |
Copy assignment. More... | |
DestMetadataCacheGroup & | operator= (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... | |
ServerRole | server_role () const |
metadata_cache::MetadataCacheAPIBase * | cache_api () |
std::optional< Destinations > | refresh_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 | |
RouteDestination & | operator= (const RouteDestination &other)=delete |
RouteDestination & | operator= (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... | |
Public Member Functions inherited from metadata_cache::ClusterStateListenerInterface | |
ClusterStateListenerInterface ()=default | |
ClusterStateListenerInterface (const ClusterStateListenerInterface &)=delete | |
ClusterStateListenerInterface & | operator= (const ClusterStateListenerInterface &)=delete |
virtual | ~ClusterStateListenerInterface () |
Public Member Functions inherited from metadata_cache::MetadataRefreshListenerInterface | |
MetadataRefreshListenerInterface ()=default | |
MetadataRefreshListenerInterface (const MetadataRefreshListenerInterface &)=default | |
MetadataRefreshListenerInterface (MetadataRefreshListenerInterface &&)=default | |
MetadataRefreshListenerInterface & | operator= (const MetadataRefreshListenerInterface &)=default |
MetadataRefreshListenerInterface & | operator= (MetadataRefreshListenerInterface &&)=default |
virtual | ~MetadataRefreshListenerInterface ()=default |
Public Member Functions inherited from metadata_cache::AcceptorUpdateHandlerInterface | |
AcceptorUpdateHandlerInterface ()=default | |
AcceptorUpdateHandlerInterface (const AcceptorUpdateHandlerInterface &)=default | |
AcceptorUpdateHandlerInterface & | operator= (const AcceptorUpdateHandlerInterface &)=default |
AcceptorUpdateHandlerInterface (AcceptorUpdateHandlerInterface &&)=default | |
AcceptorUpdateHandlerInterface & | operator= (AcceptorUpdateHandlerInterface &&)=default |
virtual | ~AcceptorUpdateHandlerInterface ()=default |
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::MetadataCacheAPIBase * | cache_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_context & | io_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_ |
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.
|
delete |
Copy constructor.
|
delete |
Move constructor.
|
override |
|
inlineoverridevirtual |
Adds a destination.
Adds a destination using the given address and port number.
dest | destination address |
Reimplemented from RouteDestination.
|
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.
void DestMetadataCacheGroup::advance | ( | size_t | n | ) |
advance the current position in the destination by n.
|
private |
|
inline |
|
overridevirtual |
get destinations to connect() to.
destinations are in order of preference.
Implements RouteDestination.
|
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.
Reimplemented from RouteDestination.
|
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).
|
private |
|
overridevirtual |
Reimplemented from RouteDestination.
|
inlineoverridevirtual |
Return our routing strategy.
Implements RouteDestination.
|
inlineoverridevirtual |
Trigger listening socket acceptors state handler based on the destination type.
Reimplemented from RouteDestination.
|
private |
Initializes.
This method initialized the object. It goes of the URI query information and sets members accordingly.
|
overrideprivatevirtualnoexcept |
Callback function that is called when state of cluster is changed.
cluster_topology | current cluster topology |
md_servers_reachable | true if metadata changed, false if metadata unavailable |
view_id | current metadata view_id in case of ReplicaSet cluster |
Implements metadata_cache::ClusterStateListenerInterface.
|
private |
|
overrideprivatevirtual |
Callback that is going to be used on each metadata refresh.
[in] | instances_changed | Informs if the cluster topology has changed since last md refresh. |
[in] | cluster_topology | current cluster topology |
Implements metadata_cache::MetadataRefreshListenerInterface.
|
delete |
Copy assignment.
|
delete |
Move assignment.
Destinations DestMetadataCacheGroup::primary_destinations | ( | ) |
|
overridevirtual |
refresh destinations.
should be called after connecting to all destinations failed.
dests | previous destinations. |
Reimplemented from RouteDestination.
|
inline |
|
overridevirtual |
Start the destination.
It also overwrites parent class' RouteDestination::start(), which launches Quarantine. For Metadata Cache routing, we don't need it.
env | pointer to the PluginFuncEnv object |
Reimplemented from RouteDestination.
|
private |
|
private |
|
private |
|
overrideprivatevirtualnoexcept |
Callback function that is called when the state of the sockets acceptors is handled during the metadata refresh.
instances | list of the current cluster nodes |
Implements metadata_cache::AcceptorUpdateHandlerInterface.
|
private |
|
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
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
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_.