MySQL 9.1.0
Source Code Documentation
recovery.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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 RECOVERY_INCLUDE
25#define RECOVERY_INCLUDE
26
28#include <stddef.h>
29#include <list>
30#include <string>
31
38
40 public:
41 /* The error status for Recovery Metadata received. */
43 // Metadata received without error.
45 // Time-out waiting for Metadata.
47 // Recovery aborted.
49 // Error fetching metadata.
51 };
52
53 /**
54 Recovery_module constructor
55
56 @param applier
57 reference to the applier
58 @param channel_obsr_mngr
59 reference to the channel hooks observation manager
60 */
62 Channel_observation_manager *channel_obsr_mngr);
63
65
67 applier_module = applier;
68 }
69
70 /**
71 Starts the recovery process, initializing the recovery thread.
72 This method is designed to be as light as possible, as if it involved any
73 major computation or wait process that would block the view change process
74 delaying the group.
75
76 @note this method only returns when the recovery thread is already running
77
78 @param group_name the joiner's group name
79 @param view_id the view id to use for the recovery.
80
81 @return the operation status
82 @retval 0 OK
83 @retval !=0 Error
84 */
85 int start_recovery(const std::string &group_name, const std::string &view_id);
86
87 /**
88 Recovery thread main execution method.
89
90 Here, the donor is selected, the connection to the donor is established,
91 and several safe keeping assurances are guaranteed, such as the applier
92 being suspended.
93 */
95
96 /**
97 Set retrieved certification info from a group replication channel extracted
98 from a given View_change event.
99
100 @param info the given view_change_event
101
102 @return the operation status
103 @retval 0 OK
104 @retval !=0 Error
105 */
106 int set_retrieved_cert_info(void *info);
107
108 /**
109 Stops the recovery process, shutting down the recovery thread.
110 If the thread does not stop in a user designated time interval, a timeout
111 is issued.
112
113 @param wait_for_termination wait for thread termination or not
114
115 @note this method only returns when the thread is stopped or on timeout
116
117 @return the operation status
118 @retval 0 OK
119 @retval !=0 Timeout
120 */
121 int stop_recovery(bool wait_for_termination = true);
122
123 /**
124 This method decides what action to take when a member exits the group and
125 executes it.
126 It can for the joiner:
127 If it exited, then terminate the recovery process.
128 If the donor left, and the state transfer is still ongoing, then pick a
129 new one and restart the transfer.
130
131 @param did_members_left states if members left the view
132 @param is_leaving true if the member is leaving the group
133
134 @return the operation status
135 @retval 0 OK
136 @retval !=0 Error
137 */
138 int update_recovery_process(bool did_members_left, bool is_leaving);
139
140 // Methods for variable updates
141
142 /** Sets the number of times recovery tries to connect to a given donor. */
143 void set_recovery_donor_retry_count(ulong retry_count) {
145 }
146
147 /** Sets the sleep time between connection attempts to all possible donors */
148 void set_recovery_donor_reconnect_interval(ulong reconnect_interval) {
150 reconnect_interval);
151 }
152
153 /**
154 Sets all the SSL option to use on recovery.
155
156 @param use_ssl force the use of SSL on recovery connections
157 @param ssl_ca SSL trusted certificate authorities file
158 @param ssl_capath a directory with trusted CA files
159 @param ssl_cert the certificate file for secure connections
160 @param ssl_cipher the list of ciphers to use
161 @param ssl_key the SSL key file
162 @param ssl_crl SSL revocation list file
163 @param ssl_crlpath path with revocation list files
164 @param ssl_verify_server_cert verify the hostname against the certificate
165 @param tls_version the list of TLS versions to use
166 @param tls_ciphersuites the list of TLS ciphersuites to use
167 */
168 void set_recovery_ssl_options(bool use_ssl, const char *ssl_ca,
169 const char *ssl_capath, const char *ssl_cert,
170 const char *ssl_cipher, const char *ssl_key,
171 const char *ssl_crl, const char *ssl_crlpath,
172 bool ssl_verify_server_cert, char *tls_version,
173 char *tls_ciphersuites) {
175 if (ssl_ca != nullptr) recovery_state_transfer.set_recovery_ssl_ca(ssl_ca);
176 if (ssl_capath != nullptr)
178 if (ssl_cert != nullptr)
180 if (ssl_cipher != nullptr)
182 if (ssl_key != nullptr)
184 if (ssl_crl != nullptr)
186 if (ssl_crlpath != nullptr)
190 if (tls_version != nullptr)
193 }
194
195 /** Set the option that forces the use of SSL on recovery connections */
196 void set_recovery_use_ssl(char use_ssl) {
198 }
199
200 /** Set a SSL trusted certificate authorities file */
201 void set_recovery_ssl_ca(const char *ssl_ca) {
203 }
204
205 /** Set a folder with SSL trusted CA files */
206 void set_recovery_ssl_capath(const char *ssl_capath) {
208 }
209
210 /** Set a SSL certificate for connection */
211 void set_recovery_ssl_cert(const char *ssl_cert) {
213 }
214
215 /** Set a SSL ciphers to be used */
216 void set_recovery_ssl_cipher(const char *ssl_cipher) {
218 }
219
220 /** Set a SSL key for connections */
221 void set_recovery_ssl_key(const char *ssl_key) {
223 }
224
225 /** Set a SSL revocation list file*/
226 void set_recovery_ssl_crl(const char *ssl_crl) {
228 }
229
230 /** Set a folder with SSL revocation list files*/
231 void set_recovery_ssl_crlpath(const char *ssl_crlpath) {
233 }
234
235 /** Set if recovery shall compare the used hostname against the certificate */
239 }
240
241 /** Set TLS version to be used */
242 void set_recovery_tls_version(const char *tls_version) {
244 }
245
246 /** Set TLS ciphersuites to be used */
247 void set_recovery_tls_ciphersuites(const char *tls_ciphersuites) {
249 }
250
251 /**
252 @return Is recovery configured to use SSL
253 */
256 }
257
258 /**
259 Get SSL options configured for recovery
260
261 @param[out] ssl_ca the ssl ca
262 @param[out] ssl_cert the ssl cert
263 @param[out] ssl_key the ssl key
264 */
265 void get_recovery_base_ssl_options(std::string *ssl_ca, std::string *ssl_cert,
266 std::string *ssl_key) {
268 ssl_key);
269 }
270 /**
271 Sets the recovery shutdown timeout.
272
273 @param[in] timeout the timeout
274 */
277 }
278
279 /** Set a public key file*/
280 void set_recovery_public_key_path(const char *public_key_path) {
281 if (public_key_path != nullptr)
283 }
284
285 /** Get public key automatically */
288 }
289
290 /** Set compression algorithm */
293 }
294
295 /** Set compression level */
298 }
299
300 /**
301 Checks if the given id matches the recovery applier thread
302 @param id the thread id
303
304 @return if it belongs to a thread
305 @retval true the id matches a SQL or worker thread
306 @retval false the id doesn't match any thread
307 */
309
310 /**
311 Checks to see if the recovery IO/SQL thread is still running, probably caused
312 by an timeout on shutdown.
313 If the threads are still running, we try to stop them again.
314 If not possible, an error is reported.
315
316 @return are the threads stopped
317 @retval 0 All is stopped.
318 @retval !=0 Threads are still running
319 */
321
322 // Recovery Metadata related function and variables - start
323 /**
324 Awakes recovery thd, waiting for the donor to send recovery metadata.
325 If send recovery metadata fails it sets the error, so that waiting recovery
326 thd unblocks and stops with error, otherwise on successful receive of
327 recovery metadata it awakes waiting recovery thd without error.
328
329 @param error Error status in recovery metadata fetching.
330 */
331 void awake_recovery_metadata_suspension(bool error = false);
332
333 /**
334 Suspend recovery thd, so that member can wait to receive the recovery
335 metadata.
336 */
338
339 /**
340 Set the recovery metadata message.
341
342 @param[in] recovery_metadata_message the recovery metadata message pointer.
343
344 @return the error status
345 @retval true Error
346 @retval false Success
347 */
349 Recovery_metadata_message *recovery_metadata_message);
350
351 /**
352 Delete recovery metadata object.
353 */
355
356 /**
357 Return the flag which determine if VCLE is enabled.
358
359 @return the status which determine if VCLE is enabled.
360 */
361 bool is_vcle_enable();
362
363 /**
364 Set the View ID on which the joiner joined.
365
366 @param is_vcle_enabled the flag determine if View_change_log_event
367 is enabled.
368 */
369 void set_vcle_enabled(bool is_vcle_enabled);
370
371 private:
372 /** Flag to determine if recovery should use VCLE */
373 bool m_is_vcle_enable{false};
374
375 /** Recovery metadata received on group members. */
377
378 // Recovery Metadata related function and variables - end
379
380 /** Sets the thread context */
382
383 /**
384 Handles code for removing the member in case of a failure during
385 recovery.
386 */
388
389 /** Cleans the recovery thread related options/structures. */
391
392 /**
393 Starts a wait process until the applier fulfills the necessary condition for
394 the member to be acknowledge as being online.
395
396 @return the operation status
397 @retval 0 OK
398 @retval !=0 Error
399 */
401
402 /**
403 Sends a message throughout the group stating the member as online.
404 */
406
407 /**
408 Starts a wait process until the recovery metadata is successfully send by
409 the donor.
410
411 @return the error status. Check enum_recovery_metadata_error for details.
412 */
414
415 // recovery thread variables
418
419 /* The plugin's applier module interface*/
421
422 /* The group to which the recovering member belongs */
423 std::string group_name;
424
425 /* The recovery state transfer class */
427
428 /* Recovery thread state */
430 /* Recovery abort flag */
432
433 /*
434 The replication until condition that can be applied to
435 channels for the recovery.
436 */
438
439 /*
440 The maximum time till which recovery thread will wait for recovery metadata
441 from sender.
442 */
444
445 // run conditions and locks
448
449 /* The return value from state transfer operation*/
451
452 /* Recovery metadata receive status. */
454
455 /** Error while fetching Recovery metadata. */
457
458 /** Recovery metadata receive error status. */
460
461 // condition and lock used to suspend/awake the recovery module
462 /* The lock for suspending/wait for the awake of the recovery module */
464
465 /* The condition for suspending/wait for the awake of the recovery module */
467};
468
469#endif /* RECOVERY_INCLUDE */
Definition: applier.h:276
A class to register observers for channel state events.
Definition: channel_observation_manager.h:131
Definition: recovery_metadata_message.h:36
Definition: recovery.h:39
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery.h:231
void set_recovery_get_public_key(bool set)
Get public key automatically.
Definition: recovery.h:286
mysql_cond_t run_cond
Definition: recovery.h:447
mysql_mutex_t m_recovery_metadata_receive_lock
Definition: recovery.h:463
mysql_cond_t m_recovery_metadata_receive_waiting_condition
Definition: recovery.h:466
enum_channel_until_condition m_until_condition
Definition: recovery.h:437
enum_recovery_metadata_error m_recovery_metadata_error_status
Recovery metadata receive error status.
Definition: recovery.h:459
void set_recovery_thread_context()
Sets the thread context.
Definition: recovery.cc:649
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery.h:216
int start_recovery(const std::string &group_name, const std::string &view_id)
Starts the recovery process, initializing the recovery thread.
Definition: recovery.cc:87
std::string group_name
Definition: recovery.h:423
thread_state recovery_thd_state
Definition: recovery.h:429
void notify_group_recovery_end()
Sends a message throughout the group stating the member as online.
Definition: recovery.cc:759
bool m_recovery_metadata_received
Definition: recovery.h:453
enum_recovery_metadata_error wait_for_recovery_metadata_gtid_executed()
Starts a wait process until the recovery metadata is successfully send by the donor.
Definition: recovery.cc:786
bool is_own_event_channel(my_thread_id id)
Checks if the given id matches the recovery applier thread.
Definition: recovery.cc:771
void set_recovery_donor_retry_count(ulong retry_count)
Sets the number of times recovery tries to connect to a given donor.
Definition: recovery.h:143
int set_retrieved_cert_info(void *info)
Set retrieved certification info from a group replication channel extracted from a given View_change ...
Definition: recovery.cc:624
Recovery_metadata_message * m_recovery_metadata_message
Recovery metadata received on group members.
Definition: recovery.h:376
void set_recovery_ssl_verify_server_cert(char ssl_verify_server_cert)
Set if recovery shall compare the used hostname against the certificate.
Definition: recovery.h:236
bool m_recovery_metadata_received_error
Error while fetching Recovery metadata.
Definition: recovery.h:456
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery.h:206
void clean_recovery_thread_context()
Cleans the recovery thread related options/structures.
Definition: recovery.cc:663
unsigned int m_max_metadata_wait_time
Definition: recovery.h:443
void set_recovery_ssl_options(bool use_ssl, const char *ssl_ca, const char *ssl_capath, const char *ssl_cert, const char *ssl_cipher, const char *ssl_key, const char *ssl_crl, const char *ssl_crlpath, bool ssl_verify_server_cert, char *tls_version, char *tls_ciphersuites)
Sets all the SSL option to use on recovery.
Definition: recovery.h:168
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery.h:275
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery.h:280
void suspend_recovery_metadata()
Suspend recovery thd, so that member can wait to receive the recovery metadata.
Definition: recovery.cc:832
int check_recovery_thread_status()
Checks to see if the recovery IO/SQL thread is still running, probably caused by an timeout on shutdo...
Definition: recovery.cc:776
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery.h:221
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set TLS ciphersuites to be used.
Definition: recovery.h:247
enum_recovery_metadata_error
Definition: recovery.h:42
void set_applier_module(Applier_module_interface *applier)
Definition: recovery.h:66
void set_recovery_use_ssl(char use_ssl)
Set the option that forces the use of SSL on recovery connections.
Definition: recovery.h:196
void set_recovery_donor_reconnect_interval(ulong reconnect_interval)
Sets the sleep time between connection attempts to all possible donors.
Definition: recovery.h:148
Applier_module_interface * applier_module
Definition: recovery.h:420
void delete_recovery_metadata_message()
Delete recovery metadata object.
Definition: recovery.cc:850
void leave_group_on_recovery_failure()
Handles code for removing the member in case of a failure during recovery.
Definition: recovery.cc:185
my_thread_handle recovery_pthd
Definition: recovery.h:416
bool set_recovery_metadata_message(Recovery_metadata_message *recovery_metadata_message)
Set the recovery metadata message.
Definition: recovery.cc:839
~Recovery_module()
Definition: recovery.cc:79
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery.h:211
Recovery_state_transfer recovery_state_transfer
Definition: recovery.h:426
THD * recovery_thd
Definition: recovery.h:417
int stop_recovery(bool wait_for_termination=true)
Stops the recovery process, shutting down the recovery thread.
Definition: recovery.cc:129
bool get_recovery_use_ssl()
Definition: recovery.h:254
void set_recovery_tls_version(const char *tls_version)
Set TLS version to be used.
Definition: recovery.h:242
Recovery_module(Applier_module_interface *applier, Channel_observation_manager *channel_obsr_mngr)
Recovery_module constructor.
Definition: recovery.cc:61
void get_recovery_base_ssl_options(std::string *ssl_ca, std::string *ssl_cert, std::string *ssl_key)
Get SSL options configured for recovery.
Definition: recovery.h:265
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery.h:291
bool m_is_vcle_enable
Flag to determine if recovery should use VCLE.
Definition: recovery.h:373
int wait_for_applier_module_recovery()
Starts a wait process until the applier fulfills the necessary condition for the member to be acknowl...
Definition: recovery.cc:668
int update_recovery_process(bool did_members_left, bool is_leaving)
This method decides what action to take when a member exits the group and executes it.
Definition: recovery.cc:600
mysql_mutex_t run_lock
Definition: recovery.h:446
State_transfer_status m_state_transfer_return
Definition: recovery.h:450
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery.h:296
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery.h:201
bool is_vcle_enable()
Return the flag which determine if VCLE is enabled.
Definition: recovery.cc:857
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery.h:226
int recovery_thread_handle()
Recovery thread main execution method.
Definition: recovery.cc:258
void awake_recovery_metadata_suspension(bool error=false)
Awakes recovery thd, waiting for the donor to send recovery metadata.
Definition: recovery.cc:824
bool recovery_aborted
Definition: recovery.h:431
void set_vcle_enabled(bool is_vcle_enabled)
Set the View ID on which the joiner joined.
Definition: recovery.cc:859
Definition: recovery_state_transfer.h:45
void set_recovery_donor_reconnect_interval(ulong reconnect_interval)
Sets the sleep time between connection attempts to all possible donors.
Definition: recovery_state_transfer.h:94
void set_recovery_donor_retry_count(ulong retry_count)
Sets the number of times recovery tries to connect to a given donor.
Definition: recovery_state_transfer.h:89
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery_state_transfer.h:141
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery_state_transfer.h:151
void set_recovery_tls_version(const char *tls_version)
Set a TLS versions to be used.
Definition: recovery_state_transfer.h:176
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery_state_transfer.h:136
void set_recovery_use_ssl(char use_ssl)
Set the option that forces the use of SSL on recovery connections.
Definition: recovery_state_transfer.h:133
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery_state_transfer.h:146
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set a TLS ciphersuites to be used.
Definition: recovery_state_transfer.h:181
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery_state_transfer.h:236
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery_state_transfer.h:156
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery_state_transfer.h:161
void set_recovery_get_public_key(bool set)
Get preference to get public key.
Definition: recovery_state_transfer.h:228
bool get_recovery_use_ssl()
Definition: recovery_state_transfer.h:194
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery_state_transfer.h:215
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery_state_transfer.h:220
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery_state_transfer.h:166
void get_recovery_base_ssl_options(std::string *ssl_ca, std::string *ssl_cert, std::string *ssl_key)
Get SSL options configured for recovery.
Definition: recovery_state_transfer.h:203
void set_recovery_ssl_verify_server_cert(char ssl_verify_server_cert)
Set if recovery shall compare the used hostname against the certificate.
Definition: recovery_state_transfer.h:171
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery_state_transfer.h:231
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
uint32 my_thread_id
Definition: my_thread_local.h:34
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2884
enum st_state_transfer_status State_transfer_status
enum_channel_until_condition
The known until conditions that can be applied to channels.
Definition: rpl_channel_service_interface.h:134
@ CHANNEL_UNTIL_VIEW_ID
Definition: rpl_channel_service_interface.h:139
case opt name
Definition: sslopt-case.h:29
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:48
int ssl_verify_server_cert(SSL *ssl, const char *server_hostname)