MySQL 8.3.0
Source Code Documentation
cluster_metadata.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 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 METADATA_CACHE_CLUSTER_METADATA_INCLUDED
26#define METADATA_CACHE_CLUSTER_METADATA_INCLUDED
27
29
34#include "router_options.h"
35#include "tcp_address.h"
36
37#include <chrono>
38#include <cstring>
39#include <map>
40#include <memory>
41#include <optional>
42#include <string>
43#include <vector>
44
46
47namespace mysqlrouter {
48class MySQLSession;
49}
50namespace xcl {
51class XSession;
52}
53
55 std::function<bool(mysqlrouter::MySQLSession &connection,
57
58/** @class ClusterMetadata
59 *
60 * The `ClusterMetadata` class encapsulates a connection to the Metadata server.
61 * It uses the mysqlrouter::MySQLSession to setup, manage and retrieve results.
62 *
63 */
65 public:
66 /** @brief Constructor
67 *
68 * @param session_config Metadata MySQL session configuration
69 * @param ssl_options SSL related options to use for MySQL connections)
70 */
73 const mysqlrouter::SSLOptions &ssl_options);
74
75 // disable copy as it isn't needed right now. Feel free to enable
76 // must be explicitly defined though.
77 explicit ClusterMetadata(const ClusterMetadata &) = delete;
79
80 /** @brief Destructor
81 *
82 * Disconnect and release the connection to the metadata node.
83 */
84 ~ClusterMetadata() override;
85
86 /** @brief Connects with the Metadata server and sets up the session
87 * parameters
88 *
89 *
90 * @param metadata_server the server instance for which the connection
91 * should be attempted.
92 *
93 * @return a boolean to indicate if the connection and session parameters
94 * setup was successful.
95 */
97 &metadata_server) noexcept override;
98
99 /** @brief Disconnects from the Metadata server
100 *
101 */
102 void disconnect() noexcept override { metadata_connection_.reset(); }
103
104 /** @brief Gets the object representing the session to the metadata server
105 */
106 std::shared_ptr<mysqlrouter::MySQLSession> get_connection() override {
107 return metadata_connection_;
108 }
109
111 const metadata_cache::metadata_server_t &rw_server,
112 const unsigned router_id,
113 const metadata_cache::RouterAttributes &router_attributes) override;
114
116 const metadata_cache::metadata_server_t &rw_server,
117 const unsigned router_id) override;
118
119 auth_credentials_t fetch_auth_credentials(
120 const metadata_cache::metadata_server_t &md_server,
121 const mysqlrouter::TargetCluster &target_cluster) override;
122
123 std::optional<metadata_cache::metadata_server_t> find_rw_server(
124 const std::vector<metadata_cache::ManagedInstance> &instances);
125
126 std::optional<metadata_cache::metadata_server_t> find_rw_server(
127 const std::vector<metadata_cache::ManagedCluster> &clusters);
128
129 std::optional<std::chrono::seconds>
131 return router_options_.get_stats_updates_frequency();
132 }
133
134 protected:
135 /** Connects a MYSQL connection to the given instance
136 */
137 bool do_connect(mysqlrouter::MySQLSession &connection,
139
140 // throws metadata_cache::metadata_error and
141 // MetadataUpgradeInProgressException
142 mysqlrouter::MetadataSchemaVersion get_and_check_metadata_schema_version(
144
145 // Metadata node generic information
148
150
151#if 0 // not used so far
152 // The number of times we should try connecting to the metadata server if a
153 // connection attempt fails.
154 int connection_attempts_;
155#endif
156
157 // connection to metadata server (it may also be shared with GR status queries
158 // for optimisation purposes)
159 std::shared_ptr<mysqlrouter::MySQLSession> metadata_connection_;
160
162};
163
164std::string as_string(const char *input_str);
165
168 const size_t classic_port_column,
169 const size_t x_port_column);
170
172 const std::string &attributes);
173
174#endif // METADATA_CACHE_CLUSTER_METADATA_INCLUDED
The ClusterMetadata class encapsulates a connection to the Metadata server.
Definition: cluster_metadata.h:64
~ClusterMetadata() override
Destructor.
ClusterMetadata(const ClusterMetadata &)=delete
std::optional< std::chrono::seconds > get_periodic_stats_update_frequency() noexcept override
Definition: cluster_metadata.h:130
ClusterMetadata & operator=(const ClusterMetadata &)=delete
mysql_ssl_mode ssl_mode_
Definition: cluster_metadata.h:146
void disconnect() noexcept override
Disconnects from the Metadata server.
Definition: cluster_metadata.h:102
RouterOptions router_options_
Definition: cluster_metadata.h:161
mysqlrouter::SSLOptions ssl_options_
Definition: cluster_metadata.h:147
std::shared_ptr< mysqlrouter::MySQLSession > metadata_connection_
Definition: cluster_metadata.h:159
metadata_cache::MetadataCacheMySQLSessionConfig session_config_
Definition: cluster_metadata.h:149
std::shared_ptr< mysqlrouter::MySQLSession > get_connection() override
Gets the object representing the session to the metadata server.
Definition: cluster_metadata.h:106
The metadata class is used to create a pluggable transport layer from which the metadata is fetched f...
Definition: metadata.h:50
virtual bool update_router_last_check_in(const metadata_cache::metadata_server_t &rw_server, const unsigned router_id)=0
virtual bool connect_and_setup_session(const metadata_cache::metadata_server_t &metadata_server)=0
virtual bool update_router_attributes(const metadata_cache::metadata_server_t &rw_server, const unsigned router_id, const metadata_cache::RouterAttributes &router_attributes)=0
virtual auth_credentials_t fetch_auth_credentials(const metadata_cache::metadata_server_t &md_server, const mysqlrouter::TargetCluster &target_cluster)=0
Represents the Router options in v2_routers view in the metadata schema.
Definition: router_options.h:52
Class ManagedInstance represents a server managed by the topology.
Definition: metadata_cache_datatypes.h:100
Defines an IP address with port number
Definition: tcp_address.h:39
Definition: mysql_session.h:152
std::vector< const char * > Row
Definition: mysql_session.h:156
Definition: cluster_metadata.h:161
void set_instance_attributes(metadata_cache::ManagedInstance &instance, const std::string &attributes)
Definition: cluster_metadata.cc:473
std::function< bool(mysqlrouter::MySQLSession &connection, const metadata_cache::ManagedInstance &mi)> ConnectCallback
Definition: cluster_metadata.h:56
std::string as_string(const char *input_str)
Return a string representation of the input character string.
Definition: cluster_metadata.cc:72
bool set_instance_ports(metadata_cache::ManagedInstance &instance, const mysqlrouter::MySQLSession::Row &row, const size_t classic_port_column, const size_t x_port_column)
Definition: cluster_metadata.cc:205
#define METADATA_CACHE_EXPORT
Definition: metadata_cache_export.h:15
mysql_ssl_mode
Definition: mysql.h:269
static void do_connect(struct st_command *command)
Definition: mysqltest.cc:6627
Definition: dim.h:357
Definition: cluster_metadata.h:50
Definition: group_replication_metadata.h:37
Metadata MySQL session configuration.
Definition: metadata_cache_datatypes.h:222
Definition: metadata_cache_datatypes.h:238
Definition: cluster_metadata.h:40
SSL connection related options.
Definition: datatypes.h:38