MySQL 9.1.0
Source Code Documentation
|
The MetadataCache manages cached information fetched from the MySQL Server. More...
#include <metadata_cache.h>
Classes | |
struct | RestAuthData |
struct | Stats |
Public Member Functions | |
MetadataCache (const unsigned router_id, const std::string &clusterset_id, const std::vector< mysql_harness::TCPAddress > &metadata_servers, std::shared_ptr< MetaData > cluster_metadata, const metadata_cache::MetadataCacheTTLConfig &ttl_config, const mysqlrouter::SSLOptions &ssl_options, const mysqlrouter::TargetCluster &target_cluster, const metadata_cache::RouterAttributes &router_attributes, size_t thread_stack_size=mysql_harness::kDefaultStackSizeInKiloBytes, bool use_cluster_notifications=false) | |
Initialize a connection to the MySQL Metadata server. More... | |
~MetadataCache () override | |
void | start () |
Starts the Metadata Cache. More... | |
void | stop () noexcept |
Stops the Metadata Cache. More... | |
metadata_cache::cluster_nodes_list_t | get_cluster_nodes () |
Returns list of managed servers in a cluster. More... | |
metadata_cache::ClusterTopology | get_cluster_topology () |
Returns object containing current Cluster Topology. More... | |
bool | wait_primary_failover (const std::string &server_uuid, const std::chrono::seconds &timeout) |
Wait until cluster PRIMARY changes. More... | |
void | refresh_thread () |
refresh cluster information More... | |
void | add_state_listener (metadata_cache::ClusterStateListenerInterface *listener) override |
Register observer that is notified when there is a change in the cluster nodes setup/state discovered. More... | |
void | remove_state_listener (metadata_cache::ClusterStateListenerInterface *listener) override |
Unregister observer previously registered with add_state_listener() More... | |
void | add_acceptor_handler_listener (metadata_cache::AcceptorUpdateHandlerInterface *listener) |
Register observer that is notified when the state of listening socket acceptors should be updated on the next metadata refresh. More... | |
void | remove_acceptor_handler_listener (metadata_cache::AcceptorUpdateHandlerInterface *listener) |
Unregister observer previously registered with add_acceptor_handler_listener() More... | |
void | add_md_refresh_listener (metadata_cache::MetadataRefreshListenerInterface *listener) |
Register observer that is notified on each metadata refresh event. More... | |
void | remove_md_refresh_listener (metadata_cache::MetadataRefreshListenerInterface *listener) |
Unregister observer previously registered with add_md_refresh_listener() More... | |
metadata_cache::MetadataCacheAPIBase::RefreshStatus | refresh_status () |
std::chrono::milliseconds | ttl () const |
mysqlrouter::TargetCluster | target_cluster () const |
virtual mysqlrouter::ClusterType | cluster_type () const noexcept=0 |
std::vector< mysql_harness::TCPAddress > | metadata_servers () |
void | enable_fetch_auth_metadata () |
void | force_cache_update () |
void | check_auth_metadata_timers () const |
std::pair< bool, MetaData::auth_credentials_t::mapped_type > | get_rest_user_auth_data (const std::string &user) |
void | handle_sockets_acceptors_on_md_refresh () |
Toggle socket acceptors state update on next metadata refresh. More... | |
bool | fetch_whole_topology () const |
void | fetch_whole_topology (bool val) |
Public Member Functions inherited from metadata_cache::ClusterStateNotifierInterface | |
ClusterStateNotifierInterface ()=default | |
ClusterStateNotifierInterface (const ClusterStateNotifierInterface &)=delete | |
ClusterStateNotifierInterface & | operator= (const ClusterStateNotifierInterface &)=delete |
virtual | ~ClusterStateNotifierInterface () |
Static Public Member Functions | |
static void * | run_thread (void *context) |
run refresh thread More... | |
Protected Member Functions | |
virtual bool | refresh (bool needs_writable_node)=0 |
Refreshes the cache. More... | |
void | on_refresh_failed (bool terminated, bool md_servers_reachable=false) |
void | on_refresh_succeeded (const metadata_cache::metadata_server_t &metadata_server) |
void | on_instances_changed (const bool md_servers_reachable, const metadata_cache::ClusterTopology &cluster_topology, uint64_t view_id=0) |
void | on_handle_sockets_acceptors () |
Called when the listening sockets acceptors state should be updated but replicaset instances has not changed (in that case socket acceptors would be handled when calling on_instances_changed). More... | |
void | on_md_refresh (const bool cluster_nodes_changed, const metadata_cache::ClusterTopology &cluster_topology) |
Called on each metadata refresh. More... | |
void | on_refresh_requested () |
void | on_refresh_completed () |
bool | update_auth_cache () |
void | update_router_attributes () |
void | update_router_last_check_in () |
bool | needs_initial_attributes_update () |
bool | needs_last_check_in_update () |
The MetadataCache manages cached information fetched from the MySQL Server.
MetadataCache::MetadataCache | ( | const unsigned | router_id, |
const std::string & | clusterset_id, | ||
const std::vector< mysql_harness::TCPAddress > & | metadata_servers, | ||
std::shared_ptr< MetaData > | cluster_metadata, | ||
const metadata_cache::MetadataCacheTTLConfig & | ttl_config, | ||
const mysqlrouter::SSLOptions & | ssl_options, | ||
const mysqlrouter::TargetCluster & | target_cluster, | ||
const metadata_cache::RouterAttributes & | router_attributes, | ||
size_t | thread_stack_size = mysql_harness::kDefaultStackSizeInKiloBytes , |
||
bool | use_cluster_notifications = false |
||
) |
Initialize a connection to the MySQL Metadata server.
router_id | id of the router in the cluster metadata |
clusterset_id | UUID of the ClusterSet the Cluster belongs to (if bootstrapped as a ClusterSet, empty otherwise) |
metadata_servers | The servers that store the metadata |
cluster_metadata | metadata of the cluster |
ttl_config | metadata TTL configuration |
ssl_options | SSL related options for connection |
target_cluster | object identifying the Cluster this operation refers to |
router_attributes | Router attributes to be registered in the metadata |
thread_stack_size | The maximum memory allocated for thread's stack |
use_cluster_notifications | Flag indicating if the metadata cache should use GR notifications as an additional trigger for metadata refresh |
|
override |
void MetadataCache::add_acceptor_handler_listener | ( | metadata_cache::AcceptorUpdateHandlerInterface * | listener | ) |
Register observer that is notified when the state of listening socket acceptors should be updated on the next metadata refresh.
listener | Observer object that is notified when replicaset nodes state is changed. |
void MetadataCache::add_md_refresh_listener | ( | metadata_cache::MetadataRefreshListenerInterface * | listener | ) |
Register observer that is notified on each metadata refresh event.
listener | Observer object that is notified on md refresh. |
|
overridevirtual |
Register observer that is notified when there is a change in the cluster nodes setup/state discovered.
listener | Observer object that is notified when cluster nodes state is changed. |
Implements metadata_cache::ClusterStateNotifierInterface.
void MetadataCache::check_auth_metadata_timers | ( | ) | const |
|
pure virtualnoexcept |
Implemented in ARMetadataCache, and GRMetadataCache.
|
inline |
|
inline |
void MetadataCache::fetch_whole_topology | ( | bool | val | ) |
|
inline |
metadata_cache::cluster_nodes_list_t MetadataCache::get_cluster_nodes | ( | ) |
Returns list of managed servers in a cluster.
Return a list of servers that are part of a cluster.
metadata_cache::ClusterTopology MetadataCache::get_cluster_topology | ( | ) |
Returns object containing current Cluster Topology.
std::pair< bool, MetaData::auth_credentials_t::mapped_type > MetadataCache::get_rest_user_auth_data | ( | const std::string & | user | ) |
|
inline |
Toggle socket acceptors state update on next metadata refresh.
std::vector< mysql_harness::TCPAddress > MetadataCache::metadata_servers | ( | ) |
|
protected |
|
protected |
|
protected |
Called when the listening sockets acceptors state should be updated but replicaset instances has not changed (in that case socket acceptors would be handled when calling on_instances_changed).
|
protected |
|
protected |
Called on each metadata refresh.
[in] | cluster_nodes_changed | Information whether there was a change in instances reported by metadata refresh. |
[in] | cluster_topology | current cluster topology |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedpure virtual |
Refreshes the cache.
Implemented in ARMetadataCache, and GRMetadataCache.
|
inline |
void MetadataCache::refresh_thread | ( | ) |
refresh cluster information
void MetadataCache::remove_acceptor_handler_listener | ( | metadata_cache::AcceptorUpdateHandlerInterface * | listener | ) |
Unregister observer previously registered with add_acceptor_handler_listener()
listener | Observer object that should be unregistered. |
void MetadataCache::remove_md_refresh_listener | ( | metadata_cache::MetadataRefreshListenerInterface * | listener | ) |
Unregister observer previously registered with add_md_refresh_listener()
listener | Observer object that should be unregistered. |
|
overridevirtual |
Unregister observer previously registered with add_state_listener()
listener | Observer object that should be unregistered. |
Implements metadata_cache::ClusterStateNotifierInterface.
|
static |
run refresh thread
void MetadataCache::start | ( | ) |
Starts the Metadata Cache.
Connect to the metadata servers and refresh the metadata information in the cache.
Starts the Metadata Cache and launch thread.
|
noexcept |
Stops the Metadata Cache.
Stop the refresh thread.
Stops the Metadata Cache and the launch thread.
|
inline |
|
inline |
|
protected |
|
protected |
|
protected |
bool MetadataCache::wait_primary_failover | ( | const std::string & | server_uuid, |
const std::chrono::seconds & | timeout | ||
) |
Wait until cluster PRIMARY changes.
wait until a change of the PRIMARY is noticed
leave early if
function has to handle two scenarios:
connection to PRIMARY fails because:
Therefore, if the connection to PRIMARY fails, wait for change of the membership or timeout, whatever happens earlier.
server_uuid | server-uuid of the PRIMARY that we failed to connect |
timeout | - amount of time to wait for a failover |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
notification thread facade
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
refresh thread facade
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Flag indicating if socket acceptors state should be updated on next metadata refresh even if instance information has not changed.
|
protected |
|
protected |