MySQL  8.0.20
Source Code Documentation
replication_threads_api.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2020, 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 REPLICATION_THREADS_API_INCLUDE
24 #define REPLICATION_THREADS_API_INCLUDE
25 
27 #include <stddef.h>
28 #include <string>
29 
30 #include "my_inttypes.h"
31 
32 #define DEFAULT_THREAD_PRIORITY 0
33 // Applier thread InnoDB priority
34 #define GROUP_REPLICATION_APPLIER_THREAD_PRIORITY 1
35 
37  public:
38  Replication_thread_api(const char *channel_interface)
39  : stop_wait_timeout(LONG_TIMEOUT), interface_channel(channel_interface) {}
40 
43 
45 
46  /**
47  Set the channel name to be used on the interface method invocation.
48 
49  @param channel_name the name to be used.
50  */
51  void set_channel_name(const char *channel_name) {
52  interface_channel = channel_name;
53  }
54 
55  /**
56  Initializes a channel connection in a similar way to a change master
57  command.
58 
59  @param hostname The channel hostname
60  @param port The channel port
61  @param user The user used in the receiver connection
62  @param password The password used in the receiver connection
63  @param use_ssl Force the use of SSL on recovery connections
64  @param ssl_ca SSL trusted certificate authorities file
65  @param ssl_capath A directory with trusted CA files
66  @param ssl_cert The certificate file for secure connections
67  @param ssl_cipher The list of ciphers to use
68  @param ssl_key The SSL key file
69  @param ssl_crl SSL revocation list file
70  @param ssl_crlpath Path with revocation list files
71  @param ssl_verify_server_cert verify the hostname against the certificate
72  @param priority The channel priority on event application
73  @param retry_count The number of retries when connecting
74  @param preserve_logs If logs should be always preserved
75  @param public_key_path The file with public key path information
76  @param get_public_key Preference to get public key if unavailable.
77  @param compression_algorithm The compression algorithm
78  @param zstd_compression_level The compression level
79  @param tls_version TLS versions
80  @param tls_ciphersuites Permissible ciphersuites for TLS 1.3.
81 
82  @return the operation status
83  @retval 0 OK
84  @retval !=0 Error on channel creation
85  */
86  int initialize_channel(char *hostname, uint port, char *user, char *password,
87  bool use_ssl, char *ssl_ca, char *ssl_capath,
88  char *ssl_cert, char *ssl_cipher, char *ssl_key,
89  char *ssl_crl, char *ssl_crlpath,
90  bool ssl_verify_server_cert, int priority,
91  int retry_count, bool preserve_logs,
92  char *public_key_path, bool get_public_key,
93  char *compression_algorithm,
94  uint zstd_compression_level, char *tls_version,
95  char *tls_ciphersuites);
96 
97  /**
98  Start the Applier/Receiver threads according to the given options.
99  If the receiver thread is to be started, connection credential must be
100  supported.
101 
102  @param start_receiver Is the receiver thread to be started
103  @param start_applier Is the applier thread to be started
104  @param view_id The view id, that can be used to activate the
105  until view id clause.
106  @param wait_for_connection If when starting the receiver, the method should
107  wait for the connection to succeed
108 
109  @return the operation status
110  @retval 0 OK
111  @retval REPLICATION_THREAD_START_ERROR
112  Error when launching on of the threads
113  @retval REPLICATION_THREAD_START_IO_NOT_CONNECTED
114  Error when the threads start, but the IO thread cannot connect
115  */
116  int start_threads(bool start_receiver, bool start_applier,
117  std::string *view_id, bool wait_for_connection);
118 
119  /**
120  Stops the channel threads according to the given options.
121 
122  @param stop_receiver if the receiver thread should be stopped
123  @param stop_applier if the applier thread should be stopped
124 
125  @return the operation status
126  @retval 0 OK
127  @retval !=0 Error stopping channel thread
128  */
129  int stop_threads(bool stop_receiver, bool stop_applier);
130 
131  /**
132  Purges the relay logs.
133 
134  @param reset_all If true, the method will purge logs and remove the channel
135  If false, the channel logs will be deleted and recreated
136  but the channel info will be preserved.
137 
138  @return the operation status
139  @retval 0 OK
140  @retval !=0 Error purging channel logs
141  */
142  int purge_logs(bool reset_all);
143 
144  /**
145  Checks if the receiver thread is running.
146 
147  @return the thread status
148  @retval true the thread is running
149  @retval false the thread is stopped
150  */
152 
153  /**
154  Checks if the receiver thread is stopping.
155 
156  @return the thread status
157  @retval true the thread is stopping
158  @retval false the thread is not stopping
159  */
161 
162  /**
163  Checks if the applier thread is running.
164 
165  @return the thread status
166  @retval true the thread is running
167  @retval false the thread is stopped
168  */
170 
171  /**
172  Checks if the applier thread is stopping.
173 
174  @return the thread status
175  @retval true the thread is stopping
176  @retval false the thread is not stopping
177  */
179 
180  /**
181  Queues a event packet into the current active channel relay log.
182 
183  @param buf the event buffer
184  @param event_len the event buffer length
185 
186  @return the operation status
187  @retval 0 OK
188  @retval != 0 Error on queue
189  */
190  int queue_packet(const char *buf, ulong event_len);
191 
192  /**
193  Checks if the applier, and its workers when parallel applier is
194  enabled, has already consumed all relay log, that is, applier is
195  waiting for transactions to be queued.
196 
197  @return the applier status
198  @retval true the applier is waiting
199  @retval false otherwise
200  */
202 
203  /**
204  Checks if all the queued transactions were executed.
205 
206  @param timeout the time (seconds) after which the method returns if the
207  above condition was not satisfied
208 
209  @return the operation status
210  @retval 0 All transactions were executed
211  @retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
212  @retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
213  */
214  int wait_for_gtid_execution(double timeout);
215 
216  /**
217  Checks if all the set transactions were executed.
218 
219  @param retrieved_set the set in string format of transaction to wait for
220  @param timeout the time (seconds) after which the method returns if the
221  above condition was not satisfied
222  @param update_THD_status Shall the method update the THD stage
223 
224  @return the operation status
225  @retval 0 All transactions were executed
226  @retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
227  @retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
228  */
229  int wait_for_gtid_execution(std::string &retrieved_set, double timeout,
230  bool update_THD_status = true);
231 
232  /**
233  Method to get applier ids from the configured channel
234 
235  @param[out] thread_ids The retrieved thread ids.
236 
237  @return the number of appliers
238  @retval <= 0 Some error occurred or the applier is not present
239  @retval > 0 Number of appliers
240  */
241  int get_applier_thread_ids(unsigned long **thread_ids);
242 
243  /**
244  Checks if the given id matches any of the event applying threads for
245  the configured channel.
246 
247  @param id the thread id
248  @param channel_name the channel name which needs to be checked. It is
249  an optional parameter.
250 
251  @return if it belongs to a thread
252  @retval true the id matches a SQL or worker thread
253  @retval false the id doesn't match any thread
254  */
256  const char *channel_name = nullptr);
257 
258  /**
259  Checks if the given id matches the receiver thread for
260  the configured channel.
261 
262  @param id the thread id
263 
264  @return if it belongs to a thread
265  @retval true the id matches an IO thread
266  @retval false the id doesn't match any thread
267  */
269 
270  /**
271  Returns last GNO from the applier for a given UUID.
272 
273  @param sidno the SIDNO of the group UUID, so that we get the
274  last GNO of group's already certified transactions
275  on relay log.
276 
277  @retval GNO value
278  */
280 
281  /**
282  Sets the threads shutdown timeout.
283 
284  @param[in] timeout the timeout
285  */
286  void set_stop_wait_timeout(ulong timeout) { stop_wait_timeout = timeout; }
287 
288  /**
289  Returns the retrieved gtid set from the receiver thread.
290 
291  @param[out] retrieved_set the set in string format.
292  @param channel_name the name of the channel to get the information.
293 
294  @retval true there was an error.
295  @retval false the operation has succeeded.
296  */
297  bool get_retrieved_gtid_set(std::string &retrieved_set,
298  const char *channel_name = nullptr);
299 
300  /**
301  Checks if the channel's relay log contains partial transaction.
302 
303  @retval true If relaylog contains partial transaction.
304  @retval false If relaylog does not contain partial transaction.
305  */
307 
308  /**
309  Interface to Channel Service Interface channel_stop_all method.
310  Stops all the running channel threads according to the given options.
311 
312  @param threads_to_stop The types of threads to be stopped
313  @param timeout The max time in which the thread should stop
314 
315  @return the operation status
316  @retval 0 OK
317  @retval !=0 Error
318  */
319  static int rpl_channel_stop_all(int threads_to_stop, long timeout);
320 
321  /**
322  Interface to kill binlog dump thread.
323  Kills binlog dump thread thus killing all slave connections.
324  @note binlog dump GTID thread is not killed as of now.
325 
326  @return the operation status
327  @retval 0 OK
328  */
329  static int rpl_binlog_dump_thread_kill();
330 
331  /**
332  Method to get the credentials configured for a channel
333 
334  @param[out] username The user to extract
335  @param[out] password The password to extract
336  @param[in] channel_name The name of the channel to get the information.
337 
338  @return the operation status
339  @retval false OK
340  @retval true Error, channel not found
341  */
342  bool get_channel_credentials(std::string &username, std::string &password,
343  const char *channel_name = nullptr);
344 
345  private:
347  const char *interface_channel;
348 };
349 
350 #endif /* REPLICATION_THREADS_API_INCLUDE */
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:95
bool get_retrieved_gtid_set(std::string &retrieved_set, const char *channel_name=nullptr)
Returns the retrieved gtid set from the receiver thread.
Definition: replication_threads_api.cc:297
int start_threads(bool start_receiver, bool start_applier, std::string *view_id, bool wait_for_connection)
Start the Applier/Receiver threads according to the given options.
Definition: replication_threads_api.cc:100
char * user
Definition: mysqladmin.cc:59
const char * interface_channel
Definition: replication_threads_api.h:347
Some integer typedefs for easier portability.
int stop_threads(bool stop_receiver, bool stop_applier)
Stops the channel threads according to the given options.
Definition: replication_threads_api.cc:147
#define LONG_TIMEOUT
Definition: version_token.cc:72
int queue_packet(const char *buf, ulong event_len)
Queues a event packet into the current active channel relay log.
Definition: replication_threads_api.cc:186
int get_applier_thread_ids(unsigned long **thread_ids)
Method to get applier ids from the configured channel.
Definition: replication_threads_api.cc:232
static int rpl_channel_stop_all(int threads_to_stop, long timeout)
Interface to Channel Service Interface channel_stop_all method.
Definition: replication_threads_api.cc:339
bool is_applier_thread_waiting()
Checks if the applier, and its workers when parallel applier is enabled, has already consumed all rel...
Definition: replication_threads_api.cc:190
Replication_thread_api()
Definition: replication_threads_api.h:41
bool is_own_event_receiver(my_thread_id id)
Checks if the given id matches the receiver thread for the configured channel.
Definition: replication_threads_api.cc:277
bool is_applier_thread_running()
Checks if the applier thread is running.
Definition: replication_threads_api.cc:178
ulong stop_wait_timeout
Definition: replication_threads_api.h:346
static int rpl_binlog_dump_thread_kill()
Interface to kill binlog dump thread.
Definition: replication_threads_api.cc:358
int wait_for_gtid_execution(double timeout)
Checks if all the queued transactions were executed.
Definition: replication_threads_api.cc:194
int ssl_verify_server_cert(SSL *ssl, const char *server_hostname)
Definition: xcom_ssl_transport.c:659
static in_port_t port
Definition: testapp.c:33
Definition: replication_threads_api.h:36
unsigned int uint
Definition: uca-dump.cc:29
int initialize_channel(char *hostname, uint port, char *user, char *password, bool use_ssl, char *ssl_ca, char *ssl_capath, char *ssl_cert, char *ssl_cipher, char *ssl_key, char *ssl_crl, char *ssl_crlpath, bool ssl_verify_server_cert, int priority, int retry_count, bool preserve_logs, char *public_key_path, bool get_public_key, char *compression_algorithm, uint zstd_compression_level, char *tls_version, char *tls_ciphersuites)
Initializes a channel connection in a similar way to a change master command.
Definition: replication_threads_api.cc:33
rpl_gno get_last_delivered_gno(rpl_sidno sidno)
Returns last GNO from the applier for a given UUID.
Definition: replication_threads_api.cc:227
bool get_channel_credentials(std::string &username, std::string &password, const char *channel_name=nullptr)
Method to get the credentials configured for a channel.
Definition: replication_threads_api.cc:313
bool is_applier_thread_stopping()
Checks if the applier thread is stopping.
Definition: replication_threads_api.cc:182
void set_stop_wait_timeout(ulong timeout)
Sets the threads shutdown timeout.
Definition: replication_threads_api.h:286
bool is_own_event_applier(my_thread_id id, const char *channel_name=nullptr)
Checks if the given id matches any of the event applying threads for the configured channel...
Definition: replication_threads_api.cc:238
~Replication_thread_api()
Definition: replication_threads_api.h:44
uint32 my_thread_id
Definition: my_thread_local.h:33
int purge_logs(bool reset_all)
Purges the relay logs.
Definition: replication_threads_api.cc:136
void set_channel_name(const char *channel_name)
Set the channel name to be used on the interface method invocation.
Definition: replication_threads_api.h:51
bool is_receiver_thread_stopping()
Checks if the receiver thread is stopping.
Definition: replication_threads_api.cc:174
static char * password
Definition: mysql_secure_installation.cc:55
static pthread_t * thread_ids
Definition: thread.c:66
bool is_partial_transaction_on_relay_log()
Checks if the channel&#39;s relay log contains partial transaction.
Definition: replication_threads_api.cc:335
long long int rpl_gno
Type of GNO, the second (numeric) component of GTID.
Definition: rpl_gtid.h:101
Replication_thread_api(const char *channel_interface)
Definition: replication_threads_api.h:38
Dialog Client Authentication nullptr
Definition: dialog.cc:353
bool is_receiver_thread_running()
Checks if the receiver thread is running.
Definition: replication_threads_api.cc:170