MySQL 9.3.0
Source Code Documentation
cluster_metadata_ar.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2025, 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_AR_INCLUDED
27#define METADATA_CACHE_CLUSTER_METADATA_AR_INCLUDED
28
30
31#include "cluster_metadata.h"
33
34/** @class ARClusterMetadata
35 *
36 * The `ARClusterMetadata` class encapsulates a connection to the ReplicaSet
37 * Cluster metadata server.
38 *
39 */
41 public:
42 /** @brief Constructor
43 *
44 * @param session_config Metadata MySQL session configuration
45 * @param ssl_options SSL related options to use for MySQL connections
46 * @param view_id last known view_id of the cluster metadata
47 */
50 const mysqlrouter::SSLOptions &ssl_options, uint64_t view_id)
51 : ClusterMetadata(session_config, ssl_options), view_id_(view_id) {}
52
53 explicit ARClusterMetadata(const ARClusterMetadata &) = delete;
55
56 /** @brief Destructor
57 *
58 * Disconnect and release the connection to the metadata node.
59 */
61
62 /** @brief Returns cluster defined in the metadata given set of the
63 * metadata servers (cluster members)
64 *
65 * @param terminated flag indicating that the process is cterminating,
66 * allowing the function to leave earlier if possible
67 * @param [in,out] target_cluster object identifying the Cluster this
68 * operation refers to
69 * @param router_id id of the router in the cluster metadata
70 * @param metadata_servers set of the metadata servers to use to fetch the
71 * metadata
72 * @param needs_writable_node flag indicating if the caller needs us to query
73 * for writable node
74 * @param [out] instance_id id of the server the metadata was fetched from
75 * @param routing_guidelines Routing Guidelines document
76 * @return object containing cluster topology information in case of success,
77 * or error code in case of failure
78 * @throws metadata_cache::metadata_error If fetching metadata fails.
79 */
82 const std::atomic<bool> &terminated,
83 mysqlrouter::TargetCluster &target_cluster, const unsigned router_id,
84 const metadata_cache::metadata_servers_list_t &metadata_servers,
85 bool needs_writable_node, const std::string & /*clusterset_id*/,
86 std::size_t &instance_id, std::string &routing_guidelines) override;
87
88 /** @brief Returns cluster type this object is suppsed to handle
89 */
92 }
93
95 const metadata_cache::ClusterTopology & /*cluster_topology*/,
96 const GRNotificationListener::NotificationClb & /*callback*/) override {}
97
98 /** @brief Deinitializes the notifications listener thread
99 */
101
102 private:
103 /** @brief Returns the current cluster topology according to the metadata of
104 * the given metadata server.
105 *
106 * @param session active connection to the member that is checked for the
107 * metadata
108 * @param view_id last known view_id of the cluster metadata
109 * @param cluster_id ID of the cluster this operation refers to
110 * @return vector of the cluster members
111 */
112 metadata_cache::ClusterTopology fetch_topology_from_member(
113 mysqlrouter::MySQLSession &session, unsigned view_id,
114 const std::string &cluster_id = "");
115
116 /** @brief Returns metadata view id the given member holds
117 *
118 * @param session active connection to the member that is checked for the view
119 * id
120 * @param cluster_id ID of the cluster this operation refers to
121 * @param[out] result member's metadata view_id
122 * @retval true on success
123 * @retval false otherwise.
124 */
126 const std::string &cluster_id, uint64_t &result);
127
128 uint64_t view_id_;
129};
130
131#endif // METADATA_CACHE_CLUSTER_METADATA_AR_INCLUDED
The ARClusterMetadata class encapsulates a connection to the ReplicaSet Cluster metadata server.
Definition: cluster_metadata_ar.h:40
ARClusterMetadata(const ARClusterMetadata &)=delete
uint64_t view_id_
Definition: cluster_metadata_ar.h:128
mysqlrouter::ClusterType get_cluster_type() override
Returns cluster type this object is suppsed to handle.
Definition: cluster_metadata_ar.h:90
void setup_notifications_listener(const metadata_cache::ClusterTopology &, const GRNotificationListener::NotificationClb &) override
Definition: cluster_metadata_ar.h:94
ARClusterMetadata(const metadata_cache::MetadataCacheMySQLSessionConfig &session_config, const mysqlrouter::SSLOptions &ssl_options, uint64_t view_id)
Constructor.
Definition: cluster_metadata_ar.h:48
void shutdown_notifications_listener() override
Deinitializes the notifications listener thread.
Definition: cluster_metadata_ar.h:100
ARClusterMetadata & operator=(const ARClusterMetadata &)=delete
~ARClusterMetadata() override
Destructor.
The ClusterMetadata class encapsulates a connection to the Metadata server.
Definition: cluster_metadata.h:66
std::function< void()> NotificationClb
Definition: gr_notifications_listener.h:43
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, std::size_t &instance_id, std::string &routing_guidelines)=0
Definition: mysql_session.h:157
Definition: cluster_metadata.h:173
Definition: expected.h:286
static stdx::expected< uint64_t, std::error_code > get_member_view_id(mysqlrouter::MySQLSession &session, const std::string &clusterset_id)
Definition: cluster_metadata_gr.cc:1112
#define METADATA_CACHE_EXPORT
Definition: metadata_cache_export.h:15
std::vector< metadata_server_t > metadata_servers_list_t
Definition: metadata_cache_datatypes.h:169
ClusterType
Definition: cluster_metadata.h:154
Definition: routing_guidelines_datatypes.h:31
Represents a cluster (a GR group or AR members) and its metadata servers.
Definition: metadata_cache_datatypes.h:208
Metadata MySQL session configuration.
Definition: metadata_cache_datatypes.h:248
SSL connection related options.
Definition: datatypes.h:34
Definition: result.h:30