MySQL 8.4.3
Source Code Documentation
cluster_metadata.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 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 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
115template <size_t N>
117 const mysqlrouter::MetadataSchemaVersion (&required)[N],
118 const mysqlrouter::MetadataSchemaVersion &available) {
119 for (size_t i = 0; i < N; ++i) {
121 return true;
122 }
123
124 return false;
125}
126
127template <size_t N>
129 std::string result;
130 for (size_t i = 0; i < N; ++i) {
131 result += to_string(version[i]);
132 if (i != N - 1) {
133 result += ", ";
134 }
135 }
136
137 return result;
138}
139
140enum class ClusterType {
141 GR_V2, /* based on Group Replication (metadata 2.x) */
142 GR_CS, /* based on Group Replication, part of ClusterSet (metadata 2.1+) */
143 RS_V2 /* ReplicaSet (metadata 2.x) */
144};
145
147get_cluster_type(const MetadataSchemaVersion &schema_version,
148 MySQLSession *mysql, unsigned int router_id = 0);
149
150std::string ROUTER_CLUSTER_EXPORT to_string(const ClusterType cluster_type);
151
152class MetadataUpgradeInProgressException : public std::exception {};
153
156
158
160 public:
163
165 const std::string &value = "")
166 : target_type_(type), target_value_(value) {
168 }
169
170 std::string to_string() const { return target_value_; }
171 const char *c_str() const { return target_value_.c_str(); }
172
176 }
177
178 void target_type(const TargetType value) { target_type_ = value; }
179 void target_value(const std::string &value) { target_value_ = value; }
183 }
184
185 private:
187 std::string target_value_;
190};
191
192constexpr const std::string_view kNodeTagHidden{"_hidden"};
193constexpr const std::string_view kNodeTagDisconnectWhenHidden{
194 "_disconnect_existing_sessions_when_hidden"};
195
196constexpr const bool kNodeTagHiddenDefault{false};
197constexpr const bool kNodeTagDisconnectWhenHiddenDefault{true};
198
200
201std::optional<InstanceType> ROUTER_CLUSTER_EXPORT
202str_to_instance_type(const std::string &);
203
205std::string ROUTER_CLUSTER_EXPORT
207
208constexpr const std::chrono::milliseconds kDefaultMetadataTTLCluster{500};
209constexpr const std::chrono::milliseconds
211 std::chrono::milliseconds(60 * 1000);
212constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterSet{
213 5000}; // default TTL for ClusterSet is 5 seconds regardless if GR
214 // Notifications are used or not
217
218} // namespace mysqlrouter
219#endif
Definition: cluster_metadata.h:152
Definition: mysql_session.h:153
Definition: cluster_metadata.h:159
void invalidated_cluster_routing_policy(const InvalidatedClusterRoutingPolicy value)
Definition: cluster_metadata.h:180
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy() const
Definition: cluster_metadata.h:174
void target_value(const std::string &value)
Definition: cluster_metadata.h:179
TargetCluster(const TargetType type=TargetType::ByPrimaryRole, const std::string &value="")
Definition: cluster_metadata.h:164
TargetType
Definition: cluster_metadata.h:161
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:162
void target_type(const TargetType value)
Definition: cluster_metadata.h:178
std::string target_value_
Definition: cluster_metadata.h:187
TargetType target_type_
Definition: cluster_metadata.h:186
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy_
Definition: cluster_metadata.h:188
std::string to_string() const
Definition: cluster_metadata.h:170
const char * c_str() const
Definition: cluster_metadata.h:171
TargetType target_type() const
Definition: cluster_metadata.h:173
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:140
InstanceType
Definition: cluster_metadata.h:199
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:193
constexpr const std::string_view kNodeTagHidden
Definition: cluster_metadata.h:192
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:210
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:212
const bool kDefaultUseGRNotificationsClusterSet
Definition: cluster_metadata.h:216
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:208
constexpr const bool kNodeTagDisconnectWhenHiddenDefault
Definition: cluster_metadata.h:197
constexpr const bool kNodeTagHiddenDefault
Definition: cluster_metadata.h:196
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:215
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