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