MySQL 8.0.37
Source Code Documentation
cluster_metadata_gr.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef METADATA_CACHE_CLUSTER_METADATA_GR_INCLUDED
27#define METADATA_CACHE_CLUSTER_METADATA_GR_INCLUDED
28
30
31#include "cluster_metadata.h"
33
36
37enum class GRClusterStatus {
42};
43
45 public:
46 /** @brief Constructor
47 *
48 * @param session_config Metadata MySQL session configuration
49 * @param ssl_options SSL related options to use for MySQL connections
50 * @param use_cluster_notifications Flag indicating if the metadata cache
51 * should use cluster notifications as an additional trigger for metadata
52 * refresh
53 */
56 const mysqlrouter::SSLOptions &ssl_options,
57 const bool use_cluster_notifications = false);
58
59 explicit GRClusterMetadata(const GRClusterMetadata &) = delete;
61
62 /** @brief Destructor
63 *
64 * Disconnect and release the connection to the metadata node.
65 */
67
68 /** @brief Returns cluster defined in the metadata given set of the
69 * metadata servers (cluster members)
70 *
71 * @param terminated flag indicating that the process is cterminating,
72 * allowing the function to leave earlier if possible
73 * @param [in,out] target_cluster object identifying the Cluster this
74 * operation refers to
75 * @param router_id id of the router in the cluster metadata
76 * @param metadata_servers set of the metadata servers to use to fetch the
77 * metadata
78 * @param needs_writable_node flag indicating if the caller needs us to query
79 * for writable node
80 * @param clusterset_id UUID of the ClusterSet the Cluster belongs to (if
81 * bootstrapped as a ClusterSet)
82 * @param whole_topology return all usable nodes, ignore potential metadata
83 * filters or policies (like target_cluster etc.)
84 * @param [out] instance_id of the server the metadata was fetched from
85 * @return object containing cluster topology information in case of success,
86 * or error code in case of failure
87 * @throws metadata_cache::metadata_error
88 */
91 const std::atomic<bool> &terminated,
92 mysqlrouter::TargetCluster &target_cluster, const unsigned router_id,
93 const metadata_cache::metadata_servers_list_t &metadata_servers,
94 bool needs_writable_node, const std::string &clusterset_id,
95 bool whole_topology, std::size_t &instance_id) override;
96
97 /** @brief Initializes the notifications listener thread (if a given cluster
98 * type supports it)
99 *
100 * @param cluster_topology current topology of the monitored Cluster(s)
101 * to
102 * @param callback callback function to get called when the GR notification
103 * was received
104 */
106 const metadata_cache::ClusterTopology &cluster_topology,
107 const GRNotificationListener::NotificationClb &callback) override {
108 if (gr_notifications_listener_)
109 gr_notifications_listener_->setup(cluster_topology, callback);
110 }
111
112 /** @brief Deinitializes the notifications listener thread
113 */
115 gr_notifications_listener_.reset();
116 }
117
118 /** @brief Returns cluster type this object is suppsed to handle
119 */
121
122 /** @brief Get authentication data of the rest users from the metadata.
123 *
124 * Authentication data is stored in the router_rest_accounts table. This
125 * method fetches the following information: username, password hash,
126 * privileges and name of the authentication mechanism that should be used.
127 *
128 * @param target_cluster information about the Cluster that this information
129 * is retrieved for
130 *
131 * @returns authentication data of the rest users stored in the metadata
132 */
133 auth_credentials_t fetch_auth_credentials(
134 const mysqlrouter::TargetCluster &target_cluster) override;
135
136 std::optional<std::chrono::seconds>
137 get_periodic_stats_update_frequency() noexcept override;
138
139 protected:
140 /** @brief Queries the metadata server for the list of instances that belong
141 * to the desired cluster.
142 */
143 metadata_cache::ClusterTopology fetch_instances_from_metadata_server(
144 const mysqlrouter::TargetCluster &target_cluster,
145 const std::string &cluster_type_specific_id);
146
147 /** Query the GR performance_schema tables for live information about a
148 * cluster.
149 *
150 * update_cluster_status() calls check_cluster_status() for some of its
151 * processing. Together, they:
152 * - check current topology (status) returned from a cluster node
153 * - update 'instances' with this state
154 * - get other metadata about the cluster
155 *
156 * The information is pulled from GR maintained performance_schema tables.
157 */
158 void update_cluster_status(metadata_cache::ManagedCluster &cluster);
159
160 GRClusterStatus check_cluster_status(
161 std::vector<metadata_cache::ManagedInstance> &instances,
162 const std::map<std::string, GroupReplicationMember> &member_status,
163 bool &metadata_gr_discrepancy) const noexcept;
164
165 void reset_metadata_backend(const mysqlrouter::ClusterType type);
166 std::unique_ptr<GRMetadataBackend> metadata_backend_;
167
168 private:
169 void update_backend(const mysqlrouter::MetadataSchemaVersion &version,
170 unsigned int router_id);
171
172 std::unique_ptr<GRNotificationListener> gr_notifications_listener_;
173
174 friend class GRMetadataBackend;
176};
177
178#endif // METADATA_CACHE_CLUSTER_METADATA_GR_INCLUDED
The ClusterMetadata class encapsulates a connection to the Metadata server.
Definition: cluster_metadata.h:64
auth_credentials_t fetch_auth_credentials(const mysqlrouter::TargetCluster &target_cluster) override
Definition: cluster_metadata.cc:472
std::optional< std::chrono::seconds > get_periodic_stats_update_frequency() noexcept override
Definition: cluster_metadata.h:131
Definition: cluster_metadata_gr.h:44
~GRClusterMetadata() override
Destructor.
void shutdown_notifications_listener() override
Deinitializes the notifications listener thread.
Definition: cluster_metadata_gr.h:114
GRClusterMetadata & operator=(const GRClusterMetadata &)=delete
void setup_notifications_listener(const metadata_cache::ClusterTopology &cluster_topology, const GRNotificationListener::NotificationClb &callback) override
Initializes the notifications listener thread (if a given cluster type supports it)
Definition: cluster_metadata_gr.h:105
GRClusterMetadata(const GRClusterMetadata &)=delete
Definition: cluster_metadata_gr.cc:162
Definition: cluster_metadata_gr.cc:67
Definition: gr_notifications_listener.h:35
std::function< void()> NotificationClb
Definition: gr_notifications_listener.h:43
virtual mysqlrouter::ClusterType get_cluster_type()=0
virtual stdx::expected< metadata_cache::ClusterTopology, std::error_code > fetch_cluster_topology(const std::atomic< bool > &terminated, mysqlrouter::TargetCluster &target_cluster, const unsigned router_id, const metadata_cache::metadata_servers_list_t &metadata_servers, bool needs_writable_node, const std::string &clusterset_id, bool whole_topology, std::size_t &instance_id)=0
Definition: cluster_metadata.h:161
Definition: expected.h:944
GRClusterStatus
Definition: cluster_metadata_gr.h:37
#define METADATA_CACHE_EXPORT
Definition: metadata_cache_export.h:15
Definition: metadata_cache.h:53
std::vector< metadata_server_t > metadata_servers_list_t
Definition: metadata_cache_datatypes.h:146
Definition: dim.h:358
ClusterType
Definition: cluster_metadata.h:141
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2892
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2438
required uint64 version
Definition: replication_group_member_actions.proto:41
required string type
Definition: replication_group_member_actions.proto:34
Definition: group_replication_metadata.h:38
Represents a cluster (a GR group or AR members) and its metadata servers.
Definition: metadata_cache_datatypes.h:181
Metadata MySQL session configuration.
Definition: metadata_cache_datatypes.h:221
SSL connection related options.
Definition: datatypes.h:39