MySQL 9.0.0
Source Code Documentation
plugin_config.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 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 METADATA_CACHE_PLUGIN_CONFIG_INCLUDED
27#define METADATA_CACHE_PLUGIN_CONFIG_INCLUDED
28
30
32
33#include <chrono>
34#include <map>
35#include <string>
36#include <vector>
37
40#include "mysql/harness/plugin.h"
43#include "router_options.h"
44#include "tcp_address.h"
45
46extern "C" {
47extern mysql_harness::Plugin METADATA_CACHE_PLUGIN_EXPORT
49}
50
53 public:
54 /** @brief Constructor
55 *
56 * @param section from configuration file provided as ConfigSection
57 */
59
60 /**
61 * @param option name of the option
62 */
63 std::string get_default(std::string_view option) const override;
64 bool is_required(std::string_view option) const override;
65
66 mutable std::unique_ptr<ClusterMetadataDynamicState>
68 /** @brief MySQL Metadata hosts to connect with */
70 /** @brief User used for authenticating with MySQL Metadata */
71 std::string user;
72 /** @brief TTL used for storing data in the cache */
73 std::chrono::milliseconds ttl;
74 /** @brief TTL used for limiting the lifetime of the rest user authentication
75 * data stored in the metadata */
76 std::chrono::milliseconds auth_cache_ttl;
77 /** @brief Refresh rate of the rest user authentication data stored in the
78 * cache */
79 std::chrono::milliseconds auth_cache_refresh_interval;
80 /** @brief Name of the Cluster this Router instance was bootstrapped to use.
81 */
82 std::string cluster_name;
83 /** @brief connect_timeout The time in seconds after which trying to connect
84 * to metadata server timeouts */
85 unsigned int connect_timeout;
86 /** @brief read_timeout The time in seconds after which read from metadata
87 * server timeouts */
88 unsigned int read_timeout;
89 /** @brief memory in kilobytes allocated for thread's stack */
90 unsigned int thread_stack_size;
91 /** @brief Whether we should listen to GR notifications from the cluster
92 * nodes. */
94 /** @brief Type of the cluster this configuration was bootstrap against. */
96 /** @brief Id of the router in the metadata. */
97 unsigned int router_id;
98 /** @brief SSL settings for metadata cache connection. */
100
101 // options configured in the metadata
102 std::string target_cluster;
104 invalidated_cluster_policy{kDefautlInvalidatedClusterRoutingPolicy};
105 bool use_replica_primary_as_rw{false};
106 QuorumConnectionLostAllowTraffic unreachable_quorum_allowed_traffic{
108 std::chrono::seconds stats_updates_frequency{std::chrono::seconds(-1)};
110
111 /** @brief Gets (Group Replication ID for GR cluster or cluster_id for
112 * ReplicaSet cluster) if preset in the dynamic configuration.
113 *
114 * @note If there is no dynamic configuration (backward compatibility) it
115 * returns empty string.
116 */
117 std::string get_cluster_type_specific_id() const;
118
119 std::string get_clusterset_id() const;
120
121 /** @brief Gets last know ReplicaSet cluster metadata view_id stored in the
122 * dynamic state file . */
123 uint64_t get_view_id() const;
124
125 void expose_configuration(const mysql_harness::ConfigSection &default_section,
126 const bool initial) const;
127
128 private:
129 /** @brief Gets a list of metadata servers.
130 *
131 *
132 * Throws std::invalid_argument on errors.
133 *
134 * @param default_port Use this port when none was provided
135 * @return std::vector<mysql_harness::TCPAddress>
136 */
137 std::vector<mysql_harness::TCPAddress> get_metadata_servers(
138 uint16_t default_port) const;
139
141 const mysql_harness::ConfigSection *section);
142
143 std::unique_ptr<ClusterMetadataDynamicState> get_dynamic_state(
144 const mysql_harness::ConfigSection *section);
145};
146
147#endif // METADATA_CACHE_PLUGIN_CONFIG_INCLUDED
Definition: plugin_config.h:52
std::chrono::milliseconds auth_cache_ttl
TTL used for limiting the lifetime of the rest user authentication data stored in the metadata.
Definition: plugin_config.h:76
std::string target_cluster
Definition: plugin_config.h:102
std::string user
User used for authenticating with MySQL Metadata.
Definition: plugin_config.h:71
unsigned int connect_timeout
connect_timeout The time in seconds after which trying to connect to metadata server timeouts
Definition: plugin_config.h:85
std::chrono::milliseconds auth_cache_refresh_interval
Refresh rate of the rest user authentication data stored in the cache.
Definition: plugin_config.h:79
unsigned int router_id
Id of the router in the metadata.
Definition: plugin_config.h:97
bool use_gr_notifications
Whether we should listen to GR notifications from the cluster nodes.
Definition: plugin_config.h:93
const metadata_cache::metadata_servers_list_t metadata_servers_addresses
MySQL Metadata hosts to connect with.
Definition: plugin_config.h:69
std::unique_ptr< ClusterMetadataDynamicState > metadata_cache_dynamic_state
Definition: plugin_config.h:67
std::string cluster_name
Name of the Cluster this Router instance was bootstrapped to use.
Definition: plugin_config.h:82
mysqlrouter::ClusterType cluster_type
Type of the cluster this configuration was bootstrap against.
Definition: plugin_config.h:95
std::chrono::milliseconds ttl
TTL used for storing data in the cache.
Definition: plugin_config.h:73
mysqlrouter::SSLOptions ssl_options
SSL settings for metadata cache connection.
Definition: plugin_config.h:99
unsigned int read_timeout
read_timeout The time in seconds after which read from metadata server timeouts
Definition: plugin_config.h:88
unsigned int thread_stack_size
memory in kilobytes allocated for thread's stack
Definition: plugin_config.h:90
mysqlrouter::ClusterType get_cluster_type(const mysql_harness::ConfigSection *section)
Retrieve and manage plugin configuration.
Definition: plugin_config.h:62
virtual bool is_required(std::string_view option) const =0
Returns whether the given option is required.
virtual std::string get_default(std::string_view option) const =0
Gets the default for the given option.
Configuration section.
Definition: config_parser.h:141
InvalidatedClusterRoutingPolicy
Definition: cluster_metadata.h:162
static stdx::expected< std::string, std::error_code > get_clusterset_id(mysqlrouter::MySQLSession &session, const mysqlrouter::TargetCluster &target_cluster)
Definition: cluster_metadata_gr.cc:1066
static void expose_configuration(mysql_harness::PluginFuncEnv *env, const char *, bool initial)
Definition: connection_pool_plugin.cc:177
mysql_harness::Plugin METADATA_CACHE_PLUGIN_EXPORT harness_plugin_metadata_cache
Definition: metadata_cache_plugin.cc:291
#define METADATA_CACHE_PLUGIN_EXPORT
Definition: metadata_cache_plugin_export.h:15
std::vector< metadata_server_t > metadata_servers_list_t
Definition: metadata_cache_datatypes.h:146
ClusterType
Definition: cluster_metadata.h:140
ReadOnlyTargets
Definition: router_options.h:39
static const auto kDefautlInvalidatedClusterRoutingPolicy
Definition: router_options.h:36
static const QuorumConnectionLostAllowTraffic kDefaultQuorumConnectionLostAllowTraffic
Definition: router_options.h:47
static const ReadOnlyTargets kDefaultReadOnlyTargets
Definition: router_options.h:40
QuorumConnectionLostAllowTraffic
Definition: router_options.h:45
SSL connection related options.
Definition: datatypes.h:39
double seconds()
Definition: task.cc:310