MySQL 8.0.40
Source Code Documentation
cluster_metadata_ar.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_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 * @return object containing cluster topology information in case of success,
76 * or error code in case of failure
77 * @throws metadata_cache::metadata_error
78 */
81 const std::atomic<bool> &terminated,
82 mysqlrouter::TargetCluster &target_cluster, const unsigned router_id,
83 const metadata_cache::metadata_servers_list_t &metadata_servers,
84 bool needs_writable_node, const std::string & /*clusterset_id*/,
85 bool /*whole_topology*/, std::size_t &instance_id) override;
86
87 /** @brief Returns cluster type this object is suppsed to handle
88 */
91 }
92
94 const metadata_cache::ClusterTopology & /*cluster_topology*/,
95 const GRNotificationListener::NotificationClb & /*callback*/) override {}
96
97 /** @brief Deinitializes the notifications listener thread
98 */
100
101 private:
102 /** @brief Returns the current cluster topology according to the metadata of
103 * the given metadata server.
104 *
105 * @param session active connection to the member that is checked for the
106 * metadata
107 * @param view_id last known view_id of the cluster metadata
108 * @param cluster_id ID of the cluster this operation refers to
109 * @return vector of the cluster members
110 */
111 metadata_cache::ClusterTopology fetch_topology_from_member(
112 mysqlrouter::MySQLSession &session, unsigned view_id,
113 const std::string &cluster_id = "");
114
115 /** @brief Returns metadata view id the given member holds
116 *
117 * @param session active connection to the member that is checked for the view
118 * id
119 * @param cluster_id ID of the cluster this operation refers to
120 * @param[out] result member's metadata view_id
121 * @retval true on success
122 * @retval false otherwise.
123 */
125 const std::string &cluster_id, uint64_t &result);
126
127 uint64_t view_id_;
128};
129
130#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:127
mysqlrouter::ClusterType get_cluster_type() override
Returns cluster type this object is suppsed to handle.
Definition: cluster_metadata_ar.h:89
void setup_notifications_listener(const metadata_cache::ClusterTopology &, const GRNotificationListener::NotificationClb &) override
Definition: cluster_metadata_ar.h:93
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:99
ARClusterMetadata & operator=(const ARClusterMetadata &)=delete
~ARClusterMetadata() override
Destructor.
The ClusterMetadata class encapsulates a connection to the Metadata server.
Definition: cluster_metadata.h:64
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, bool whole_topology, std::size_t &instance_id)=0
Definition: mysql_session.h:153
Definition: cluster_metadata.h:161
Definition: expected.h:944
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:1095
#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:141
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
Definition: result.h:30