MySQL 8.4.0
Source Code Documentation
router_options.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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_ROUTER_OPTIONS_INCLUDED
27#define METADATA_CACHE_ROUTER_OPTIONS_INCLUDED
28
32
33#include <chrono>
34#include <optional>
35
38
42
44
49
52
53/** @class RouterOptions
54 *
55 * @brief Represents the Router options in v2_routers view in the metadata
56 * schema
57 */
59 public:
60 /** @brief Pupulate the object by reading the options from the metadata
61 *
62 * @param session mysql server session to read metadata with
63 * @param router_id id of the Router in the metadata\
64 * @param schema_version current metadata schema version
65 * @param cluster_type type of the cluster the Router is configured to use
66 *
67 * @returns true if successful, false otherwise
68 */
70 mysqlrouter::MySQLSession &session, const unsigned router_id,
71 const mysqlrouter::MetadataSchemaVersion schema_version,
72 const mysqlrouter::ClusterType cluster_type);
73
74 /** @brief Get the raw JSON string read from the metadata during the last
75 * read_from_metadata() call
76 */
77 std::string get_string() const { return options_str_; }
78
79 /** @brief Get the setting for RO targets assigned to a given Router in the
80 * metadata
81 */
83
84 /** @brief Get the stats updates ferquency value (in seconds) assigned for a
85 * given Router in the metadata
86 */
87 std::optional<std::chrono::seconds> get_stats_updates_frequency() const;
88
89 // clusterset specific Router Options
90
91 /** @brief Get the get_use_replica_primary_as_rw boolean value assigned for a
92 * given Router in the metadata
93 */
95
96 /** @brief Get the unreachable_quorum_allowed_traffic value assigned for a
97 * given Router in the metadata
98 */
100 const;
101
102 /** @brief Get the target_cluster assigned for a given Router in the metadata
103 *
104 * @returns assigned target_cluster if read successful, std::nullopt otherwise
105 */
106 std::optional<mysqlrouter::TargetCluster> get_target_cluster() const;
107
108 private:
109 std::string options_str_;
110 unsigned int router_id_{};
112};
113
114#endif // METADATA_CACHE_ROUTER_OPTIONS_INCLUDED
Represents the Router options in v2_routers view in the metadata schema.
Definition: router_options.h:58
bool read_from_metadata(mysqlrouter::MySQLSession &session, const unsigned router_id, const mysqlrouter::MetadataSchemaVersion schema_version, const mysqlrouter::ClusterType cluster_type)
Pupulate the object by reading the options from the metadata.
Definition: router_options.cc:243
unsigned int router_id_
Definition: router_options.h:110
std::string options_str_
Definition: router_options.h:109
QuorumConnectionLostAllowTraffic get_unreachable_quorum_allowed_traffic() const
Get the unreachable_quorum_allowed_traffic value assigned for a given Router in the metadata.
Definition: router_options.cc:344
std::optional< std::chrono::seconds > get_stats_updates_frequency() const
Get the stats updates ferquency value (in seconds) assigned for a given Router in the metadata.
Definition: router_options.cc:195
mysqlrouter::ClusterType cluster_type_
Definition: router_options.h:111
std::string get_string() const
Get the raw JSON string read from the metadata during the last read_from_metadata() call.
Definition: router_options.h:77
std::optional< mysqlrouter::TargetCluster > get_target_cluster() const
Get the target_cluster assigned for a given Router in the metadata.
Definition: router_options.cc:135
bool get_use_replica_primary_as_rw() const
Get the get_use_replica_primary_as_rw boolean value assigned for a given Router in the metadata.
Definition: router_options.cc:229
ReadOnlyTargets get_read_only_targets() const
Get the setting for RO targets assigned to a given Router in the metadata.
Definition: router_options.cc:289
Definition: mysql_session.h:153
#define METADATA_CACHE_EXPORT
Definition: metadata_cache_export.h:15
ClusterType
Definition: cluster_metadata.h:139
mode
Definition: file_handle.h:61
ReadOnlyTargets
Definition: router_options.h:39
METADATA_CACHE_EXPORT std::string to_string(const ReadOnlyTargets mode)
Definition: router_options.cc:332
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
Definition: cluster_metadata.h:42