MySQL 8.0.39
Source Code Documentation
cluster_metadata_dynamic_state.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 CLUSTER_METADATA_DYNAMIC_STATE_INCLUDED
27#define CLUSTER_METADATA_DYNAMIC_STATE_INCLUDED
28
29#include <memory>
30#include <string>
31#include <vector>
32
34
35namespace mysql_harness {
36class DynamicState;
37}
38
39/**
40 * @brief ClusterMetadataDynamicState represents a dynamic state that the
41 * metadata cache module wants to persist in the file.
42 */
44 public:
45 /**
46 * @brief Creates and initializes a metadata cache dynamic state object.
47 *
48 * @param base_config pointer to the global dynamic state base object that
49 * should be used to read and write metadata cache section.
50 * @param cluster_type type of the cluster (GR or ReplicaSet)
51 */
53 mysqlrouter::ClusterType cluster_type);
54
55 /**
56 * @brief Destructor.
57 */
59
60 /**
61 * @brief Saves the current state in the associated global base object,
62 * overwrites the current state in the global.
63 *
64 * @return success of operation
65 * @retval true operation succeeded
66 * @retval false operation failed
67 */
68 bool save();
69
70 /**
71 * @brief Loads the dynamic state from the associated global base object,
72 * overwrites the current state with the loaded data.
73 */
74 void load();
75
76 /**
77 * @brief Saves the state to the output stream given as a parameter,
78 * overwrites the stream content.
79 *
80 * @param state_stream stream where json content should be written to
81 *
82 * @return success of operation
83 * @retval true operation succeeded
84 * @retval false operation failed
85 */
86 bool save(std::ostream &state_stream);
87
88 /**
89 * @brief Sets the new value for the cluster type specific id in the state
90 * object.
91 *
92 * @param cluster_type_specific_id new value of the cluster type specific id
93 * to set
94 */
95 void set_cluster_type_specific_id(
96 const std::string &cluster_type_specific_id);
97
98 /**
99 * @brief Sets the new value for the ClusterSet id in the state object.
100 *
101 * @param clusterset_id new value of the ClusterSet id
102 * to set
103 */
104 void set_clusterset_id(const std::string &clusterset_id);
105
106 /**
107 * @brief Sets the new value for the cluster metadata server list in the state
108 * object.
109 *
110 * @param metadata_servers vector of the new metadata servers to set
111 */
112 void set_metadata_servers(const std::vector<std::string> &metadata_servers);
113
114 /**
115 * @brief Reads the current cluster metadata server list from the state
116 * object.
117 *
118 * @return vector containing current cluster metadata server list
119 */
120 std::vector<std::string> get_metadata_servers() const;
121
122 /**
123 * @brief Sets the new value for the last known metadata view_id of the
124 * ReplicaSet cluster or ClusterSet.
125 *
126 * @param view_id last known metadata view_id of the ReplicaSet cluster
127 */
128 void set_view_id(const uint64_t view_id);
129
130 /**
131 * @brief Reads the current value of the last known metadata view_id of the
132 * ReplicaSet cluster or ClusterSet from the state object.
133 *
134 * @return last known metadata view_id of the ReplicaSet cluster
135 */
136 unsigned get_view_id() const;
137
138 /**
139 * @brief Reads the current cluster type specific id from the state object.
140 *
141 * @return current cluster type specific id
142 */
143 std::string get_cluster_type_specific_id() const;
144
145 /**
146 * @brief Reads the current ClusterSet id from the state object.
147 *
148 * @return current cluster type specific id
149 */
150 std::string get_clusterset_id() const;
151
152 /**
153 * @brief Returns true if the metadata is configured to work with a
154 * ClusterSet, false if a single Cluster
155 *
156 */
157 bool is_clusterset() const;
158
159 private:
160 void save_section();
161
162 struct Pimpl;
163 std::unique_ptr<Pimpl> pimpl_;
164
166 std::string clusterset_id_;
167 std::vector<std::string> metadata_servers_;
168 uint64_t view_id_{0};
169
170 bool changed_{false};
171
173};
174
175#endif // CLUSTER_METADATA_DYNAMIC_STATE_INCLUDED
ClusterMetadataDynamicState represents a dynamic state that the metadata cache module wants to persis...
Definition: cluster_metadata_dynamic_state.h:43
mysqlrouter::ClusterType cluster_type_
Definition: cluster_metadata_dynamic_state.h:172
std::vector< std::string > metadata_servers_
Definition: cluster_metadata_dynamic_state.h:167
std::unique_ptr< Pimpl > pimpl_
Definition: cluster_metadata_dynamic_state.h:162
std::string cluster_type_specific_id_
Definition: cluster_metadata_dynamic_state.h:165
std::string clusterset_id_
Definition: cluster_metadata_dynamic_state.h:166
virtual ~ClusterMetadataDynamicState()
Destructor.
DynamicState represents a MySQLRouter dynamic state object.
Definition: dynamic_state.h:64
static stdx::expected< std::string, std::error_code > get_clusterset_id(mysqlrouter::MySQLSession &session, const mysqlrouter::TargetCluster &target_cluster)
Definition: cluster_metadata_gr.cc:1127
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:308
Definition: common.h:42
ClusterType
Definition: cluster_metadata.h:141
#define ROUTER_LIB_EXPORT
Definition: router_export.h:15
Definition: cluster_metadata_dynamic_state.cc:49
static void set_view_id(void *const context, const char &value, size_t length)
Definition: table_replication_group_member_stats.cc:60