MySQL  8.0.19
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. */
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 != NULL) recovery_state_transfer.set_recovery_ssl_ca(ssl_ca);
173  if (ssl_capath != NULL)
175  if (ssl_cert != NULL)
177  if (ssl_cipher != NULL)
179  if (ssl_key != NULL) recovery_state_transfer.set_recovery_ssl_key(ssl_key);
180  if (ssl_crl != NULL) recovery_state_transfer.set_recovery_ssl_crl(ssl_crl);
181  if (ssl_crlpath != NULL)
184  ssl_verify_server_cert);
185  if (tls_version != NULL)
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 */
231  void set_recovery_ssl_verify_server_cert(char ssl_verify_server_cert) {
233  ssl_verify_server_cert);
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  */
270  void set_stop_wait_timeout(ulong timeout) {
271  stop_wait_timeout = timeout;
273  }
274 
275  /**
276  Sets recovery threshold policy on what to wait when handling transactions
277  @param completion_policy if recovery shall wait for execution
278  or certification
279  */
281  enum_recovery_completion_policies completion_policy) {
282  this->recovery_completion_policy = completion_policy;
283  }
284 
285  /** Set a public key file*/
286  void set_recovery_public_key_path(const char *public_key_path) {
287  if (public_key_path != NULL)
289  }
290 
291  /** Get public key automatically */
294  }
295 
296  /** Set compression algorithm */
299  }
300 
301  /** Set compression level */
304  }
305 
306  /**
307  Checks if the given id matches the recovery applier thread
308  @param id the thread id
309 
310  @return if it belongs to a thread
311  @retval true the id matches a SQL or worker thread
312  @retval false the id doesn't match any thread
313  */
315 
316  private:
317  /** Sets the thread context */
319 
320  /**
321  Handles code for removing the member in case of a failure during
322  recovery.
323  */
325 
326  /** Cleans the recovery thread related options/structures. */
328 
329  /**
330  Starts a wait process until the applier fulfills the necessary condition for
331  the member to be acknowledge as being online.
332 
333  @return the operation status
334  @retval 0 OK
335  @retval !=0 Error
336  */
338 
339  /**
340  Sends a message throughout the group stating the member as online.
341  */
343 
344  // recovery thread variables
347 
348  /* The plugin's applier module interface*/
350 
351  /* The group to which the recovering member belongs */
352  std::string group_name;
353 
354  /* The recovery state transfer class */
356 
357  /* Recovery thread state */
359  /* Recovery abort flag */
361 
362  // run conditions and locks
365 
366  /* Recovery strategy when waiting for the cache transaction handling*/
368 
369  /* Recovery module's timeout on shutdown */
371 };
372 
373 #endif /* RECOVERY_INCLUDE */
Recovery_module::recovery_thread_handle
int recovery_thread_handle()
Recovery thread main execution method.
Definition: recovery.cc:226
Recovery_state_transfer::set_recovery_ssl_cipher
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery_state_transfer.h:133
Recovery_module::set_recovery_completion_policy
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:280
THD
Definition: sql_class.h:764
RECOVERY_POLICY_WAIT_EXECUTED
@ RECOVERY_POLICY_WAIT_EXECUTED
Definition: recovery.h:41
NULL
#define NULL
Definition: types.h:55
Recovery_state_transfer::set_recovery_ssl_ca
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery_state_transfer.h:118
Recovery_state_transfer::get_recovery_use_ssl
bool get_recovery_use_ssl()
Definition: recovery_state_transfer.h:176
Recovery_state_transfer::set_recovery_ssl_crl
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery_state_transfer.h:143
Recovery_state_transfer
Definition: recovery_state_transfer.h:37
Channel_observation_manager
A class to register observers for channel state events.
Definition: channel_observation_manager.h:130
Recovery_module::set_recovery_ssl_cipher
void set_recovery_ssl_cipher(const char *ssl_cipher)
Set a SSL ciphers to be used.
Definition: recovery.h:211
mysql_mutex_t
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Recovery_state_transfer::set_recovery_ssl_verify_server_cert
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
enum_recovery_completion_policies
enum_recovery_completion_policies
Definition: recovery.h:38
Recovery_module::~Recovery_module
~Recovery_module()
Definition: recovery.cc:66
Recovery_module::set_recovery_zstd_compression_level
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery.h:302
Recovery_state_transfer::set_recovery_get_public_key
void set_recovery_get_public_key(bool set)
Get preference to get public key.
Definition: recovery_state_transfer.h:210
Recovery_module::group_name
std::string group_name
Definition: recovery.h:352
Recovery_module::set_recovery_thread_context
void set_recovery_thread_context()
Sets the thread context.
Definition: recovery.cc:424
Recovery_module::set_applier_module
void set_applier_module(Applier_module_interface *applier)
Definition: recovery.h:62
Recovery_module::notify_group_recovery_end
void notify_group_recovery_end()
Sends a message throughout the group stating the member as online.
Definition: recovery.cc:545
Recovery_module::update_recovery_process
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
Recovery_state_transfer::set_recovery_tls_ciphersuites
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set a TLS ciphersuites to be used.
Definition: recovery_state_transfer.h:163
gcs_communication_interface.h
Recovery_module::recovery_pthd
my_thread_handle recovery_pthd
Definition: recovery.h:345
Recovery_module::set_recovery_compression_algorithm
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery.h:297
Recovery_state_transfer::set_recovery_donor_retry_count
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
Recovery_module::wait_for_applier_module_recovery
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
Recovery_module::run_lock
mysql_mutex_t run_lock
Definition: recovery.h:363
Applier_module_interface
Definition: applier.h:239
Recovery_module::set_stop_wait_timeout
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery.h:270
Recovery_module::set_recovery_get_public_key
void set_recovery_get_public_key(bool set)
Get public key automatically.
Definition: recovery.h:292
Recovery_module::recovery_thd_state
thread_state recovery_thd_state
Definition: recovery.h:358
Recovery_module::set_recovery_public_key_path
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery.h:286
uint
unsigned int uint
Definition: uca-dump.cc:29
RECOVERY_POLICY_WAIT_CERTIFIED
@ RECOVERY_POLICY_WAIT_CERTIFIED
Definition: recovery.h:39
Recovery_module::set_recovery_tls_version
void set_recovery_tls_version(const char *tls_version)
Set TLS version to be used.
Definition: recovery.h:237
Recovery_module::set_recovery_tls_ciphersuites
void set_recovery_tls_ciphersuites(const char *tls_ciphersuites)
Set TLS ciphersuites to be used.
Definition: recovery.h:242
Recovery_module::set_recovery_ssl_ca
void set_recovery_ssl_ca(const char *ssl_ca)
Set a SSL trusted certificate authorities file.
Definition: recovery.h:196
Recovery_state_transfer::set_recovery_ssl_crlpath
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery_state_transfer.h:148
Recovery_module::recovery_thd
THD * recovery_thd
Definition: recovery.h:346
Recovery_state_transfer::set_recovery_compression_algorithm
void set_recovery_compression_algorithm(const char *name)
Set compression algorithm.
Definition: recovery_state_transfer.h:213
Recovery_module::leave_group_on_recovery_failure
void leave_group_on_recovery_failure()
Handles code for removing the member in case of a failure during recovery.
Definition: recovery.cc:172
Recovery_state_transfer::set_recovery_ssl_capath
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery_state_transfer.h:123
applier.h
my_thread_handle
Definition: my_thread_bits.h:51
thread_state
Definition: plugin_utils.h:42
Recovery_module::is_own_event_channel
bool is_own_event_channel(my_thread_id id)
Checks if the given id matches the recovery applier thread.
Definition: recovery.cc:557
Recovery_module::recovery_aborted
bool recovery_aborted
Definition: recovery.h:360
Recovery_module::stop_recovery
int stop_recovery(bool wait_for_termination=true)
Stops the recovery process, shutting down the recovery thread.
Definition: recovery.cc:109
Recovery_state_transfer::set_recovery_ssl_cert
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery_state_transfer.h:128
Recovery_module
Definition: recovery.h:44
Recovery_module::set_recovery_ssl_key
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery.h:216
Recovery_module::run_cond
mysql_cond_t run_cond
Definition: recovery.h:364
Recovery_module::set_recovery_ssl_crlpath
void set_recovery_ssl_crlpath(const char *ssl_crlpath)
Set a folder with SSL revocation list files.
Definition: recovery.h:226
Recovery_module::set_recovery_donor_reconnect_interval
void set_recovery_donor_reconnect_interval(ulong reconnect_interval)
Sets the sleep time between connection attempts to all possible donors.
Definition: recovery.h:145
Recovery_module::start_recovery
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
Recovery_state_transfer::set_recovery_ssl_key
void set_recovery_ssl_key(const char *ssl_key)
Set a SSL key for connections.
Definition: recovery_state_transfer.h:138
name
const string name("\"Name\"")
Recovery_state_transfer::set_recovery_zstd_compression_level
void set_recovery_zstd_compression_level(uint level)
Set compression level.
Definition: recovery_state_transfer.h:218
set
void set(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:105
my_thread_id
uint32 my_thread_id
Definition: my_thread_local.h:33
Recovery_module::stop_wait_timeout
ulong stop_wait_timeout
Definition: recovery.h:370
Recovery_module::recovery_state_transfer
Recovery_state_transfer recovery_state_transfer
Definition: recovery.h:355
Recovery_module::Recovery_module
Recovery_module(Applier_module_interface *applier, Channel_observation_manager *channel_obsr_mngr, ulong components_stop_timeout)
Recovery_module constructor.
Definition: recovery.cc:52
recovery_state_transfer.h
Recovery_module::set_recovery_donor_retry_count
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
Recovery_module::set_recovery_ssl_verify_server_cert
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
Recovery_state_transfer::get_recovery_base_ssl_options
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
Recovery_state_transfer::set_recovery_use_ssl
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
gcs_control_interface.h
Recovery_module::set_retrieved_cert_info
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
Recovery_module::set_recovery_ssl_cert
void set_recovery_ssl_cert(const char *ssl_cert)
Set a SSL certificate for connection.
Definition: recovery.h:206
Recovery_module::set_recovery_use_ssl
void set_recovery_use_ssl(char use_ssl)
Set the option that forces the use of SSL on recovery connections.
Definition: recovery.h:191
Recovery_module::recovery_completion_policy
enum_recovery_completion_policies recovery_completion_policy
Definition: recovery.h:367
ulong
unsigned long ulong
Definition: my_inttypes.h:48
Recovery_module::get_recovery_use_ssl
bool get_recovery_use_ssl()
Definition: recovery.h:249
Recovery_state_transfer::set_recovery_public_key_path
void set_recovery_public_key_path(const char *public_key_path)
Set a public key file.
Definition: recovery_state_transfer.h:202
mysql_cond_t
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
Recovery_module::clean_recovery_thread_context
void clean_recovery_thread_context()
Cleans the recovery thread related options/structures.
Definition: recovery.cc:438
Recovery_module::applier_module
Applier_module_interface * applier_module
Definition: recovery.h:349
Recovery_state_transfer::set_stop_wait_timeout
void set_stop_wait_timeout(ulong timeout)
Sets the recovery shutdown timeout.
Definition: recovery_state_transfer.h:197
Recovery_state_transfer::set_recovery_donor_reconnect_interval
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
Recovery_module::set_recovery_ssl_crl
void set_recovery_ssl_crl(const char *ssl_crl)
Set a SSL revocation list file.
Definition: recovery.h:221
Recovery_module::set_recovery_ssl_capath
void set_recovery_ssl_capath(const char *ssl_capath)
Set a folder with SSL trusted CA files.
Definition: recovery.h:201
info
Log info(cout, "NOTE")
Recovery_module::get_recovery_base_ssl_options
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
group_replication_priv.h
Recovery_state_transfer::set_recovery_tls_version
void set_recovery_tls_version(const char *tls_version)
Set a TLS versions to be used.
Definition: recovery_state_transfer.h:158
channel_observation_manager.h
Recovery_module::set_recovery_ssl_options
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