MySQL  8.0.20
Source Code Documentation
recovery.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef RECOVERY_INCLUDE
24 #define RECOVERY_INCLUDE
25 
27 #include <stddef.h>
28 #include <list>
29 #include <string>
30 
36 
37 /* The possible policies used on recovery when applying cached transactions */
40  0, // Wait for the certification of transactions
41  RECOVERY_POLICY_WAIT_EXECUTED, // Wait for the execution of transactions
42 };
43 
45  public:
46  /**
47  Recovery_module constructor
48 
49  @param applier
50  reference to the applier
51  @param channel_obsr_mngr
52  reference to the channel hooks observation manager
53  @param components_stop_timeout
54  timeout value for the recovery module during shutdown.
55  */
57  Channel_observation_manager *channel_obsr_mngr,
58  ulong components_stop_timeout);
59 
61 
63  applier_module = applier;
64  }
65 
66  /**
67  Starts the recovery process, initializing the recovery thread.
68  This method is designed to be as light as possible, as if it involved any
69  major computation or wait process that would block the view change process
70  delaying the group.
71 
72  @note this method only returns when the recovery thread is already running
73 
74  @param group_name the joiner's group name
75  @param rec_view_id the new view id
76 
77  @return the operation status
78  @retval 0 OK
79  @retval !=0 Error
80  */
81  int start_recovery(const std::string &group_name,
82  const std::string &rec_view_id);
83 
84  /**
85  Recovery thread main execution method.
86 
87  Here, the donor is selected, the connection to the donor is established,
88  and several safe keeping assurances are guaranteed, such as the applier
89  being suspended.
90  */
92 
93  /**
94  Set retrieved certification info from a group replication channel extracted
95  from a given View_change event.
96 
97  @param info the given view_change_event
98 
99  @return the operation status
100  @retval 0 OK
101  @retval !=0 Error
102  */
103  int set_retrieved_cert_info(void *info);
104 
105  /**
106  Stops the recovery process, shutting down the recovery thread.
107  If the thread does not stop in a user designated time interval, a timeout
108  is issued.
109 
110  @param wait_for_termination wait for thread termination or not
111 
112  @note this method only returns when the thread is stopped or on timeout
113 
114  @return the operation status
115  @retval 0 OK
116  @retval !=0 Timeout
117  */
118  int stop_recovery(bool wait_for_termination = true);
119 
120  /**
121  This method decides what action to take when a member exits the group and
122  executes it.
123  It can for the joiner:
124  If it exited, then terminate the recovery process.
125  If the donor left, and the state transfer is still ongoing, then pick a
126  new one and restart the transfer.
127 
128  @param did_members_left states if members left the view
129  @param is_leaving true if the member is leaving the group
130 
131  @return the operation status
132  @retval 0 OK
133  @retval !=0 Error
134  */
135  int update_recovery_process(bool did_members_left, bool is_leaving);
136 
137  // Methods for variable updates
138 
139  /** Sets the number of times recovery tries to connect to a given donor. */
140  void set_recovery_donor_retry_count(ulong retry_count) {
142  }
143 
144  /** Sets the sleep time between connection attempts to all possible donors */
145  void set_recovery_donor_reconnect_interval(ulong reconnect_interval) {
147  reconnect_interval);
148  }
149 
150  /**
151  Sets all the SSL option to use on recovery.
152 
153  @param use_ssl force the use of SSL on recovery connections
154  @param ssl_ca SSL trusted certificate authorities file
155  @param ssl_capath a directory with trusted CA files
156  @param ssl_cert the certificate file for secure connections
157  @param ssl_cipher the list of ciphers to use
158  @param ssl_key the SSL key file
159  @param ssl_crl SSL revocation list file
160  @param ssl_crlpath path with revocation list files
161  @param ssl_verify_server_cert verify the hostname against the certificate
162  @param tls_version the list of TLS versions to use
163  @param tls_ciphersuites the list of TLS ciphersuites to use
164  */
165  void set_recovery_ssl_options(bool use_ssl, const char *ssl_ca,
166  const char *ssl_capath, const char *ssl_cert,
167  const char *ssl_cipher, const char *ssl_key,
168  const char *ssl_crl, const char *ssl_crlpath,
169  bool ssl_verify_server_cert, char *tls_version,
170  char *tls_ciphersuites) {
172  if (ssl_ca != nullptr) recovery_state_transfer.set_recovery_ssl_ca(ssl_ca);
173  if (ssl_capath != nullptr)
175  if (ssl_cert != nullptr)
177  if (ssl_cipher != nullptr)
179  if (ssl_key != nullptr)
181  if (ssl_crl != nullptr)
183  if (ssl_crlpath != nullptr)
186  ssl_verify_server_cert);
187  if (tls_version != nullptr)
190  }
191 
192  /** Set the option that forces the use of SSL on recovery connections */
193  void set_recovery_use_ssl(char use_ssl) {
195  }
196 
197  /** Set a SSL trusted certificate authorities file */
198  void set_recovery_ssl_ca(const char *ssl_ca) {
200  }
201 
202  /** Set a folder with SSL trusted CA files */
203  void set_recovery_ssl_capath(const char *ssl_capath) {
205  }
206 
207  /** Set a SSL certificate for connection */
208  void set_recovery_ssl_cert(const char *ssl_cert) {
210  }
211 
212  /** Set a SSL ciphers to be used */
213  void set_recovery_ssl_cipher(const char *ssl_cipher) {
215  }
216 
217  /** Set a SSL key for connections */
218  void set_recovery_ssl_key(const char *ssl_key) {
220  }
221 
222  /** Set a SSL revocation list file*/
223  void set_recovery_ssl_crl(const char *ssl_crl) {
225  }
226 
227  /** Set a folder with SSL revocation list files*/
228  void set_recovery_ssl_crlpath(const char *ssl_crlpath) {
230  }
231 
232  /** Set if recovery shall compare the used hostname against the certificate */
235  ssl_verify_server_cert);
236  }
237 
238  /** Set TLS version to be used */
239  void set_recovery_tls_version(const char *tls_version) {
241  }
242 
243  /** Set TLS ciphersuites to be used */
244  void set_recovery_tls_ciphersuites(const char *tls_ciphersuites) {
246  }
247 
248  /**
249  @return Is recovery configured to use SSL
250  */
253  }
254 
255  /**
256  Get SSL options configured for recovery
257 
258  @param[out] ssl_ca the ssl ca
259  @param[out] ssl_cert the ssl cert
260  @param[out] ssl_key the ssl key
261  */
262  void get_recovery_base_ssl_options(std::string *ssl_ca, std::string *ssl_cert,
263  std::string *ssl_key) {
265  ssl_key);
266  }
267  /**
268  Sets the recovery shutdown timeout.
269 
270  @param[in] timeout the timeout
271  */
272  void set_stop_wait_timeout(ulong timeout) {
273  stop_wait_timeout = timeout;
275  }
276 
277  /**
278  Sets recovery threshold policy on what to wait when handling transactions
279  @param completion_policy if recovery shall wait for execution
280  or certification
281  */
283  enum_recovery_completion_policies completion_policy) {
284  this->recovery_completion_policy = completion_policy;
285  }
286 
287  /** Set a public key file*/
288  void set_recovery_public_key_path(const char *public_key_path) {
289  if (public_key_path != nullptr)
291  }
292 
293  /** Get public key automatically */
296  }
297 
298  /** Set compression algorithm */
301  }
302 
303  /** Set compression level */
306  }
307 
308  /**
309  Checks if the given id matches the recovery applier thread
310  @param id the thread id
311 
312  @return if it belongs to a thread
313  @retval true the id matches a SQL or worker thread
314  @retval false the id doesn't match any thread
315  */
317 
318  private:
319  /** Sets the thread context */
321 
322  /**
323  Handles code for removing the member in case of a failure during
324  recovery.
325  */
327 
328  /** Cleans the recovery thread related options/structures. */
330 
331  /**
332  Starts a wait process until the applier fulfills the necessary condition for
333  the member to be acknowledge as being online.
334 
335  @return the operation status
336  @retval 0 OK
337  @retval !=0 Error
338  */
340 
341  /**
342  Sends a message throughout the group stating the member as online.
343  */
345 
346  // recovery thread variables
349 
350  /* The plugin's applier module interface*/
352 
353  /* The group to which the recovering member belongs */
354  std::string group_name;
355 
356  /* The recovery state transfer class */
358 
359  /* Recovery thread state */
361  /* Recovery abort flag */
363 
364  // run conditions and locks
367 
368  /* Recovery strategy when waiting for the cache transaction handling*/
370 
371  /* Recovery module's timeout on shutdown */
373 };
374 
375 #endif /* RECOVERY_INCLUDE */
void set_applier_module(Applier_module_interface *applier)
Definition: recovery.h:62
void set_recovery_donor_reconnect_interval(ulong reconnect_interval)
Sets the sleep time between connection attempts to all possible donors.
Definition: recovery.h:145
my_thread_handle recovery_pthd
Definition: recovery.h:347
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery_state_transfer.h:133
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery.h:272
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
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:76
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery.h:228
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set a TLS ciphersuites to be used.
Definition: recovery_state_transfer.h:163
void set_recovery_use_ssl(char use_ssl)
Set the option that forces the use of SSL on recovery connections.
Definition: recovery.h:193
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery.h:208
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery.h:288
bool is_own_event_channel(my_thread_id id)
Checks if the given id matches the recovery applier thread.
Definition: recovery.cc:557
int stop_recovery(bool wait_for_termination=true)
Stops the recovery process, shutting down the recovery thread.
Definition: recovery.cc:109
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery_state_transfer.h:118
bool recovery_aborted
Definition: recovery.h:362
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set TLS ciphersuites to be used.
Definition: recovery.h:244
bool get_recovery_use_ssl()
Definition: recovery_state_transfer.h:176
Definition: recovery.h:44
mysql_cond_t run_cond
Definition: recovery.h:366
bool get_recovery_use_ssl()
Definition: recovery.h:251
THD * recovery_thd
Definition: recovery.h:348
void leave_group_on_recovery_failure()
Handles code for removing the member in case of a failure during recovery.
Definition: recovery.cc:172
void set_recovery_tls_version(const char *tls_version)
Set a TLS versions to be used.
Definition: recovery_state_transfer.h:158
A class to register observers for channel state events.
Definition: channel_observation_manager.h:130
ulong stop_wait_timeout
Definition: recovery.h:372
Applier_module_interface * applier_module
Definition: recovery.h:351
Definition: recovery.h:41
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:399
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery.h:223
enum_recovery_completion_policies recovery_completion_policy
Definition: recovery.h:369
Recovery_state_transfer recovery_state_transfer
Definition: recovery.h:357
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:282
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:153
Recovery_module(Applier_module_interface *applier, Channel_observation_manager *channel_obsr_mngr, ulong components_stop_timeout)
Recovery_module constructor.
Definition: recovery.cc:52
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:140
int ssl_verify_server_cert(SSL *ssl, const char *server_hostname)
Definition: xcom_ssl_transport.c:659
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery_state_transfer.h:143
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:233
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:262
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:165
void set_recovery_get_public_key(bool set)
Get preference to get public key.
Definition: recovery_state_transfer.h:210
int recovery_thread_handle()
Recovery thread main execution method.
Definition: recovery.cc:226
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery.h:203
void clean_recovery_thread_context()
Cleans the recovery thread related options/structures.
Definition: recovery.cc:438
Definition: my_thread_bits.h:51
Definition: recovery.h:39
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:115
unsigned int uint
Definition: uca-dump.cc:29
case opt name
Definition: sslopt-case.h:32
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery_state_transfer.h:128
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery_state_transfer.h:148
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery_state_transfer.h:138
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery_state_transfer.h:213
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery_state_transfer.h:218
Definition: plugin_utils.h:42
Definition: recovery_state_transfer.h:37
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery.h:304
enum_recovery_completion_policies
Definition: recovery.h:38
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:71
uint32 my_thread_id
Definition: my_thread_local.h:33
std::string group_name
Definition: recovery.h:354
void notify_group_recovery_end()
Sends a message throughout the group stating the member as online.
Definition: recovery.cc:545
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:375
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery_state_transfer.h:123
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery.h:213
~Recovery_module()
Definition: recovery.cc:66
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:443
mysql_mutex_t run_lock
Definition: recovery.h:365
Definition: applier.h:239
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery_state_transfer.h:197
void set_recovery_get_public_key(bool set)
Get public key automatically.
Definition: recovery.h:294
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:185
Log info(cout, "NOTE")
void set_recovery_tls_version(const char *tls_version)
Set TLS version to be used.
Definition: recovery.h:239
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery.h:299
void set_recovery_thread_context()
Sets the thread context.
Definition: recovery.cc:424
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery_state_transfer.h:202
thread_state recovery_thd_state
Definition: recovery.h:360
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery.h:198
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:765
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery.h:218