MySQL 8.4.2
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 * @param md_server address of the metadata server to get the data from
131 *
132 * @returns authentication data of the rest users stored in the metadata
133 */
134 auth_credentials_t fetch_auth_credentials(
135 const metadata_cache::metadata_server_t &md_server,
136 const mysqlrouter::TargetCluster &target_cluster) override;
137
138 protected:
139 /** @brief Queries the metadata server for the list of instances that belong
140 * to the desired cluster.
141 */
142 metadata_cache::ClusterTopology fetch_instances_from_metadata_server(
143 const mysqlrouter::TargetCluster &target_cluster,
144 const std::string &cluster_type_specific_id);
145
146 /** Query the GR performance_schema tables for live information about a
147 * cluster.
148 *
149 * update_cluster_status_from_gr() calls check_cluster_status_in_gr() for some
150 * of its processing. Together, they:
151 * - check current topology (status) returned from a cluster node
152 * - update 'instances' with this state
153 * - get other metadata about the cluster
154 *
155 * The information is pulled from GR maintained performance_schema tables.
156 */
157 void update_cluster_status_from_gr(
158 const bool unreachable_quorum_allowed_traffic,
160
161 GRClusterStatus check_cluster_status_in_gr(
162 std::vector<metadata_cache::ManagedInstance *> &instances,
163 const std::map<std::string, GroupReplicationMember> &member_status,
164 bool &metadata_gr_discrepancy) const noexcept;
165
166 void reset_metadata_backend(const mysqlrouter::ClusterType type);
167 std::unique_ptr<GRMetadataBackend> metadata_backend_;
168
169 private:
170 void update_backend(const mysqlrouter::MetadataSchemaVersion &version,
171 unsigned int router_id);
172
173 std::unique_ptr<GRNotificationListener> gr_notifications_listener_;
174
175 friend class GRMetadataBackend;
177};
178
179#endif // METADATA_CACHE_CLUSTER_METADATA_GR_INCLUDED
The ClusterMetadata class encapsulates a connection to the Metadata server.
Definition: cluster_metadata.h:65
auth_credentials_t fetch_auth_credentials(const metadata_cache::metadata_server_t &md_server, const mysqlrouter::TargetCluster &target_cluster) override
Definition: cluster_metadata.cc:373
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
std::unique_ptr< GRNotificationListener > gr_notifications_listener_
Definition: cluster_metadata_gr.h:173
std::unique_ptr< GRMetadataBackend > metadata_backend_
Definition: cluster_metadata_gr.h:167
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:130
Definition: cluster_metadata_gr.cc:70
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
Represents a cluster (a GR group or AR members)
Definition: metadata_cache_datatypes.h:151
Defines an IP address with port number
Definition: tcp_address.h:40
Definition: cluster_metadata.h:159
Definition: expected.h:284
GRClusterStatus
Definition: cluster_metadata_gr.h:37
#define METADATA_CACHE_EXPORT
Definition: metadata_cache_export.h:15
std::vector< metadata_server_t > metadata_servers_list_t
Definition: metadata_cache_datatypes.h:146
ClusterType
Definition: cluster_metadata.h:140
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:183
Metadata MySQL session configuration.
Definition: metadata_cache_datatypes.h:223
Definition: cluster_metadata.h:42
SSL connection related options.
Definition: datatypes.h:39