MySQL 9.0.0
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 replication
56 source 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 @param until_condition the replication until condition that can be
111 applied to channels for the recovery.
112
113 @return the operation status
114 @retval 0 OK
115 @retval REPLICATION_THREAD_START_ERROR
116 Error when launching on of the threads
117 @retval REPLICATION_THREAD_START_IO_NOT_CONNECTED
118 Error when the threads start, but the IO thread cannot connect
119 */
120 int start_threads(
121 bool start_receiver, bool start_applier, std::string *view_id,
122 bool wait_for_connection,
124
125 /**
126 Stops the channel threads according to the given options.
127
128 @param stop_receiver if the receiver thread should be stopped
129 @param stop_applier if the applier thread should be stopped
130
131 @return the operation status
132 @retval 0 OK
133 @retval !=0 Error stopping channel thread
134 */
135 int stop_threads(bool stop_receiver, bool stop_applier);
136
137 /**
138 Purges the relay logs.
139
140 @param reset_all If true, the method will purge logs and remove the channel
141 If false, the channel logs will be deleted and recreated
142 but the channel info will be preserved.
143
144 @return the operation status
145 @retval 0 OK
146 @retval !=0 Error purging channel logs
147 */
148 int purge_logs(bool reset_all);
149
150 /**
151 Checks if the receiver thread is running.
152
153 @return the thread status
154 @retval true the thread is running
155 @retval false the thread is stopped
156 */
158
159 /**
160 Checks if the receiver thread is stopping.
161
162 @return the thread status
163 @retval true the thread is stopping
164 @retval false the thread is not stopping
165 */
167
168 /**
169 Checks if the applier thread is running.
170
171 @return the thread status
172 @retval true the thread is running
173 @retval false the thread is stopped
174 */
176
177 /**
178 Checks if the applier thread is stopping.
179
180 @return the thread status
181 @retval true the thread is stopping
182 @retval false the thread is not stopping
183 */
185
186 /**
187 Queues a event packet into the current active channel relay log.
188
189 @param buf the event buffer
190 @param event_len the event buffer length
191
192 @return the operation status
193 @retval 0 OK
194 @retval != 0 Error on queue
195 */
196 int queue_packet(const char *buf, ulong event_len);
197
198 /**
199 Checks if the applier, and its workers when parallel applier is
200 enabled, has already consumed all relay log, that is, applier is
201 waiting for transactions to be queued.
202
203 @return the applier status
204 @retval true the applier is waiting
205 @retval false otherwise
206 */
208
209 /**
210 Checks if all the queued transactions were executed.
211
212 @param timeout the time (seconds) after which the method returns if the
213 above condition was not satisfied
214
215 @return the operation status
216 @retval 0 All transactions were executed
217 @retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
218 @retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
219 */
221
222 /**
223 Checks if all the set transactions were executed.
224
225 @param retrieved_set the set in string format of transaction to wait for
226 @param timeout the time (seconds) after which the method returns if the
227 above condition was not satisfied
228 @param update_THD_status Shall the method update the THD stage
229
230 @return the operation status
231 @retval 0 All transactions were executed
232 @retval REPLICATION_THREAD_WAIT_TIMEOUT_ERROR A timeout occurred
233 @retval REPLICATION_THREAD_WAIT_NO_INFO_ERROR An error occurred
234 */
235 int wait_for_gtid_execution(std::string &retrieved_set, double timeout,
236 bool update_THD_status = true);
237
238 /**
239 Method to get applier ids from the configured channel
240
241 @param[out] thread_ids The retrieved thread ids.
242
243 @return the number of appliers
244 @retval <= 0 Some error occurred or the applier is not present
245 @retval > 0 Number of appliers
246 */
247 int get_applier_thread_ids(unsigned long **thread_ids);
248
249 /**
250 Checks if the given id matches any of the event applying threads for
251 the configured channel.
252
253 @param id the thread id
254 @param channel_name the channel name which needs to be checked. It is
255 an optional parameter.
256
257 @return if it belongs to a thread
258 @retval true the id matches a SQL or worker thread
259 @retval false the id doesn't match any thread
260 */
262 const char *channel_name = nullptr);
263
264 /**
265 Checks if the given id matches the receiver thread for
266 the configured channel.
267
268 @param id the thread id
269
270 @return if it belongs to a thread
271 @retval true the id matches an IO thread
272 @retval false the id doesn't match any thread
273 */
275
276 /**
277 Returns last GNO from the applier for a given UUID.
278
279 @param sidno the SIDNO of the group UUID, so that we get the
280 last GNO of group's already certified transactions
281 on relay log.
282
283 @retval GNO value
284 */
286
287 /**
288 Sets the threads shutdown timeout.
289
290 @param[in] timeout the timeout
291 */
293
294 /**
295 Returns the retrieved gtid set from the receiver thread.
296
297 @param[out] retrieved_set the set in string format.
298 @param channel_name the name of the channel to get the information.
299
300 @retval true there was an error.
301 @retval false the operation has succeeded.
302 */
303 bool get_retrieved_gtid_set(std::string &retrieved_set,
304 const char *channel_name = nullptr);
305
306 /**
307 Checks if the channel's relay log contains partial transaction.
308
309 @retval true If relaylog contains partial transaction.
310 @retval false If relaylog does not contain partial transaction.
311 */
313
314 /**
315 Interface to Channel Service Interface channel_stop_all method.
316 Stops all the running channel threads according to the given options.
317
318 @param threads_to_stop The types of threads to be stopped
319 @param timeout The max time in which the thread should stop
320
321 @return the operation status
322 @retval 0 OK
323 @retval !=0 Error
324 */
325 static int rpl_channel_stop_all(int threads_to_stop, long timeout);
326
327 /**
328 Interface to kill binlog dump thread.
329 Kills binlog dump thread thus killing all slave connections.
330 @note binlog dump GTID thread is not killed as of now.
331
332 @return the operation status
333 @retval 0 OK
334 */
335 static int rpl_binlog_dump_thread_kill();
336
337 /**
338 Interface to remove stored credentials from thread api.
339 Removes credentials for the channel from thread api.
340
341 @param channel_name Credential associated channel name
342
343 @return the operation status
344 @retval 0 OK
345 @retval !=0 Error
346 */
347 static int delete_credential(const char *channel_name);
348
349 /**
350 Method to get the credentials configured for a channel
351
352 @param[out] username The user to extract
353 @param[out] password The password to extract
354 @param[in] channel_name The name of the channel to get the information.
355
356 @return the operation status
357 @retval false OK
358 @retval true Error, channel not found
359 */
360 bool get_channel_credentials(std::string &username, std::string &password,
361 const char *channel_name = nullptr);
362
363 /**
364 Method to get the network namespace configured for a channel
365
366 @param[out] net_ns The network namespace to extract
367 @param[in] channel_name The name of the channel to get the information.
368
369 @return the operation status
370 @retval false OK
371 @retval true Error, channel not found
372 */
373 bool get_channel_network_namespace(std::string &net_ns,
374 const char *channel_name = nullptr);
375
376 /**
377 Checks if any channel uses the same UUID for
378 assign_gtids_to_anonymous_transactions as the given uuid
379
380 @param[in] uuid_param the group name
381
382 @retval true at least one channel has the same uuid
383 @retval false none of the the channels have the same
384 uuid
385 */
387 const char *uuid_param);
388
389 private:
391 const char *interface_channel;
392};
393
394#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:388
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:369
bool is_partial_transaction_on_relay_log()
Checks if the channel's relay log contains partial transaction.
Definition: replication_threads_api.cc:365
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:335
ulong stop_wait_timeout
Definition: replication_threads_api.h:390
bool is_receiver_thread_running()
Checks if the receiver thread is running.
Definition: replication_threads_api.cc:189
static int delete_credential(const char *channel_name)
Interface to remove stored credentials from thread api.
Definition: replication_threads_api.cc:393
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:260
void set_stop_wait_timeout(ulong timeout)
Sets the threads shutdown timeout.
Definition: replication_threads_api.h:292
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:299
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:319
~Replication_thread_api()=default
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:351
rpl_gno get_last_delivered_gno(rpl_sidno sidno)
Returns last GNO from the applier for a given UUID.
Definition: replication_threads_api.cc:249
int start_threads(bool start_receiver, bool start_applier, std::string *view_id, bool wait_for_connection, enum_channel_until_condition until_condition=CHANNEL_UNTIL_VIEW_ID)
Start the Applier/Receiver threads according to the given options.
Definition: replication_threads_api.cc:115
bool is_applier_thread_running()
Checks if the applier thread is running.
Definition: replication_threads_api.cc:197
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:399
int purge_logs(bool reset_all)
Purges the relay logs.
Definition: replication_threads_api.cc:155
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:193
int stop_threads(bool stop_receiver, bool stop_applier)
Stops the channel threads according to the given options.
Definition: replication_threads_api.cc:166
int wait_for_gtid_execution(double timeout)
Checks if all the queued transactions were executed.
Definition: replication_threads_api.cc:213
int get_applier_thread_ids(unsigned long **thread_ids)
Method to get applier ids from the configured channel.
Definition: replication_threads_api.cc:254
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:209
const char * interface_channel
Definition: replication_threads_api.h:391
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 replication source 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:205
bool is_applier_thread_stopping()
Checks if the applier thread is stopping.
Definition: replication_threads_api.cc:201
Some integer typedefs for easier portability.
uint32 my_thread_id
Definition: my_thread_local.h:34
static char * password
Definition: mysql_secure_installation.cc:58
char * user
Definition: mysqladmin.cc:66
Definition: buf0block_hint.cc:30
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
required uint32 priority
Definition: replication_group_member_actions.proto:35
enum_channel_until_condition
The known until conditions that can be applied to channels.
Definition: rpl_channel_service_interface.h:134
@ CHANNEL_UNTIL_VIEW_ID
Definition: rpl_channel_service_interface.h:139
mysql::gtid::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
Definition: rpl_gtid.h:112
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:108
static const Thread_to_stop threads_to_stop[]
Definition: srv0start.cc:1326
int ssl_verify_server_cert(SSL *ssl, const char *server_hostname)