MySQL  8.0.19
Source Code Documentation
replication_threads_api.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 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  */
255  bool is_own_event_applier(my_thread_id id, const char *channel_name = NULL);
256 
257  /**
258  Checks if the given id matches the receiver thread for
259  the configured channel.
260 
261  @param id the thread id
262 
263  @return if it belongs to a thread
264  @retval true the id matches an IO thread
265  @retval false the id doesn't match any thread
266  */
268 
269  /**
270  Returns last GNO from the applier for a given UUID.
271 
272  @param sidno the SIDNO of the group UUID, so that we get the
273  last GNO of group's already certified transactions
274  on relay log.
275 
276  @return
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  @return
295  @retval true there was an error.
296  @retval false the operation has succeeded.
297  */
298  bool get_retrieved_gtid_set(std::string &retrieved_set,
299  const char *channel_name = NULL);
300 
301  /**
302  Checks if the channel's relay log contains partial transaction.
303  @return
304  @retval true If relaylog contains partial transaction.
305  @retval false If relaylog does not contain partial transaction.
306  */
308 
309  /**
310  Interface to Channel Service Interface channel_stop_all method.
311  Stops all the running channel threads according to the given options.
312 
313  @param threads_to_stop The types of threads to be stopped
314  @param timeout The max time in which the thread should stop
315 
316  @return the operation status
317  @retval 0 OK
318  @retval !=0 Error
319  */
320  static int rpl_channel_stop_all(int threads_to_stop, long timeout);
321 
322  /**
323  Interface to kill binlog dump thread.
324  Kills binlog dump thread thus killing all slave connections.
325  @note binlog dump GTID thread is not killed as of now.
326 
327  @return the operation status
328  @retval 0 OK
329  */
330  static int rpl_binlog_dump_thread_kill();
331 
332  /**
333  Method to get the credentials configured for a channel
334 
335  @param[out] username The user to extract
336  @param[out] password The password to extract
337  @param[in] channel_name The name of the channel to get the information.
338 
339  @return the operation status
340  @retval false OK
341  @retval true Error, channel not found
342  */
343  bool get_channel_credentials(std::string &username, std::string &password,
344  const char *channel_name = NULL);
345 
346  private:
348  const char *interface_channel;
349 };
350 
351 #endif /* REPLICATION_THREADS_API_INCLUDE */
Replication_thread_api::is_own_event_applier
bool is_own_event_applier(my_thread_id id, const char *channel_name=NULL)
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::interface_channel
const char * interface_channel
Definition: replication_threads_api.h:348
Replication_thread_api::Replication_thread_api
Replication_thread_api(const char *channel_interface)
Definition: replication_threads_api.h:38
Replication_thread_api::is_applier_thread_running
bool is_applier_thread_running()
Checks if the applier thread is running.
Definition: replication_threads_api.cc:178
NULL
#define NULL
Definition: types.h:55
Replication_thread_api::get_channel_credentials
bool get_channel_credentials(std::string &username, std::string &password, const char *channel_name=NULL)
Method to get the credentials configured for a channel.
Definition: replication_threads_api.cc:313
rpl_sidno
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:94
Replication_thread_api::set_stop_wait_timeout
void set_stop_wait_timeout(ulong timeout)
Sets the threads shutdown timeout.
Definition: replication_threads_api.h:286
Replication_thread_api
Definition: replication_threads_api.h:36
Replication_thread_api::is_own_event_receiver
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
LONG_TIMEOUT
#define LONG_TIMEOUT
Definition: version_token.cc:72
Replication_thread_api::get_last_delivered_gno
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
Replication_thread_api::get_applier_thread_ids
int get_applier_thread_ids(unsigned long **thread_ids)
Method to get applier ids from the configured channel.
Definition: replication_threads_api.cc:232
my_inttypes.h
Replication_thread_api::set_channel_name
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
Replication_thread_api::is_receiver_thread_stopping
bool is_receiver_thread_stopping()
Checks if the receiver thread is stopping.
Definition: replication_threads_api.cc:174
Replication_thread_api::is_partial_transaction_on_relay_log
bool is_partial_transaction_on_relay_log()
Checks if the channel's relay log contains partial transaction.
Definition: replication_threads_api.cc:335
uint
unsigned int uint
Definition: uca-dump.cc:29
rpl_gno
long long int rpl_gno
Type of GNO, the second (numeric) component of GTID.
Definition: rpl_gtid.h:100
Replication_thread_api::is_receiver_thread_running
bool is_receiver_thread_running()
Checks if the receiver thread is running.
Definition: replication_threads_api.cc:170
Replication_thread_api::get_retrieved_gtid_set
bool get_retrieved_gtid_set(std::string &retrieved_set, const char *channel_name=NULL)
Returns the retrieved gtid set from the receiver thread.
Definition: replication_threads_api.cc:297
port
static in_port_t port
Definition: testapp.c:33
user
char * user
Definition: mysqladmin.cc:59
Replication_thread_api::stop_threads
int stop_threads(bool stop_receiver, bool stop_applier)
Stops the channel threads according to the given options.
Definition: replication_threads_api.cc:147
Replication_thread_api::is_applier_thread_stopping
bool is_applier_thread_stopping()
Checks if the applier thread is stopping.
Definition: replication_threads_api.cc:182
my_thread_id
uint32 my_thread_id
Definition: my_thread_local.h:33
Replication_thread_api::initialize_channel
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
password
static char * password
Definition: mysql_secure_installation.cc:55
Replication_thread_api::queue_packet
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
ulong
unsigned long ulong
Definition: my_inttypes.h:48
Replication_thread_api::purge_logs
int purge_logs(bool reset_all)
Purges the relay logs.
Definition: replication_threads_api.cc:136
Replication_thread_api::rpl_channel_stop_all
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
Replication_thread_api::~Replication_thread_api
~Replication_thread_api()
Definition: replication_threads_api.h:44
Replication_thread_api::is_applier_thread_waiting
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::Replication_thread_api
Replication_thread_api()
Definition: replication_threads_api.h:41
Replication_thread_api::stop_wait_timeout
ulong stop_wait_timeout
Definition: replication_threads_api.h:347
Replication_thread_api::wait_for_gtid_execution
int wait_for_gtid_execution(double timeout)
Checks if all the queued transactions were executed.
Definition: replication_threads_api.cc:194
Replication_thread_api::start_threads
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
thread_ids
static pthread_t * thread_ids
Definition: thread.c:66
Replication_thread_api::rpl_binlog_dump_thread_kill
static int rpl_binlog_dump_thread_kill()
Interface to kill binlog dump thread.
Definition: replication_threads_api.cc:358
group_replication_priv.h