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