![]() |
MySQL 9.4.0
Source Code Documentation
|
#include <dest_metadata_cache.h>
Public Types | |
| enum | ServerRole { Primary , Secondary , PrimaryAndSecondary } |
Public Types inherited from DestinationManager | |
| using | DestVector = std::vector< mysql_harness::Destination > |
Public Member Functions | |
| DestMetadataCacheManager (net::io_context &io_ctx, MySQLRoutingContext &routing_ctx, const std::string &metadata_cache, const mysqlrouter::URIQuery &query, const ServerRole role, metadata_cache::MetadataCacheAPIBase *cache_api=metadata_cache::MetadataCacheAPI::instance()) | |
| Constructor. More... | |
| DestMetadataCacheManager (const DestMetadataCacheManager &other)=delete | |
| Copy constructor. More... | |
| DestMetadataCacheManager (DestMetadataCacheManager &&)=delete | |
| Move constructor. More... | |
| DestMetadataCacheManager & | operator= (const DestMetadataCacheManager &)=delete |
| Copy assignment. More... | |
| DestMetadataCacheManager & | operator= (DestMetadataCacheManager &&)=delete |
| Move assignment. More... | |
| ~DestMetadataCacheManager () override | |
| void | start (const mysql_harness::PluginFuncEnv *env) override |
| Start the destination. More... | |
| mysqlrouter::ServerMode | purpose () const override |
| stdx::expected< void, std::error_code > | init_destinations (const routing_guidelines::Session_info &session_info) override |
| Set up destination manager, prepare the destinations. More... | |
| metadata_cache::MetadataCacheAPIBase * | cache_api () |
| bool | refresh_destinations (const routing_guidelines::Session_info &session_info) override |
| refresh destinations. More... | |
| void | handle_sockets_acceptors () override |
| Trigger listening socket acceptors state handler based on the destination type. More... | |
| std::unique_ptr< Destination > | get_next_destination (const routing_guidelines::Session_info &session_info) override |
| Get destination that should be used for connection attempt. More... | |
| std::vector< mysql_harness::Destination > | get_destination_candidates () const override |
| Get addresses of all nodes that are a possible destination candidates. More... | |
| void | connect_status (std::error_code ec) override |
| bool | has_read_write () const override |
| Check if there are read-write destinations that could be used. More... | |
| bool | has_read_only () const override |
| Check if there are read-only destinations that could be used. More... | |
| routing_guidelines::Routing_guidelines_engine::RouteChanges | update_routing_guidelines (const std::string &routing_guidelines_document) |
| Update routing guidelines engine with a new routing guideline. More... | |
| void | clear_internal_state () |
| Clear internal state (indexes, last connection status etc). More... | |
| bool | is_dynamic () override |
| Specifies if the destination addresses can be added/removed from the set. More... | |
| std::string | get_dynamic_plugin_name () override |
Public Member Functions inherited from DestinationManager | |
| DestinationManager (net::io_context &io_ctx, MySQLRoutingContext &routing_ctx) | |
| Default constructor. More... | |
| virtual | ~DestinationManager ()=default |
| Destructor. More... | |
| DestinationManager (const DestinationManager &other)=delete | |
| DestinationManager (DestinationManager &&other)=delete | |
| DestinationManager & | operator= (const DestinationManager &other)=delete |
| DestinationManager & | operator= (DestinationManager &&other)=delete |
| bool | routing_guidelines_session_rand_used () const |
| Check if routing guidelines uses $.session.rand as a match criterion. More... | |
| routing_guidelines::Router_info | get_router_info () const |
| Get information about this given Router instance. More... | |
Public Member Functions inherited from DestinationNodesStateNotifier | |
| virtual | ~DestinationNodesStateNotifier ()=default |
| 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 Types | |
| enum class | ConnectionStatus { InProgress , Failed , NotSet } |
| Status of a last connection. More... | |
Private Member Functions | |
| std::unordered_map< std::string, net::ip::address > | resolve_routing_guidelines_hostnames (const std::vector< routing_guidelines::Resolve_host > &hostnames) |
| Resolve hostnames used in routing guidelines document. More... | |
| void | prepare_destination_groups () |
| Fill each destination group with destination candidates, according to the routing guideline that is being used. More... | |
| bool | change_group () |
| Change destination group that is currently being used. More... | |
| void | validate_current_sharing_settings (std::string_view route_name, Destination *dest) const |
| If the routing guideline enables the connection sharing then it validates if the sharing prerequisites are met and it could be used. More... | |
| std::unique_ptr< Destination > | get_next_destination_impl () |
| void | set_last_connect_successful (const bool state) |
| Set information if the last connection was successful. More... | |
| std::vector< routing_guidelines::Server_info > | get_nodes_allowed_by_routing_guidelines () const |
| Get addresses of nodes allowed by the auto-generated routing guideline. More... | |
| std::vector< routing_guidelines::Server_info > | get_all_nodes () const |
| Get addresses of all nodes in the topology. More... | |
| void | init () |
| Initializes. More... | |
| virtual std::vector< routing_guidelines::Server_info > | get_nodes_from_topology (const metadata_cache::ClusterTopology &cluster_topology, const bool drop_all_hidden) const |
| Get destination candidates details from the given topology. More... | |
| std::vector< routing_guidelines::Server_info > | get_new_connection_nodes () const |
| Get information about nodes available for new connections. More... | |
| std::vector< routing_guidelines::Server_info > | get_old_connection_nodes () const |
| Get information about nodes available for existing connections. More... | |
| std::unique_ptr< Destination > | get_last_used_destination () const override |
| Get a destination candidate that was already selected by the Destination Manager, this will not balance destinations or change the Destination Manager internal state. More... | |
| void | on_instances_change (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 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 () 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) 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... | |
| 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} |
| std::shared_ptr< routing_guidelines::Routing_guidelines_engine > | routing_guidelines_ {nullptr} |
| Routing guideline engine. More... | |
| Protocol::Type | protocol_ |
| Protocol for the destination. More... | |
| routing::RoutingStrategy | strategy_ |
| Routing strategy that is used within the currently used destination group. More... | |
| std::string | last_server_uuid_ |
| UUID of a last destination returned by get_next_destination(), used in wait for primary failover mechanism. More... | |
| routing_guidelines::Routing_guidelines_engine::Route_classification | route_info_ |
| Guidelines route which is designated by the guidelines engine to handle connection. More... | |
| std::vector< std::vector< Destination > > | destination_candidates_ |
| Destination candidates that are going to be used to create destination groups. More... | |
| uint16_t | current_destination_group_index_ {0} |
| Index of the currently used destination group. More... | |
| uint16_t | current_group_position_ {0} |
| Index of the current position within a destination group. More... | |
| std::map< uint16_t, uint16_t > | stored_destination_indexes_ |
| std::atomic< ConnectionStatus > | last_connection_status_ |
| Information about previous connection status. More... | |
| uint16_t | available_dests_in_group_ {0} |
| How many available destinations are in the currently used destination group. More... | |
| bool | has_read_write_ {false} |
| Destination manager contains read-write destination candidates. More... | |
| bool | has_read_only_ {false} |
| Destination manager contains read-only destination candidates. More... | |
| Destination | destination_ |
| Destination thats used for the connection. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from DestinationManager | |
| const MySQLRoutingContext & | get_routing_context () const |
Protected Attributes inherited from DestinationManager | |
| net::io_context & | io_ctx_ |
| MySQLRoutingContext & | routing_ctx_ |
| std::mutex | state_mtx_ |
| std::error_code | last_ec_ |
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_ |
|
strongprivate |
| DestMetadataCacheManager::DestMetadataCacheManager | ( | net::io_context & | io_ctx, |
| MySQLRoutingContext & | routing_ctx, | ||
| const std::string & | metadata_cache, | ||
| const mysqlrouter::URIQuery & | query, | ||
| const ServerRole | role, | ||
| metadata_cache::MetadataCacheAPIBase * | cache_api = metadata_cache::MetadataCacheAPI::instance() |
||
| ) |
Constructor.
|
delete |
Copy constructor.
|
delete |
Move constructor.
|
override |
|
inline |
|
private |
Change destination group that is currently being used.
This happens if there was a connection error and current group could not provide a destination candidate.
| true | successful group change |
| false | unsuccessful group change |
| void DestMetadataCacheManager::clear_internal_state | ( | ) |
Clear internal state (indexes, last connection status etc).
Used when guidelines are updated.
|
overridevirtual |
Implements DestinationManager.
|
private |
Get addresses of all nodes in the topology.
|
overridevirtual |
Get addresses of all nodes that are a possible destination candidates.
Implements DestinationManager.
|
overridevirtual |
Reimplemented from DestinationNodesStateNotifier.
|
inlineoverrideprivatevirtual |
Get a destination candidate that was already selected by the Destination Manager, this will not balance destinations or change the Destination Manager internal state.
Implements DestinationManager.
|
private |
Get information about nodes available for new connections.
|
overridevirtual |
Get destination that should be used for connection attempt.
It uses routing strategies and internal information (last used indexes, failed attempt information) for destination selection.
Implements DestinationManager.
|
private |
|
private |
Get addresses of nodes allowed by the auto-generated routing guideline.
Should not be called when user-provided guideline is used as in such case it might be impossible to determine the list upfront (matching criteria might depend on source IP info for example).
|
privatevirtual |
Get destination candidates details from the given topology.
| cluster_topology | topology of the cluster |
| drop_all_hidden | shoud the hidden nodes be included in the result |
|
private |
Get information about nodes available for existing connections.
|
inlineoverridevirtual |
Trigger listening socket acceptors state handler based on the destination type.
Implements DestinationManager.
|
inlineoverridevirtual |
Check if there are read-only destinations that could be used.
Implements DestinationManager.
|
inlineoverridevirtual |
Check if there are read-write destinations that could be used.
Implements DestinationManager.
|
private |
Initializes.
This method initialized the object. It goes of the URI query information and sets members accordingly.
|
overridevirtual |
Set up destination manager, prepare the destinations.
Implements DestinationManager.
|
inlineoverridevirtual |
Specifies if the destination addresses can be added/removed from the set.
NOTE: the sequence of nodes may change.
Reimplemented from DestinationNodesStateNotifier.
|
overrideprivatevirtualnoexcept |
Callback function that is called when state of cluster is changed.
| 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. |
Implements metadata_cache::MetadataRefreshListenerInterface.
|
delete |
Copy assignment.
|
delete |
Move assignment.
|
private |
Fill each destination group with destination candidates, according to the routing guideline that is being used.
For example given the group setting [[d1,d2], [d3]] and d1 containing 127.0.0.1 d2 containing 127.0.1.1 127.0.1.2 d3 containing 127.0.2.1 It will create two destination groups 1) [127.0.0.1, 127.0.1.1, 127.0.1.2] 2) [127.0.2.1] Where group 2) is a backup destination group.
|
inlineoverridevirtual |
Reimplemented from DestinationManager.
|
overridevirtual |
refresh destinations.
should be called after connecting to all destinations failed.
| true | refresh suceeded, there are destinations that could be used. |
| false | refresh failed, there are no destinations that could be used. |
Implements DestinationManager.
|
private |
Resolve hostnames used in routing guidelines document.
If hostname could be resolved to multiple addresses (with requested IP version) then only one of the addresses is used, with unspecified order.
| hostnames | list of hostnames to be resolved, each host contain information about hostname and IP version which should be used. |
|
private |
Set information if the last connection was successful.
|
overridevirtual |
Start the destination.
It also overwrites parent class' DestinationManager::start(), which launches Quarantine. For Metadata Cache routing, we don't need it.
| env | pointer to the PluginFuncEnv object |
Implements DestinationManager.
|
private |
|
private |
|
private |
| routing_guidelines::Routing_guidelines_engine::RouteChanges DestMetadataCacheManager::update_routing_guidelines | ( | const std::string & | routing_guidelines_document | ) |
Update routing guidelines engine with a new routing guideline.
If the new routing guideline is empty then auto-generated guideline is used. If the guidelines engine could not be updated then old guideline is preserved and used.
|
overrideprivatevirtualnoexcept |
Callback function that is called when the state of the sockets acceptors is handled during the metadata refresh.
Implements metadata_cache::AcceptorUpdateHandlerInterface.
|
private |
If the routing guideline enables the connection sharing then it validates if the sharing prerequisites are met and it could be used.
If not then connection sharing is disabled.
| route_name | name of the route that enables connection sharing |
| dest | destination candidate that is going to be used for connection. |
|
private |
How many available destinations are in the currently used destination group.
|
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 |
Index of the currently used destination group.
|
private |
Index of the current position within a destination group.
|
private |
Destination thats used for the connection.
|
private |
Destination candidates that are going to be used to create destination groups.
|
private |
|
private |
|
private |
Destination manager contains read-only destination candidates.
|
private |
Destination manager contains read-write destination candidates.
|
private |
Information about previous connection status.
|
private |
UUID of a last destination returned by get_next_destination(), used in wait for primary failover mechanism.
|
private |
Protocol for the destination.
|
private |
Guidelines route which is designated by the guidelines engine to handle connection.
|
private |
Routing guideline engine.
|
private |
|
private |
|
private |
Routing strategy that is used within the currently used destination group.
|
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_.