MySQL 8.4.5
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
cluster_metadata.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 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 MYSQLROUTER_CLUSTER_METADATA_INCLUDED
27#define MYSQLROUTER_CLUSTER_METADATA_INCLUDED
28
30
31#include <chrono>
32#include <optional>
33#include <stdexcept>
34#include <string>
35
37
38namespace mysqlrouter {
39
40class MySQLSession;
41
43 unsigned int major;
44 unsigned int minor;
45 unsigned int patch;
46
47 bool operator<(const MetadataSchemaVersion &o) const {
48 if (major == o.major) {
49 if (minor == o.minor) {
50 return patch < o.patch;
51 } else {
52 return minor < o.minor;
53 }
54 } else {
55 return major < o.major;
56 }
57 }
58
59 bool operator<=(const MetadataSchemaVersion &o) const {
60 return operator<(o) || operator==(o);
61 }
62
63 bool operator>(const MetadataSchemaVersion &o) const {
64 return operator!=(o) && !operator<(o);
65 }
66
67 bool operator>=(const MetadataSchemaVersion &o) const {
68 return operator>(o) || operator==(o);
69 }
70
71 bool operator==(const MetadataSchemaVersion &o) const {
72 return major == o.major && minor == o.minor && patch == o.patch;
73 }
74
75 bool operator!=(const MetadataSchemaVersion &o) const {
76 return !operator==(o);
77 }
78};
79
80std::string ROUTER_CLUSTER_EXPORT
81to_string(const MetadataSchemaVersion &version);
82
83// Semantic version numbers that this Router version supports for bootstrap mode
85
86// Semantic version number that this Router version supports for routing mode
88 {2, 0, 0}};
89
90// Version that introduced views and support for ReplicaSet cluster type
92
93// Version that introduced support for ClusterSets
95
96// Version that will be is set while the metadata is being updated
98
99MetadataSchemaVersion ROUTER_CLUSTER_EXPORT
101
104 const mysqlrouter::MetadataSchemaVersion &available);
105
108
109// throws std::logic_error, MySQLSession::Error
111
112// throws MySQLSession::Error, std::logic_error, std::out_of_range
114
116
117std::string ROUTER_CLUSTER_EXPORT
119
120template <size_t N>
122 const mysqlrouter::MetadataSchemaVersion (&required)[N],
123 const mysqlrouter::MetadataSchemaVersion &available) {
124 for (size_t i = 0; i < N; ++i) {
126 return true;
127 }
128
129 return false;
130}
131
132template <size_t N>
134 std::string result;
135 for (size_t i = 0; i < N; ++i) {
136 result += to_string(version[i]);
137 if (i != N - 1) {
138 result += ", ";
139 }
140 }
141
142 return result;
143}
144
145enum class ClusterType {
146 GR_V2, /* based on Group Replication (metadata 2.x) */
147 GR_CS, /* based on Group Replication, part of ClusterSet (metadata 2.1+) */
148 RS_V2 /* ReplicaSet (metadata 2.x) */
149};
150
152get_cluster_type(const MetadataSchemaVersion &schema_version,
153 MySQLSession *mysql, unsigned int router_id = 0);
154
155std::string ROUTER_CLUSTER_EXPORT to_string(const ClusterType cluster_type);
156
157class MetadataUpgradeInProgressException : public std::exception {};
158
161
163
165 public:
168
170 const std::string &value = "")
171 : target_type_(type), target_value_(value) {
173 }
174
175 std::string to_string() const { return target_value_; }
176 const char *c_str() const { return target_value_.c_str(); }
177
181 }
182
183 void target_type(const TargetType value) { target_type_ = value; }
184 void target_value(const std::string &value) { target_value_ = value; }
188 }
189
190 private:
192 std::string target_value_;
195};
196
197constexpr const std::string_view kNodeTagHidden{"_hidden"};
198constexpr const std::string_view kNodeTagDisconnectWhenHidden{
199 "_disconnect_existing_sessions_when_hidden"};
200
201constexpr const bool kNodeTagHiddenDefault{false};
202constexpr const bool kNodeTagDisconnectWhenHiddenDefault{true};
203
205
206std::optional<InstanceType> ROUTER_CLUSTER_EXPORT
207str_to_instance_type(const std::string &);
208
210std::string ROUTER_CLUSTER_EXPORT
212
213constexpr const std::chrono::milliseconds kDefaultMetadataTTLCluster{500};
214constexpr const std::chrono::milliseconds
216 std::chrono::milliseconds(60 * 1000);
217constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterSet{
218 5000}; // default TTL for ClusterSet is 5 seconds regardless if GR
219 // Notifications are used or not
222
223} // namespace mysqlrouter
224#endif
Definition: cluster_metadata.h:157
Definition: mysql_session.h:153
Definition: cluster_metadata.h:164
void invalidated_cluster_routing_policy(const InvalidatedClusterRoutingPolicy value)
Definition: cluster_metadata.h:185
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy() const
Definition: cluster_metadata.h:179
void target_value(const std::string &value)
Definition: cluster_metadata.h:184
TargetCluster(const TargetType type=TargetType::ByPrimaryRole, const std::string &value="")
Definition: cluster_metadata.h:169
TargetType
Definition: cluster_metadata.h:166
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:167
void target_type(const TargetType value)
Definition: cluster_metadata.h:183
std::string target_value_
Definition: cluster_metadata.h:192
TargetType target_type_
Definition: cluster_metadata.h:191
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy_
Definition: cluster_metadata.h:193
std::string to_string() const
Definition: cluster_metadata.h:175
const char * c_str() const
Definition: cluster_metadata.h:176
TargetType target_type() const
Definition: cluster_metadata.h:178
Definition: expected.h:286
std::atomic< Type > N
Definition: ut0counter.h:225
Definition: instrumented_condition_variable.h:32
Definition: base64.h:43
constexpr MetadataSchemaVersion kClusterSetsMetadataVersion
Definition: cluster_metadata.h:94
constexpr MetadataSchemaVersion kNewMetadataVersion
Definition: cluster_metadata.h:91
bool ROUTER_CLUSTER_EXPORT is_part_of_cluster_set(MySQLSession *mysql)
Definition: cluster_metadata.cc:1082
ClusterType
Definition: cluster_metadata.h:145
InstanceType
Definition: cluster_metadata.h:204
std::string ROUTER_CLUSTER_EXPORT get_unsupported_server_version_msg(MySQLSession *mysql)
Definition: cluster_metadata.cc:1329
constexpr MetadataSchemaVersion kUpgradeInProgressMetadataVersion
Definition: cluster_metadata.h:97
constexpr MetadataSchemaVersion kRequiredRoutingMetadataSchemaVersion[]
Definition: cluster_metadata.h:87
constexpr const std::string_view kNodeTagDisconnectWhenHidden
Definition: cluster_metadata.h:198
bool ROUTER_CLUSTER_EXPORT is_server_version_supported(MySQLSession *mysql)
Definition: cluster_metadata.cc:1325
constexpr const std::string_view kNodeTagHidden
Definition: cluster_metadata.h:197
MetadataSchemaVersion ROUTER_CLUSTER_EXPORT get_metadata_schema_version(MySQLSession *mysql)
Definition: cluster_metadata.cc:423
std::string ROUTER_CLUSTER_EXPORT get_metadata_schema_uncompatible_msg(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:409
stdx::expected< void, std::string > ROUTER_CLUSTER_EXPORT setup_metadata_session(MySQLSession &session)
Definition: cluster_metadata.cc:1255
bool ROUTER_CLUSTER_EXPORT check_group_has_quorum(MySQLSession *mysql)
Definition: cluster_metadata.cc:490
constexpr MetadataSchemaVersion kRequiredBootstrapSchemaVersion[]
Definition: cluster_metadata.h:84
constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterGRNotificationsON
Definition: cluster_metadata.h:215
ClusterType ROUTER_CLUSTER_EXPORT get_cluster_type(const MetadataSchemaVersion &schema_version, MySQLSession *mysql, unsigned int router_id=0)
Definition: cluster_metadata.cc:1123
constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterSet
Definition: cluster_metadata.h:217
const bool kDefaultUseGRNotificationsClusterSet
Definition: cluster_metadata.h:221
bool ROUTER_CLUSTER_EXPORT check_group_replication_online(MySQLSession *mysql)
Definition: cluster_metadata.cc:474
bool ROUTER_CLUSTER_EXPORT metadata_schema_version_is_compatible(const mysqlrouter::MetadataSchemaVersion &required, const mysqlrouter::MetadataSchemaVersion &available)
Definition: cluster_metadata.cc:395
constexpr const std::chrono::milliseconds kDefaultMetadataTTLCluster
Definition: cluster_metadata.h:213
constexpr const bool kNodeTagDisconnectWhenHiddenDefault
Definition: cluster_metadata.h:202
constexpr const bool kNodeTagHiddenDefault
Definition: cluster_metadata.h:201
std::optional< InstanceType > ROUTER_CLUSTER_EXPORT str_to_instance_type(const std::string &)
Definition: cluster_metadata.cc:1283
std::string ROUTER_CLUSTER_EXPORT to_string(const MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:418
const bool kDefaultUseGRNotificationsCluster
Definition: cluster_metadata.h:220
struct result result
Definition: result.h:34
required uint64 version
Definition: replication_group_member_actions.proto:41
required string type
Definition: replication_group_member_actions.proto:34
#define ROUTER_CLUSTER_EXPORT
Definition: router_cluster_export.h:15
Definition: cluster_metadata.h:42
bool operator<(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:47
bool operator>(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:63
bool operator==(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:71
bool operator>=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:67
unsigned int minor
Definition: cluster_metadata.h:44
unsigned int major
Definition: cluster_metadata.h:43
unsigned int patch
Definition: cluster_metadata.h:45
bool operator!=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:75
bool operator<=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:59
Definition: result.h:30