MySQL 8.0.39
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 <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
116template <size_t N>
118 const mysqlrouter::MetadataSchemaVersion (&required)[N],
119 const mysqlrouter::MetadataSchemaVersion &available) {
120 for (size_t i = 0; i < N; ++i) {
122 return true;
123 }
124
125 return false;
126}
127
128template <size_t N>
130 std::string result;
131 for (size_t i = 0; i < N; ++i) {
132 result += to_string(version[i]);
133 if (i != N - 1) {
134 result += ", ";
135 }
136 }
137
138 return result;
139}
140
141enum class ClusterType {
142 GR_V1, /* based on Group Replication (metadata 1.x) */
143 GR_V2, /* based on Group Replication (metadata 2.x) */
144 GR_CS, /* based on Group Replication, part of ClusterSet (metadata 2.1+) */
145 RS_V2 /* ReplicaSet (metadata 2.x) */
146};
147
149get_cluster_type(const MetadataSchemaVersion &schema_version,
150 MySQLSession *mysql, unsigned int router_id = 0);
151
152std::string ROUTER_LIB_EXPORT to_string(const ClusterType cluster_type);
153
154class MetadataUpgradeInProgressException : public std::exception {};
155
158
160
162 public:
165
167 const std::string &value = "")
168 : target_type_(type), target_value_(value) {
170 }
171
172 std::string to_string() const { return target_value_; }
173 const char *c_str() const { return target_value_.c_str(); }
174
178 }
179
180 void target_type(const TargetType value) { target_type_ = value; }
181 void target_value(const std::string &value) { target_value_ = value; }
185 }
186
187 private:
189 std::string target_value_;
192};
193
194} // namespace mysqlrouter
195#endif
Definition: cluster_metadata.h:154
Definition: mysql_session.h:153
Definition: cluster_metadata.h:161
void invalidated_cluster_routing_policy(const InvalidatedClusterRoutingPolicy value)
Definition: cluster_metadata.h:182
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy() const
Definition: cluster_metadata.h:176
void target_value(const std::string &value)
Definition: cluster_metadata.h:181
TargetCluster(const TargetType type=TargetType::ByPrimaryRole, const std::string &value="")
Definition: cluster_metadata.h:166
TargetType
Definition: cluster_metadata.h:163
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:164
void target_type(const TargetType value)
Definition: cluster_metadata.h:180
std::string target_value_
Definition: cluster_metadata.h:189
TargetType target_type_
Definition: cluster_metadata.h:188
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy_
Definition: cluster_metadata.h:190
std::string to_string() const
Definition: cluster_metadata.h:172
const char * c_str() const
Definition: cluster_metadata.h:173
TargetType target_type() const
Definition: cluster_metadata.h:175
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:141
std::string ROUTER_LIB_EXPORT get_metadata_schema_deprecated_msg(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:451
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
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