MySQL 8.0.41
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <stdexcept>
32#include <string>
33
35
36namespace mysqlrouter {
37
38class MySQLSession;
39
41 unsigned int major;
42 unsigned int minor;
43 unsigned int patch;
44
45 bool operator<(const MetadataSchemaVersion &o) const {
46 if (major == o.major) {
47 if (minor == o.minor) {
48 return patch < o.patch;
49 } else {
50 return minor < o.minor;
51 }
52 } else {
53 return major < o.major;
54 }
55 }
56
57 bool operator<=(const MetadataSchemaVersion &o) const {
58 return operator<(o) || operator==(o);
59 }
60
61 bool operator>(const MetadataSchemaVersion &o) const {
62 return operator!=(o) && !operator<(o);
63 }
64
65 bool operator>=(const MetadataSchemaVersion &o) const {
66 return operator>(o) || operator==(o);
67 }
68
69 bool operator==(const MetadataSchemaVersion &o) const {
70 return major == o.major && minor == o.minor && patch == o.patch;
71 }
72
73 bool operator!=(const MetadataSchemaVersion &o) const {
74 return !operator==(o);
75 }
76};
77
78std::string ROUTER_LIB_EXPORT to_string(const MetadataSchemaVersion &version);
79
80// Semantic version numbers that this Router version supports for bootstrap mode
82 {2, 0, 0}};
83
84// Semantic version number that this Router version supports for routing mode
86 {1, 0, 0}, {2, 0, 0}};
87
88// Version that introduced views and support for ReplicaSet cluster type
90
91// Version that introduced support for ClusterSets
93
94// Version that will be is set while the metadata is being updated
96
97MetadataSchemaVersion ROUTER_LIB_EXPORT
99
102 const mysqlrouter::MetadataSchemaVersion &available);
103
106
109
110// throws std::logic_error, MySQLSession::Error
112
113// throws MySQLSession::Error, std::logic_error, std::out_of_range
115
117
118std::string ROUTER_LIB_EXPORT
120
121template <size_t N>
123 const mysqlrouter::MetadataSchemaVersion (&required)[N],
124 const mysqlrouter::MetadataSchemaVersion &available) {
125 for (size_t i = 0; i < N; ++i) {
127 return true;
128 }
129
130 return false;
131}
132
133template <size_t N>
135 std::string result;
136 for (size_t i = 0; i < N; ++i) {
137 result += to_string(version[i]);
138 if (i != N - 1) {
139 result += ", ";
140 }
141 }
142
143 return result;
144}
145
146enum class ClusterType {
147 GR_V1, /* based on Group Replication (metadata 1.x) */
148 GR_V2, /* based on Group Replication (metadata 2.x) */
149 GR_CS, /* based on Group Replication, part of ClusterSet (metadata 2.1+) */
150 RS_V2 /* ReplicaSet (metadata 2.x) */
151};
152
154get_cluster_type(const MetadataSchemaVersion &schema_version,
155 MySQLSession *mysql, unsigned int router_id = 0);
156
157std::string ROUTER_LIB_EXPORT to_string(const ClusterType cluster_type);
158
159class MetadataUpgradeInProgressException : public std::exception {};
160
163
165
167 public:
170
172 const std::string &value = "")
173 : target_type_(type), target_value_(value) {
175 }
176
177 std::string to_string() const { return target_value_; }
178 const char *c_str() const { return target_value_.c_str(); }
179
183 }
184
185 void target_type(const TargetType value) { target_type_ = value; }
186 void target_value(const std::string &value) { target_value_ = value; }
190 }
191
192 private:
194 std::string target_value_;
197};
198
199} // namespace mysqlrouter
200#endif
Definition: cluster_metadata.h:159
Definition: mysql_session.h:153
Definition: cluster_metadata.h:166
void invalidated_cluster_routing_policy(const InvalidatedClusterRoutingPolicy value)
Definition: cluster_metadata.h:187
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy() const
Definition: cluster_metadata.h:181
void target_value(const std::string &value)
Definition: cluster_metadata.h:186
TargetCluster(const TargetType type=TargetType::ByPrimaryRole, const std::string &value="")
Definition: cluster_metadata.h:171
TargetType
Definition: cluster_metadata.h:168
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:169
void target_type(const TargetType value)
Definition: cluster_metadata.h:185
std::string target_value_
Definition: cluster_metadata.h:194
TargetType target_type_
Definition: cluster_metadata.h:193
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy_
Definition: cluster_metadata.h:195
std::string to_string() const
Definition: cluster_metadata.h:177
const char * c_str() const
Definition: cluster_metadata.h:178
TargetType target_type() const
Definition: cluster_metadata.h:180
Definition: expected.h:944
std::atomic< Type > N
Definition: ut0counter.h:225
Definition: instrumented_condition_variable.h:32
Definition: dim.h:358
constexpr MetadataSchemaVersion kClusterSetsMetadataVersion
Definition: cluster_metadata.h:92
constexpr MetadataSchemaVersion kNewMetadataVersion
Definition: cluster_metadata.h:89
bool ROUTER_LIB_EXPORT is_part_of_cluster_set(MySQLSession *mysql)
Definition: cluster_metadata.cc:1123
ClusterType
Definition: cluster_metadata.h:146
std::string ROUTER_LIB_EXPORT get_metadata_schema_deprecated_msg(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:451
std::string ROUTER_LIB_EXPORT get_unsupported_server_version_msg(MySQLSession *mysql)
Definition: cluster_metadata.cc:1354
bool ROUTER_LIB_EXPORT metadata_schema_version_is_deprecated(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:446
constexpr MetadataSchemaVersion kUpgradeInProgressMetadataVersion
Definition: cluster_metadata.h:95
constexpr MetadataSchemaVersion kRequiredRoutingMetadataSchemaVersion[]
Definition: cluster_metadata.h:85
bool ROUTER_LIB_EXPORT is_server_version_supported(MySQLSession *mysql)
Definition: cluster_metadata.cc:1350
MetadataSchemaVersion ROUTER_LIB_EXPORT get_metadata_schema_version(MySQLSession *mysql)
Definition: cluster_metadata.cc:465
stdx::expected< void, std::string > ROUTER_LIB_EXPORT setup_metadata_session(MySQLSession &session)
Definition: cluster_metadata.cc:1317
bool ROUTER_LIB_EXPORT check_group_has_quorum(MySQLSession *mysql)
Definition: cluster_metadata.cc:533
constexpr MetadataSchemaVersion kRequiredBootstrapSchemaVersion[]
Definition: cluster_metadata.h:81
ClusterType ROUTER_LIB_EXPORT get_cluster_type(const MetadataSchemaVersion &schema_version, MySQLSession *mysql, unsigned int router_id=0)
Definition: cluster_metadata.cc:1163
bool ROUTER_LIB_EXPORT check_group_replication_online(MySQLSession *mysql)
Definition: cluster_metadata.cc:517
bool ROUTER_LIB_EXPORT metadata_schema_version_is_compatible(const mysqlrouter::MetadataSchemaVersion &required, const mysqlrouter::MetadataSchemaVersion &available)
Definition: cluster_metadata.cc:432
std::string ROUTER_LIB_EXPORT to_string(const MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:460
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_LIB_EXPORT
Definition: router_export.h:15
Definition: cluster_metadata.h:40
bool operator<(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:45
bool operator>(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:61
bool operator==(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:69
bool operator>=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:65
unsigned int minor
Definition: cluster_metadata.h:42
unsigned int major
Definition: cluster_metadata.h:41
unsigned int patch
Definition: cluster_metadata.h:43
bool operator!=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:73
bool operator<=(const MetadataSchemaVersion &o) const
Definition: cluster_metadata.h:57
Definition: result.h:30