MySQL 8.0.39
Source Code Documentation
gcs_operations.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
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, version 2.0, 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#ifndef GCS_OPERATIONS_INCLUDE
25#define GCS_OPERATIONS_INCLUDE
26
28#include <atomic>
29#include <future>
30#include <string>
31#include <utility>
32
39// TODO::change this for something more elegant
41
44
45/**
46 @class Gcs_operations
47 Coordinates all operations to GCS interface.
48*/
50 public:
51 /**
52 @enum enum_leave_state
53
54 This enumeration describes the return values when a process tries to leave
55 a group.
56 */
58 /* The request was accepted, the member should now be leaving. */
60 /* The member is already leaving, no point in retrying */
62 /* The member already left */
64 /* There was an error when trying to leave */
66 };
67
68 /**
69 @enum enum_force_members_state
70
71 This enumeration describes the return value when forces a new group
72 membership
73 */
75 /* OK. The forced new group membership is successful */
77 /* Error. The member is not ONLINE */
79 /*
80 Error. The member is not ONLINE and majority of the members are
81 unreachable.
82 */
84 /* Error. The member is leaving the group */
86 /* Timeout on wait for view after setting group_replication_force_members */
88 /* Error setting group_replication_force_members value */
90 /* Internal Error while setting group_replication_force_members */
92 };
93
94 /**
95 Default constructor.
96 */
98
99 /**
100 Destructor.
101 */
102 virtual ~Gcs_operations();
103
104 /**
105 Initialize the GCS interface.
106
107 @return the operation status
108 @retval 0 OK
109 @retval !=0 Error
110 */
111 int initialize();
112
113 /**
114 Finalize the GCS interface.
115 */
116 void finalize();
117
118 /**
119 Get the group current view.
120
121 @return a copy of the group current view.
122 NULL if member does not belong to a group..
123 The return value must deallocated by the caller.
124 */
126
127 /**
128 Configure the GCS interface.
129
130 @param[in] parameters The configuration parameters
131
132 @return the operation status
133 @retval 0 OK
134 @retval !=0 Error
135 */
136 enum enum_gcs_error configure(const Gcs_interface_parameters &parameters);
137
138 /**
139 Reconfigure the GCS interface, i.e. update its configuration parameters.
140
141 @param[in] parameters The configuration parameters
142
143 @return the operation status
144 @retval 0 OK
145 @retval !=0 Error
146 */
148
149 /**
150 Configure the debug options that shall be used by GCS.
151
152 @param debug_options Set of debug options separated by comma
153
154 @return the operation status
155 @retval 0 OK
156 @retval !=0 Error
157 */
158 enum enum_gcs_error set_debug_options(std::string &debug_options) const;
159
160 /**
161 Request server to join the group.
162
163 @param[in] communication_event_listener The communication event listener
164 @param[in] control_event_listener The control event listener
165 @param[in] view_notifier A view change notifier to know the response
166
167
168 @return the operation status
169 @retval 0 OK
170 @retval !=0 Error
171 */
172 enum enum_gcs_error join(
173 const Gcs_communication_event_listener &communication_event_listener,
174 const Gcs_control_event_listener &control_event_listener,
176
177 /**
178 Returns true if this server belongs to the group.
179 */
180 bool belongs_to_group();
181
182 /**
183 Request GCS interface to leave the group.
184
185 @param[in] view_notifier A view change notifier to know the response.
186 Pass a null pointer if you don't want to wait
187
188 Note: This method only asks to leave, it does not know if request was
189 successful
190
191 @return the operation status
192 @retval NOW_LEAVING Request accepted, the member is leaving
193 @retval ALREADY_LEAVING The member is already leaving
194 @retval ALREADY_LEFT The member already left
195 @retval ERROR_WHEN_LEAVING An error happened when trying to leave
196 */
198
199 /**
200 Notify all listeners that a view changed.
201 */
203
204 /**
205 Notify all listeners that a view was canceled.
206
207 @param[in] errnr The error associated to this view
208 */
211
212 /**
213 Checks if the view modification is a injected one.
214
215 @retval true if the current view modification is a injected one
216 @retval false otherwise
217 */
219
220 /**
221 Removes the notifier from the list
222 */
225
226 /**
227 Declare the member as being already out of the group.
228 */
230
231 /**
232 Get the local member identifier.
233
234 @param[out] identifier The local member identifier when the
235 method is successful
236
237 @return Operation status
238 @retval 0 OK
239 @retval !=0 Error
240 */
241 int get_local_member_identifier(std::string &identifier);
242
243 /**
244 Send a message to the group.
245
246 @param[in] message The message to send
247 @param[in] skip_if_not_initialized If true, the message will not be sent
248 and no errors will returned when the
249 GCS interface is not initialized
250
251 @return the operation status
252 @retval 0 OK
253 @retval !=0 Error
254 */
256 bool skip_if_not_initialized = false);
257
258 /**
259 Send a transaction message to the group.
260
261 @param[in] message The message to send
262
263 @return the operation status
264 @retval 0 OK
265 @retval !=0 Error
266 */
269
270 /**
271 Forces a new group membership, on which the excluded members
272 will not receive a new view and will be blocked.
273
274 @param members The list of members, comma
275 separated. E.g., host1:port1,host2:port2
276
277 @return Operation status
278 @retval FORCE_MEMBERS_OK The forced new group membership is
279 successful.
280 @retval FORCE_MEMBERS_ER_MEMBER_NOT_ONLINE
281 An error as member is not ONLINE,
282 when forcing a new group membership.
283 @retval FORCE_MEMBERS_NOT_ONLINE_AND_MAJORITY_UNREACHABLE
284 An error as member is not ONLINE and
285 majority of the members are
286 unreachable.
287 @retval FORCE_MEMBERS_ER_MEMBERS_WHEN_LEAVING
288 An error as member leaving group,
289 when forcing new group membership.
290 @retval FORCE_MEMBERS_ER_TIMEOUT_ON_WAIT_FOR_VIEW
291 A timeout happened when waiting for
292 view after setting
293 group_replication_force_members.
294 @retval FORCE_MEMBERS_VALUE_SET_ERROR
295 Error setting
296 group_replication_force_members value.
297 @retval FORCE_MEMBERS_INTERNAL_ERROR Internal error.
298 */
299 enum enum_force_members_state force_members(const char *members);
300
301 /**
302 Retrieves the minimum supported "write concurrency" value.
303 */
304 uint32_t get_minimum_write_concurrency() const;
305
306 /**
307 Retrieves the maximum supported "write concurrency" value.
308 */
309 uint32_t get_maximum_write_concurrency() const;
310
311 /**
312 Retrieves the group's "write concurrency" value.
313
314 @param[out] write_concurrency A reference to where the group's "write
315 concurrency" will be written to
316
317 @retval GCS_OK if successful
318 @retval GCS_NOK if unsuccessful
319 */
320 enum enum_gcs_error get_write_concurrency(uint32_t &write_concurrency);
321
322 /**
323 Reconfigures the group's "write concurrency" value.
324
325 The caller should ensure that the supplied value is between @c
326 minimum_write_concurrency and @c maximum_write_concurrency.
327
328 The method is non-blocking, meaning that it shall only send the
329 request to an underlying GCS. The final result can be polled via @c
330 get_write_concurrency.
331
332 @param new_write_concurrency The desired "write concurrency" value.
333
334 @retval GCS_OK if successful
335 @retval GCS_NOK if unsuccessful
336 */
337 enum enum_gcs_error set_write_concurrency(uint32_t new_write_concurrency);
338
339 /**
340 * @brief Reconfigures the group's "consensus leaders."
341 *
342 * Instructs the underlying GCS to use @c leader as the single preferred
343 * consensus leader.
344 *
345 * The method is non-blocking, meaning that it shall only send the
346 * request to an underlying GCS. The final result can be polled via @c
347 * get_leaders.
348 *
349 * @param leader The member you desire to act as a consensus leader.
350 *
351 * @retval GCS_OK if successful
352 * @retval GCS_NOK if unsuccessful
353 */
355
356 /**
357 * @brief Reconfigures the group's "consensus leaders."
358 *
359 * Instructs the underlying GCS to use every member as a consensus leader.
360 *
361 * The method is non-blocking, meaning that it shall only send the
362 * request to an underlying GCS. The final result can be polled via @c
363 * get_leaders.
364 *
365 * @retval GCS_OK if successful
366 * @retval GCS_NOK if unsuccessful
367 */
369
370 /**
371 * @brief Inspect the group's "consensus leader" configuration.
372 *
373 * @param[out] preferred_leaders The members specified as preferred leaders.
374 * @param[out] actual_leaders The members actually carrying out the leader
375 * role at this moment.
376 *
377 * @retval GCS_OK if successful, @c preferred_leaders and @c actual_leaders
378 * contain the result
379 * @retval GCS_NOK if unsuccessful
380 */
382 std::vector<Gcs_member_identifier> &preferred_leaders,
383 std::vector<Gcs_member_identifier> &actual_leaders);
384
385 /**
386 Retrieves the group's "group communication protocol" value.
387
388 @retval the protocol version
389 */
391
392 /**
393 Modifies the GCS protocol version in use.
394
395 The method is non-blocking. It returns a future on which the caller can
396 wait for the action to finish.
397
398 @param gcs_protocol The desired GCS protocol version
399
400 @retval {true, future} If successful
401 @retval {false, _} If unsuccessful because @c new_version is unsupported
402 */
403 std::pair<bool, std::future<void>> set_protocol_version(
404 Gcs_protocol_version gcs_protocol);
405
406 /**
407 Get the maximum protocol version currently supported by the group.
408
409 @returns the maximum protocol version currently supported by the group
410 */
412
413 /**
414 Requests GCS to change the maximum size of the XCom cache.
415
416 @param new_size The new maximum size of the XCom cache.
417
418 @retval GCS_OK if request successfully scheduled
419 @retval GCS_NOK if GCS is unable to schedule the request
420 */
421 enum enum_gcs_error set_xcom_cache_size(uint64_t new_size);
422
423 /**
424 * @brief Get the current incoming connections protocol stack configured in
425 * GCS
426 *
427 * @return GcsRunningProtocol
428 */
430
431 /**
432 * @brief Get the mysql network provider owned by GCS operations
433 *
434 * @return a Network_provider if initialized and running. nullptr, otherwise.
435 */
437
438 /**
439 * @return the communication engine being used
440 */
441 static const std::string &get_gcs_engine();
442
443 /**
444 Returns a flag indicating whether or not the component is initialized.
445
446 @retval true if the component is initialized.
447 @retval false otherwise.
448 */
449 bool is_initialized();
450
451 private:
452 /**
453 Internal function that configures the debug options that shall be used by
454 GCS.
455 */
456 enum enum_gcs_error do_set_debug_options(std::string &debug_options) const;
459
460 static const std::string gcs_engine;
462
463 /**
464 * External IoC dependencies for gcs_mysql_net_provider.
465 * - A provider for authentication parameters
466 * - A provider for all mysql native methods
467 */
470 std::shared_ptr<Gcs_mysql_network_provider> gcs_mysql_net_provider;
471
473
474 /** Was this view change injected */
476 /** Is the member leaving*/
477 std::atomic<bool> leave_coordination_leaving;
478 /** Did the member already left*/
479 std::atomic<bool> leave_coordination_left;
480
481 /** List of associated view change notifiers waiting */
482 std::list<Plugin_gcs_view_modification_notifier *> view_change_notifier_list;
483
485 /** Lock for the list of waiters on a view change */
487};
488
489#endif /* GCS_OPERATIONS_INCLUDE */
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:309
This interface is implemented by those who wish to receive messages.
Definition: gcs_communication_event_listener.h:36
This interface represents all the communication facilities that a binding implementation should provi...
Definition: gcs_communication_interface.h:90
This interface is implemented by those who wish to receive Control Interface notifications.
Definition: gcs_control_event_listener.h:52
Group Replication implementation of Logger_interface.
Definition: gcs_logger.h:36
Definition: gcs_group_management_interface.h:32
This class is to be used to provide parameters to bindings in a transparent and generic way.
Definition: gcs_types.h:59
This interface must be implemented by all specific binding implementations as its entry point.
Definition: gcs_interface.h:101
It represents the identity of a group member within a certain group.
Definition: gcs_member_identifier.h:40
Implementation of Gcs_mysql_network_provider_auth_interface that retrieves auth data from MySQL.
Definition: gcs_mysql_network_provider.h:70
Internal implementation of Gcs_mysql_network_provider_native_interface_impl that serves as a proxy fo...
Definition: gcs_mysql_network_provider.h:216
Implementation of a.
Definition: gcs_mysql_network_provider.h:297
Coordinates all operations to GCS interface.
Definition: gcs_operations.h:49
enum enum_force_members_state force_members(const char *members)
Forces a new group membership, on which the excluded members will not receive a new view and will be ...
Definition: gcs_operations.cc:491
Gcs_group_management_interface * get_gcs_group_manager() const
Definition: gcs_operations.cc:573
bool is_initialized()
Returns a flag indicating whether or not the component is initialized.
Definition: gcs_operations.cc:815
static const std::string gcs_engine
Definition: gcs_operations.h:460
int get_local_member_identifier(std::string &identifier)
Get the local member identifier.
Definition: gcs_operations.cc:383
std::pair< bool, std::future< void > > set_protocol_version(Gcs_protocol_version gcs_protocol)
Modifies the GCS protocol version in use.
Definition: gcs_operations.cc:746
enum enum_gcs_error set_write_concurrency(uint32_t new_write_concurrency)
Reconfigures the group's "write concurrency" value.
Definition: gcs_operations.cc:614
Checkable_rwlock * view_observers_lock
Lock for the list of waiters on a view change.
Definition: gcs_operations.h:486
Gcs_view * get_current_view()
Get the group current view.
Definition: gcs_operations.cc:364
enum enum_gcs_error configure(const Gcs_interface_parameters &parameters)
Configure the GCS interface.
Definition: gcs_operations.cc:129
enum enum_gcs_error join(const Gcs_communication_event_listener &communication_event_listener, const Gcs_control_event_listener &control_event_listener, Plugin_gcs_view_modification_notifier *view_notifier)
Request server to join the group.
Definition: gcs_operations.cc:199
Gcs_protocol_version get_protocol_version()
Retrieves the group's "group communication protocol" value.
Definition: gcs_operations.cc:722
enum enum_gcs_error send_transaction_message(Transaction_message_interface &message)
Send a transaction message to the group.
Definition: gcs_operations.cc:449
enum enum_gcs_error get_leaders(std::vector< Gcs_member_identifier > &preferred_leaders, std::vector< Gcs_member_identifier > &actual_leaders)
Inspect the group's "consensus leader" configuration.
Definition: gcs_operations.cc:654
void leave_coordination_member_left()
Declare the member as being already out of the group.
Definition: gcs_operations.cc:357
Gcs_communication_interface * get_gcs_communication() const
Definition: gcs_operations.cc:693
enum enum_gcs_error set_xcom_cache_size(uint64_t new_size)
Requests GCS to change the maximum size of the XCom cache.
Definition: gcs_operations.cc:763
uint32_t get_minimum_write_concurrency() const
Retrieves the minimum supported "write concurrency" value.
Definition: gcs_operations.cc:669
enum_leave_state
This enumeration describes the return values when a process tries to leave a group.
Definition: gcs_operations.h:57
@ ERROR_WHEN_LEAVING
Definition: gcs_operations.h:65
@ ALREADY_LEFT
Definition: gcs_operations.h:63
@ ALREADY_LEAVING
Definition: gcs_operations.h:61
@ NOW_LEAVING
Definition: gcs_operations.h:59
bool is_injected_view_modification()
Checks if the view modification is a injected one.
Definition: gcs_operations.cc:341
enum enum_gcs_error set_everyone_leader()
Reconfigures the group's "consensus leaders.".
Definition: gcs_operations.cc:641
std::atomic< bool > leave_coordination_left
Did the member already left.
Definition: gcs_operations.h:479
static const std::string & get_gcs_engine()
Definition: gcs_operations.cc:813
enum enum_gcs_error set_debug_options(std::string &debug_options) const
Configure the debug options that shall be used by GCS.
Definition: gcs_operations.cc:186
enum enum_gcs_error set_leader(Gcs_member_identifier const &leader)
Reconfigures the group's "consensus leaders.".
Definition: gcs_operations.cc:627
std::shared_ptr< Gcs_mysql_network_provider > gcs_mysql_net_provider
Definition: gcs_operations.h:470
Gcs_operations()
Default constructor.
Definition: gcs_operations.cc:36
Gcs_gr_logger_impl gcs_logger
Definition: gcs_operations.h:461
void notify_of_view_change_end()
Notify all listeners that a view changed.
Definition: gcs_operations.cc:323
Gcs_mysql_network_provider * get_mysql_network_provider()
Get the mysql network provider owned by GCS operations.
Definition: gcs_operations.cc:799
void remove_view_notifer(Plugin_gcs_view_modification_notifier *view_notifier)
Removes the notifier from the list.
Definition: gcs_operations.cc:348
Gcs_mysql_network_provider_native_interface_impl native_interface
Definition: gcs_operations.h:469
void notify_of_view_change_cancellation(int errnr=GROUP_REPLICATION_CONFIGURATION_ERROR)
Notify all listeners that a view was canceled.
Definition: gcs_operations.cc:332
void finalize()
Finalize the GCS interface.
Definition: gcs_operations.cc:107
enum enum_gcs_error do_set_debug_options(std::string &debug_options) const
Internal function that configures the debug options that shall be used by GCS.
Definition: gcs_operations.cc:162
enum enum_gcs_error get_write_concurrency(uint32_t &write_concurrency)
Retrieves the group's "write concurrency" value.
Definition: gcs_operations.cc:601
enum_force_members_state
This enumeration describes the return value when forces a new group membership.
Definition: gcs_operations.h:74
@ FORCE_MEMBERS_ER_VALUE_SET_ERROR
Definition: gcs_operations.h:89
@ FORCE_MEMBERS_ER_TIMEOUT_ON_WAIT_FOR_VIEW
Definition: gcs_operations.h:87
@ FORCE_MEMBERS_ER_MEMBER_NOT_ONLINE
Definition: gcs_operations.h:78
@ FORCE_MEMBERS_ER_NOT_ONLINE_AND_MAJORITY_UNREACHABLE
Definition: gcs_operations.h:83
@ FORCE_MEMBERS_ER_INTERNAL_ERROR
Definition: gcs_operations.h:91
@ FORCE_MEMBERS_ER_MEMBERS_WHEN_LEAVING
Definition: gcs_operations.h:85
@ FORCE_MEMBERS_OK
Definition: gcs_operations.h:76
std::list< Plugin_gcs_view_modification_notifier * > view_change_notifier_list
List of associated view change notifiers waiting.
Definition: gcs_operations.h:482
bool belongs_to_group()
Returns true if this server belongs to the group.
Definition: gcs_operations.cc:252
Checkable_rwlock * gcs_operations_lock
Definition: gcs_operations.h:484
Gcs_protocol_version get_maximum_protocol_version()
Get the maximum protocol version currently supported by the group.
Definition: gcs_operations.cc:734
enum enum_gcs_error send_message(const Plugin_gcs_message &message, bool skip_if_not_initialized=false)
Send a message to the group.
Definition: gcs_operations.cc:405
std::atomic< bool > leave_coordination_leaving
Is the member leaving.
Definition: gcs_operations.h:477
enum_leave_state leave(Plugin_gcs_view_modification_notifier *view_notifier)
Request GCS interface to leave the group.
Definition: gcs_operations.cc:270
Gcs_mysql_network_provider_auth_interface_impl auth_provider
External IoC dependencies for gcs_mysql_net_provider.
Definition: gcs_operations.h:468
uint32_t get_maximum_write_concurrency() const
Retrieves the maximum supported "write concurrency" value.
Definition: gcs_operations.cc:681
virtual ~Gcs_operations()
Destructor.
Definition: gcs_operations.cc:56
enum_transport_protocol get_current_incoming_connections_protocol()
Get the current incoming connections protocol stack configured in GCS.
Definition: gcs_operations.cc:781
Gcs_interface * gcs_interface
Definition: gcs_operations.h:472
bool injected_view_modification
Was this view change injected.
Definition: gcs_operations.h:475
enum enum_gcs_error reconfigure(const Gcs_interface_parameters &parameters)
Reconfigure the GCS interface, i.e.
Definition: gcs_operations.cc:150
int initialize()
Initialize the GCS interface.
Definition: gcs_operations.cc:61
This represents the membership view that a member has from a group.
Definition: gcs_view.h:55
This is the base GCS plugin message.
Definition: gcs_plugin_messages.h:64
Definition: gcs_view_modification_notifier.h:36
Definition: transaction_message_interface.h:41
enum_gcs_error
This enumeration describes errors which can occur during group communication operations.
Definition: gcs_types.h:41
Gcs_protocol_version
The GCS protocol versions.
Definition: gcs_types.h:128
enum_transport_protocol
Enum that describes the available XCom Communication Stacks.
Definition: network_provider.h:45
#define GROUP_REPLICATION_CONFIGURATION_ERROR
Definition: plugin_constants.h:37