MySQL 8.0.39
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
37
38/* The possible policies used on recovery when applying cached transactions */
41 0, // Wait for the certification of transactions
42 RECOVERY_POLICY_WAIT_EXECUTED, // Wait for the execution of transactions
43};
44
46 public:
47 /**
48 Recovery_module constructor
49
50 @param applier
51 reference to the applier
52 @param channel_obsr_mngr
53 reference to the channel hooks observation manager
54 */
56 Channel_observation_manager *channel_obsr_mngr);
57
59
61 applier_module = applier;
62 }
63
64 /**
65 Starts the recovery process, initializing the recovery thread.
66 This method is designed to be as light as possible, as if it involved any
67 major computation or wait process that would block the view change process
68 delaying the group.
69
70 @note this method only returns when the recovery thread is already running
71
72 @param group_name the joiner's group name
73 @param rec_view_id the new view id
74
75 @return the operation status
76 @retval 0 OK
77 @retval !=0 Error
78 */
79 int start_recovery(const std::string &group_name,
80 const std::string &rec_view_id);
81
82 /**
83 Recovery thread main execution method.
84
85 Here, the donor is selected, the connection to the donor is established,
86 and several safe keeping assurances are guaranteed, such as the applier
87 being suspended.
88 */
90
91 /**
92 Set retrieved certification info from a group replication channel extracted
93 from a given View_change event.
94
95 @param info the given view_change_event
96
97 @return the operation status
98 @retval 0 OK
99 @retval !=0 Error
100 */
101 int set_retrieved_cert_info(void *info);
102
103 /**
104 Stops the recovery process, shutting down the recovery thread.
105 If the thread does not stop in a user designated time interval, a timeout
106 is issued.
107
108 @param wait_for_termination wait for thread termination or not
109
110 @note this method only returns when the thread is stopped or on timeout
111
112 @return the operation status
113 @retval 0 OK
114 @retval !=0 Timeout
115 */
116 int stop_recovery(bool wait_for_termination = true);
117
118 /**
119 This method decides what action to take when a member exits the group and
120 executes it.
121 It can for the joiner:
122 If it exited, then terminate the recovery process.
123 If the donor left, and the state transfer is still ongoing, then pick a
124 new one and restart the transfer.
125
126 @param did_members_left states if members left the view
127 @param is_leaving true if the member is leaving the group
128
129 @return the operation status
130 @retval 0 OK
131 @retval !=0 Error
132 */
133 int update_recovery_process(bool did_members_left, bool is_leaving);
134
135 // Methods for variable updates
136
137 /** Sets the number of times recovery tries to connect to a given donor. */
138 void set_recovery_donor_retry_count(ulong retry_count) {
140 }
141
142 /** Sets the sleep time between connection attempts to all possible donors */
143 void set_recovery_donor_reconnect_interval(ulong reconnect_interval) {
145 reconnect_interval);
146 }
147
148 /**
149 Sets all the SSL option to use on recovery.
150
151 @param use_ssl force the use of SSL on recovery connections
152 @param ssl_ca SSL trusted certificate authorities file
153 @param ssl_capath a directory with trusted CA files
154 @param ssl_cert the certificate file for secure connections
155 @param ssl_cipher the list of ciphers to use
156 @param ssl_key the SSL key file
157 @param ssl_crl SSL revocation list file
158 @param ssl_crlpath path with revocation list files
159 @param ssl_verify_server_cert verify the hostname against the certificate
160 @param tls_version the list of TLS versions to use
161 @param tls_ciphersuites the list of TLS ciphersuites to use
162 */
163 void set_recovery_ssl_options(bool use_ssl, const char *ssl_ca,
164 const char *ssl_capath, const char *ssl_cert,
165 const char *ssl_cipher, const char *ssl_key,
166 const char *ssl_crl, const char *ssl_crlpath,
167 bool ssl_verify_server_cert, char *tls_version,
168 char *tls_ciphersuites) {
170 if (ssl_ca != nullptr) recovery_state_transfer.set_recovery_ssl_ca(ssl_ca);
171 if (ssl_capath != nullptr)
173 if (ssl_cert != nullptr)
175 if (ssl_cipher != nullptr)
177 if (ssl_key != nullptr)
179 if (ssl_crl != nullptr)
181 if (ssl_crlpath != nullptr)
185 if (tls_version != nullptr)
188 }
189
190 /** Set the option that forces the use of SSL on recovery connections */
191 void set_recovery_use_ssl(char use_ssl) {
193 }
194
195 /** Set a SSL trusted certificate authorities file */
196 void set_recovery_ssl_ca(const char *ssl_ca) {
198 }
199
200 /** Set a folder with SSL trusted CA files */
201 void set_recovery_ssl_capath(const char *ssl_capath) {
203 }
204
205 /** Set a SSL certificate for connection */
206 void set_recovery_ssl_cert(const char *ssl_cert) {
208 }
209
210 /** Set a SSL ciphers to be used */
211 void set_recovery_ssl_cipher(const char *ssl_cipher) {
213 }
214
215 /** Set a SSL key for connections */
216 void set_recovery_ssl_key(const char *ssl_key) {
218 }
219
220 /** Set a SSL revocation list file*/
221 void set_recovery_ssl_crl(const char *ssl_crl) {
223 }
224
225 /** Set a folder with SSL revocation list files*/
226 void set_recovery_ssl_crlpath(const char *ssl_crlpath) {
228 }
229
230 /** Set if recovery shall compare the used hostname against the certificate */
234 }
235
236 /** Set TLS version to be used */
237 void set_recovery_tls_version(const char *tls_version) {
239 }
240
241 /** Set TLS ciphersuites to be used */
242 void set_recovery_tls_ciphersuites(const char *tls_ciphersuites) {
244 }
245
246 /**
247 @return Is recovery configured to use SSL
248 */
251 }
252
253 /**
254 Get SSL options configured for recovery
255
256 @param[out] ssl_ca the ssl ca
257 @param[out] ssl_cert the ssl cert
258 @param[out] ssl_key the ssl key
259 */
260 void get_recovery_base_ssl_options(std::string *ssl_ca, std::string *ssl_cert,
261 std::string *ssl_key) {
263 ssl_key);
264 }
265 /**
266 Sets the recovery shutdown timeout.
267
268 @param[in] timeout the timeout
269 */
272 }
273
274 /**
275 Sets recovery threshold policy on what to wait when handling transactions
276 @param completion_policy if recovery shall wait for execution
277 or certification
278 */
280 enum_recovery_completion_policies completion_policy) {
281 this->recovery_completion_policy = completion_policy;
282 }
283
284 /** Set a public key file*/
285 void set_recovery_public_key_path(const char *public_key_path) {
286 if (public_key_path != nullptr)
288 }
289
290 /** Get public key automatically */
293 }
294
295 /** Set compression algorithm */
298 }
299
300 /** Set compression level */
303 }
304
305 /**
306 Checks if the given id matches the recovery applier thread
307 @param id the thread id
308
309 @return if it belongs to a thread
310 @retval true the id matches a SQL or worker thread
311 @retval false the id doesn't match any thread
312 */
314
315 /**
316 Checks to see if the recovery IO/SQL thread is still running, probably caused
317 by an timeout on shutdown.
318 If the threads are still running, we try to stop them again.
319 If not possible, an error is reported.
320
321 @return are the threads stopped
322 @retval 0 All is stopped.
323 @retval !=0 Threads are still running
324 */
326
327 private:
328 /** Sets the thread context */
330
331 /**
332 Handles code for removing the member in case of a failure during
333 recovery.
334 */
336
337 /** Cleans the recovery thread related options/structures. */
339
340 /**
341 Starts a wait process until the applier fulfills the necessary condition for
342 the member to be acknowledge as being online.
343
344 @return the operation status
345 @retval 0 OK
346 @retval !=0 Error
347 */
349
350 /**
351 Sends a message throughout the group stating the member as online.
352 */
354
355 // recovery thread variables
358
359 /* The plugin's applier module interface*/
361
362 /* The group to which the recovering member belongs */
363 std::string group_name;
364
365 /* The recovery state transfer class */
367
368 /* Recovery thread state */
370 /* Recovery abort flag */
372
373 // run conditions and locks
376
377 /* Recovery strategy when waiting for the cache transaction handling*/
379
380 /* The return value from state transfer operation*/
382};
383
384#endif /* RECOVERY_INCLUDE */
Definition: applier.h:240
A class to register observers for channel state events.
Definition: channel_observation_manager.h:131
Definition: recovery.h:45
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery.h:226
void set_recovery_get_public_key(bool set)
Get public key automatically.
Definition: recovery.h:291
mysql_cond_t run_cond
Definition: recovery.h:375
void set_recovery_thread_context()
Sets the thread context.
Definition: recovery.cc:450
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery.h:211
int start_recovery(const std::string &group_name, const std::string &rec_view_id)
Starts the recovery process, initializing the recovery thread.
Definition: recovery.cc:71
std::string group_name
Definition: recovery.h:363
thread_state recovery_thd_state
Definition: recovery.h:369
void notify_group_recovery_end()
Sends a message throughout the group stating the member as online.
Definition: recovery.cc:571
bool is_own_event_channel(my_thread_id id)
Checks if the given id matches the recovery applier thread.
Definition: recovery.cc:583
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:138
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:425
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:231
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery.h:201
void clean_recovery_thread_context()
Cleans the recovery thread related options/structures.
Definition: recovery.cc:464
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:163
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery.h:270
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery.h:285
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:588
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery.h:216
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set TLS ciphersuites to be used.
Definition: recovery.h:242
void set_applier_module(Applier_module_interface *applier)
Definition: recovery.h:60
void set_recovery_use_ssl(char use_ssl)
Set the option that forces the use of SSL on recovery connections.
Definition: recovery.h:191
void set_recovery_donor_reconnect_interval(ulong reconnect_interval)
Sets the sleep time between connection attempts to all possible donors.
Definition: recovery.h:143
Applier_module_interface * applier_module
Definition: recovery.h:360
void leave_group_on_recovery_failure()
Handles code for removing the member in case of a failure during recovery.
Definition: recovery.cc:158
my_thread_handle recovery_pthd
Definition: recovery.h:356
~Recovery_module()
Definition: recovery.cc:66
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery.h:206
Recovery_state_transfer recovery_state_transfer
Definition: recovery.h:366
THD * recovery_thd
Definition: recovery.h:357
int stop_recovery(bool wait_for_termination=true)
Stops the recovery process, shutting down the recovery thread.
Definition: recovery.cc:105
bool get_recovery_use_ssl()
Definition: recovery.h:249
void set_recovery_tls_version(const char *tls_version)
Set TLS version to be used.
Definition: recovery.h:237
Recovery_module(Applier_module_interface *applier, Channel_observation_manager *channel_obsr_mngr)
Recovery_module constructor.
Definition: recovery.cc:53
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:260
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery.h:296
void set_recovery_completion_policy(enum_recovery_completion_policies completion_policy)
Sets recovery threshold policy on what to wait when handling transactions.
Definition: recovery.h:279
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:469
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:401
mysql_mutex_t run_lock
Definition: recovery.h:374
State_transfer_status m_state_transfer_return
Definition: recovery.h:381
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery.h:301
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery.h:196
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery.h:221
int recovery_thread_handle()
Recovery thread main execution method.
Definition: recovery.cc:211
bool recovery_aborted
Definition: recovery.h:371
enum_recovery_completion_policies recovery_completion_policy
Definition: recovery.h:378
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:84
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:79
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery_state_transfer.h:131
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery_state_transfer.h:141
void set_recovery_tls_version(const char *tls_version)
Set a TLS versions to be used.
Definition: recovery_state_transfer.h:166
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery_state_transfer.h:126
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:123
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery_state_transfer.h:136
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set a TLS ciphersuites to be used.
Definition: recovery_state_transfer.h:171
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery_state_transfer.h:226
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery_state_transfer.h:146
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery_state_transfer.h:151
void set_recovery_get_public_key(bool set)
Get preference to get public key.
Definition: recovery_state_transfer.h:218
bool get_recovery_use_ssl()
Definition: recovery_state_transfer.h:184
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery_state_transfer.h:205
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery_state_transfer.h:210
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery_state_transfer.h:156
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:193
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:161
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery_state_transfer.h:221
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
uint32 my_thread_id
Definition: my_thread_local.h:34
Log info(cout, "NOTE")
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2882
enum_recovery_completion_policies
Definition: recovery.h:39
@ RECOVERY_POLICY_WAIT_CERTIFIED
Definition: recovery.h:40
@ RECOVERY_POLICY_WAIT_EXECUTED
Definition: recovery.h:42
enum st_state_transfer_status State_transfer_status
case opt name
Definition: sslopt-case.h:33
Definition: my_thread_bits.h:52
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:47
unsigned int uint
Definition: uca9-dump.cc:75
int ssl_verify_server_cert(SSL *ssl, const char *server_hostname)