MySQL 8.3.0
Source Code Documentation
cluster_metadata.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQLROUTER_CLUSTER_METADATA_INCLUDED
26#define MYSQLROUTER_CLUSTER_METADATA_INCLUDED
27
29
30#include <optional>
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
194constexpr const std::string_view kNodeTagHidden{"_hidden"};
195constexpr const std::string_view kNodeTagDisconnectWhenHidden{
196 "_disconnect_existing_sessions_when_hidden"};
197
198constexpr const bool kNodeTagHiddenDefault{false};
199constexpr const bool kNodeTagDisconnectWhenHiddenDefault{true};
200
202
203std::optional<InstanceType> ROUTER_LIB_EXPORT
204str_to_instance_type(const std::string &);
205
206std::string ROUTER_LIB_EXPORT to_string(const InstanceType);
207
208} // namespace mysqlrouter
209#endif
Definition: cluster_metadata.h:154
Definition: mysql_session.h:152
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:943
std::atomic< Type > N
Definition: ut0counter.h:224
Definition: instrumented_condition_variable.h:31
Definition: dim.h:357
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:1191
ClusterType
Definition: cluster_metadata.h:141
std::string ROUTER_LIB_EXPORT get_metadata_schema_deprecated_msg(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:462
InstanceType
Definition: cluster_metadata.h:201
bool ROUTER_LIB_EXPORT metadata_schema_version_is_deprecated(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:457
constexpr MetadataSchemaVersion kUpgradeInProgressMetadataVersion
Definition: cluster_metadata.h:95
constexpr MetadataSchemaVersion kRequiredRoutingMetadataSchemaVersion[]
Definition: cluster_metadata.h:85
constexpr const std::string_view kNodeTagDisconnectWhenHidden
Definition: cluster_metadata.h:195
constexpr const std::string_view kNodeTagHidden
Definition: cluster_metadata.h:194
MetadataSchemaVersion ROUTER_LIB_EXPORT get_metadata_schema_version(MySQLSession *mysql)
Definition: cluster_metadata.cc:476
stdx::expected< void, std::string > ROUTER_LIB_EXPORT setup_metadata_session(MySQLSession &session)
Definition: cluster_metadata.cc:1385
bool ROUTER_LIB_EXPORT check_group_has_quorum(MySQLSession *mysql)
Definition: cluster_metadata.cc:544
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:1231
bool ROUTER_LIB_EXPORT check_group_replication_online(MySQLSession *mysql)
Definition: cluster_metadata.cc:528
bool ROUTER_LIB_EXPORT metadata_schema_version_is_compatible(const mysqlrouter::MetadataSchemaVersion &required, const mysqlrouter::MetadataSchemaVersion &available)
Definition: cluster_metadata.cc:443
constexpr const bool kNodeTagDisconnectWhenHiddenDefault
Definition: cluster_metadata.h:199
constexpr const bool kNodeTagHiddenDefault
Definition: cluster_metadata.h:198
std::optional< InstanceType > ROUTER_LIB_EXPORT str_to_instance_type(const std::string &)
Definition: cluster_metadata.cc:1413
std::string ROUTER_LIB_EXPORT to_string(const MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:471
struct result result
Definition: result.h:33
required uint64 version
Definition: replication_group_member_actions.proto:40
required string type
Definition: replication_group_member_actions.proto:33
#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:29