MySQL 9.2.0
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, 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
31
32#include <chrono>
33#include <optional>
34#include <stdexcept>
35#include <string>
36
38
39namespace mysqlrouter {
40
41class MySQLSession;
42
44
45std::string ROUTER_CLUSTER_EXPORT
47
48// Semantic version numbers that this Router version supports for bootstrap mode
50
51// Semantic version number that this Router version supports for routing mode
53 {2, 0, 0}};
54
55// Version that introduced views and support for ReplicaSet cluster type
57
58// Version that introduced support for ClusterSets
60
61// Version that introduced support for Routing guidelines
63
64// Version that will be is set while the metadata is being updated
66
67MetadataSchemaVersion ROUTER_CLUSTER_EXPORT
69
72 const mysqlrouter::MetadataSchemaVersion &available);
73
76
77// throws std::logic_error, MySQLSession::Error
79
80// throws MySQLSession::Error, std::logic_error, std::out_of_range
82
84
85std::string ROUTER_CLUSTER_EXPORT
87
88template <size_t N>
90 const mysqlrouter::MetadataSchemaVersion (&required)[N],
91 const mysqlrouter::MetadataSchemaVersion &available) {
92 for (size_t i = 0; i < N; ++i) {
94 return true;
95 }
96
97 return false;
98}
99
101 MySQLSession *mysql, const std::uint32_t router_id);
102
103template <size_t N>
105 std::string result;
106 for (size_t i = 0; i < N; ++i) {
107 result += to_string(version[i]);
108 if (i != N - 1) {
109 result += ", ";
110 }
111 }
112
113 return result;
114}
115
116enum class ClusterType {
117 GR_V2, /* based on Group Replication (metadata 2.x) */
118 GR_CS, /* based on Group Replication, part of ClusterSet (metadata 2.1+) */
119 RS_V2 /* ReplicaSet (metadata 2.x) */
120};
121
123get_cluster_type(const MetadataSchemaVersion &schema_version,
124 MySQLSession *mysql, unsigned int router_id = 0);
125
126std::string ROUTER_CLUSTER_EXPORT to_string(const ClusterType cluster_type);
127
128class MetadataUpgradeInProgressException : public std::exception {};
129
132
134
136 public:
139
141 const std::string &value = "")
142 : target_type_(type), target_value_(value) {
144 }
145
146 std::string to_string() const { return target_value_; }
147 const char *c_str() const { return target_value_.c_str(); }
148
152 }
153
154 void target_type(const TargetType value) { target_type_ = value; }
155 void target_value(const std::string &value) { target_value_ = value; }
159 }
160
161 private:
163 std::string target_value_;
166};
167
168constexpr const std::string_view kNodeTagHidden{"_hidden"};
169constexpr const std::string_view kNodeTagDisconnectWhenHidden{
170 "_disconnect_existing_sessions_when_hidden"};
171
172constexpr const bool kNodeTagHiddenDefault{false};
173constexpr const bool kNodeTagDisconnectWhenHiddenDefault{true};
174
176
177std::optional<InstanceType> ROUTER_CLUSTER_EXPORT
178str_to_instance_type(const std::string &);
179
181std::string ROUTER_CLUSTER_EXPORT
183
184constexpr const std::chrono::milliseconds kDefaultMetadataTTLCluster{500};
185constexpr const std::chrono::milliseconds
187 std::chrono::milliseconds(60 * 1000);
188constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterSet{
189 5000}; // default TTL for ClusterSet is 5 seconds regardless if GR
190 // Notifications are used or not
193
196
197} // namespace mysqlrouter
198#endif
Definition: cluster_metadata.h:128
Definition: mysql_session.h:154
Definition: cluster_metadata.h:135
void invalidated_cluster_routing_policy(const InvalidatedClusterRoutingPolicy value)
Definition: cluster_metadata.h:156
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy() const
Definition: cluster_metadata.h:150
void target_value(const std::string &value)
Definition: cluster_metadata.h:155
TargetCluster(const TargetType type=TargetType::ByPrimaryRole, const std::string &value="")
Definition: cluster_metadata.h:140
TargetType
Definition: cluster_metadata.h:137
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:138
void target_type(const TargetType value)
Definition: cluster_metadata.h:154
std::string target_value_
Definition: cluster_metadata.h:163
TargetType target_type_
Definition: cluster_metadata.h:162
InvalidatedClusterRoutingPolicy invalidated_cluster_routing_policy_
Definition: cluster_metadata.h:164
std::string to_string() const
Definition: cluster_metadata.h:146
const char * c_str() const
Definition: cluster_metadata.h:147
TargetType target_type() const
Definition: cluster_metadata.h:149
Definition: expected.h:286
std::atomic< Type > N
Definition: ut0counter.h:225
Definition: instrumented_condition_variable.h:32
Definition: base64.h:43
void ROUTER_CLUSTER_EXPORT verify_routing_guidelines_version(MySQLSession *mysql, const std::uint32_t router_id)
Definition: cluster_metadata.cc:459
constexpr MetadataSchemaVersion kClusterSetsMetadataVersion
Definition: cluster_metadata.h:59
constexpr MetadataSchemaVersion kNewMetadataVersion
Definition: cluster_metadata.h:56
bool ROUTER_CLUSTER_EXPORT is_part_of_cluster_set(MySQLSession *mysql)
Definition: cluster_metadata.cc:1174
ClusterType
Definition: cluster_metadata.h:116
InstanceType
Definition: cluster_metadata.h:175
std::string ROUTER_CLUSTER_EXPORT get_unsupported_server_version_msg(MySQLSession *mysql)
Definition: cluster_metadata.cc:1421
constexpr MetadataSchemaVersion kUpgradeInProgressMetadataVersion
Definition: cluster_metadata.h:65
constexpr MetadataSchemaVersion kRequiredRoutingMetadataSchemaVersion[]
Definition: cluster_metadata.h:52
constexpr const std::string_view kNodeTagDisconnectWhenHidden
Definition: cluster_metadata.h:169
bool ROUTER_CLUSTER_EXPORT is_server_version_supported(MySQLSession *mysql)
Definition: cluster_metadata.cc:1417
constexpr MetadataSchemaVersion kRoutingGuidelinesMetadataVersion
Definition: cluster_metadata.h:62
constexpr const std::string_view kNodeTagHidden
Definition: cluster_metadata.h:168
MetadataSchemaVersion ROUTER_CLUSTER_EXPORT get_metadata_schema_version(MySQLSession *mysql)
Definition: cluster_metadata.cc:492
std::string ROUTER_CLUSTER_EXPORT get_metadata_schema_uncompatible_msg(const mysqlrouter::MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:450
stdx::expected< void, std::string > ROUTER_CLUSTER_EXPORT setup_metadata_session(MySQLSession &session)
Definition: cluster_metadata.cc:1347
const bool kDefaultCloseConnectionAfterRefreshClusterSet
Definition: cluster_metadata.h:195
bool ROUTER_CLUSTER_EXPORT check_group_has_quorum(MySQLSession *mysql)
Definition: cluster_metadata.cc:559
constexpr MetadataSchemaVersion kRequiredBootstrapSchemaVersion[]
Definition: cluster_metadata.h:49
const bool kDefaultCloseConnectionAfterRefreshCluster
Definition: cluster_metadata.h:194
constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterGRNotificationsON
Definition: cluster_metadata.h:186
ClusterType ROUTER_CLUSTER_EXPORT get_cluster_type(const MetadataSchemaVersion &schema_version, MySQLSession *mysql, unsigned int router_id=0)
Definition: cluster_metadata.cc:1215
constexpr const std::chrono::milliseconds kDefaultMetadataTTLClusterSet
Definition: cluster_metadata.h:188
const bool kDefaultUseGRNotificationsClusterSet
Definition: cluster_metadata.h:192
bool ROUTER_CLUSTER_EXPORT check_group_replication_online(MySQLSession *mysql)
Definition: cluster_metadata.cc:543
bool ROUTER_CLUSTER_EXPORT metadata_schema_version_is_compatible(const mysqlrouter::MetadataSchemaVersion &required, const mysqlrouter::MetadataSchemaVersion &available)
Definition: cluster_metadata.cc:436
constexpr const std::chrono::milliseconds kDefaultMetadataTTLCluster
Definition: cluster_metadata.h:184
constexpr const bool kNodeTagDisconnectWhenHiddenDefault
Definition: cluster_metadata.h:173
constexpr const bool kNodeTagHiddenDefault
Definition: cluster_metadata.h:172
std::optional< InstanceType > ROUTER_CLUSTER_EXPORT str_to_instance_type(const std::string &)
Definition: cluster_metadata.cc:1375
std::string ROUTER_CLUSTER_EXPORT to_string(const MetadataSchemaVersion &version)
Definition: cluster_metadata.cc:487
const bool kDefaultUseGRNotificationsCluster
Definition: cluster_metadata.h:191
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:43
Definition: version_base.h:33
Definition: result.h:30