MySQL 26.7.0
Source Code Documentation
rpl_replica.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2026, 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 RPL_REPLICA_H
25#define RPL_REPLICA_H
26
27#include <limits.h>
28#include <sys/types.h>
29#include <atomic>
30#include <memory>
31
32#include "my_bitmap.h"
33#include "my_dbug.h"
34#include "my_inttypes.h"
35#include "my_psi_config.h"
36#include "my_thread.h" // my_start_routine
37#include "mysql.h" // MYSQL
39#include "mysql_com.h"
41#include "sql/current_thd.h"
42#include "sql/debug_sync.h"
43
44class Master_info;
45class Relay_log_info;
46class THD;
47struct LEX_SOURCE_INFO;
48struct mysql_cond_t;
49struct mysql_mutex_t;
51
52namespace mysql::csa {
53class Csa_service;
54}
55
56const long mts_online_stat_period = 60 * 2;
57
59
60typedef enum {
66
67/**
68 SOURCE_DELAY can be at most (1 << 31) - 1.
69*/
70#define SOURCE_DELAY_MAX (0x7FFFFFFF)
71#if INT_MAX < 0x7FFFFFFF
72#error "don't support platforms where INT_MAX < 0x7FFFFFFF"
73#endif
74
75/**
76 @defgroup Replication Replication
77 @{
78
79 @file
80*/
81
82/**
83 Some of defines are need in parser even though replication is not
84 compiled in (embedded).
85*/
86
87/**
88 The maximum is defined as (ULONG_MAX/1000) with 4 bytes ulong
89*/
90#define REPLICA_MAX_HEARTBEAT_PERIOD 4294967
91
92#define REPLICA_NET_TIMEOUT 60
93
94#define MAX_SLAVE_ERROR 14000
95
96#define MTS_WORKER_UNDEF ((ulong)-1)
97#define MTS_MAX_WORKERS 1024
98#define MAX_SLAVE_RETRY_PAUSE 5
99
100/*
101 When using tables to store the slave workers bitmaps,
102 we use a BLOB field. The maximum size of a BLOB is:
103
104 2^16-1 = 65535 bytes => (2^16-1) * 8 = 524280 bits
105*/
106#define MTS_MAX_BITS_IN_GROUP ((1L << 19) - 8) /* 524280 */
107
108extern bool server_id_supplied;
109
110/*****************************************************************************
111
112 MySQL Replication
113
114 Replication is implemented via two types of threads:
115
116 I/O Thread - One of these threads is started for each master server.
117 They maintain a connection to their master server, read log
118 events from the master as they arrive, and queues them into
119 a single, shared relay log file. A Master_info represents
120 each of these threads.
121
122 SQL Thread - One of these threads is started and reads from the relay log
123 file, executing each event. A Relay_log_info represents this
124 thread.
125
126 Buffering in the relay log file makes it unnecessary to reread events from
127 a master server across a slave restart. It also decouples the slave from
128 the master where long-running updates and event logging are concerned--ie
129 it can continue to log new events while a slow query executes on the slave.
130
131*****************************************************************************/
132
133/*
134 # MUTEXES in replication #
135
136 JAG: TODO: This guide needs to be updated after pushing WL#10406!
137
138 ## In Multisource_info (channel_map) ##
139
140 ### m_channel_map_lock ###
141
142 This rwlock is used to protect the multi source replication data structure
143 (channel_map). Any operation reading contents from the channel_map should
144 hold the rdlock during the operation. Any operation changing the
145 channel_map (either adding/removing channels to/from the channel_map)
146 should hold the wrlock during the operation.
147
148 [init_replica() does not need it it's called early].
149
150 ## In Master_info (mi) ##
151
152 ### m_channel_lock ###
153
154 It is used to SERIALIZE ALL administrative commands of replication: START
155 SLAVE, STOP REPLICA, CHANGE REPLICATION SOURCE, RESET REPLICA,
156 delete_slave_info_objects (when mysqld stops)
157
158 This thus protects us against a handful of deadlocks, being the know ones
159 around lock_slave_threads and the mixed order they are acquired in some
160 operations:
161
162 + consider start_slave_thread() which, when starting the I/O thread,
163 releases mi->run_lock, keeps rli->run_lock, and tries to re-acquire
164 mi->run_lock.
165
166 + Same applies to stop_slave() where a stop of the I/O thread will
167 mi->run_lock, keeps rli->run_lock, and tries to re-acquire mi->run_lock.
168 For the SQL thread, the order is the opposite.
169
170 ### run_lock ###
171
172 Protects all information about the running state: slave_running, thd
173 and the existence of the I/O thread itself (to stop/start it, you need
174 this mutex).
175 Check the above m_channel_lock about locking order.
176
177 ### data_lock ###
178
179 Protects some moving members of the struct: counters (log name,
180 position).
181
182 ### tsid_lock ###
183
184 Protects the retrieved GTID set and it's TSID map from updates.
185
186 ## In Relay_log_info (rli) ##
187
188 ### run_lock ###
189
190 Same as Master_info's one. However, note that run_lock does not protect
191 Relay_log_info.run_state. That is protected by data_lock.
192 Check the above m_channel_lock about locking order.
193
194 ### data_lock ###
195
196 Protects some moving members of the struct: counters (log name,
197 position).
198
199 ## In MYSQL_BIN_LOG (mysql_bin_log,relay_log) ##
200
201 ### LOCK_log ###
202
203 This mutex should be taken when going to write to a log file. Notice that it
204 does not prevent other threads from reading from the file being written (the
205 "hot" file) or any other older file.
206
207 ### LOCK_index ###
208
209 This mutex should be taken when going to create/delete a log file (as those
210 operations will update the .index file).
211
212 ### LOCK_binlog_end_pos ###
213
214 This mutex protects the access to the binlog_end_pos variable. The variable
215 it set with the position that other threads reading from the currently active
216 log file (the "hot" one) should not cross.
217
218 ## Gtid_state (gtid_state, global_tsid_map) ##
219
220 ### global_tsid_lock ###
221
222 Protects all Gtid_state GTID sets (lost_gtids, executed_gtids,
223 gtids_only_in_table, previous_gtids_logged, owned_gtids) and the global TSID
224 map from updates.
225
226 The global_tsid_lock must not be taken after LOCK_reset_gtid_table.
227
228 ## Gtid_mode (gtid_mode) ##
229
230 ### Gtid_mode::lock ###
231
232 Used to arbitrate changes on server Gtid_mode.
233
234 # Order of acquisition #
235
236 Here, we list most major functions that acquire multiple locks.
237
238 Notation: For each function, we list the locks it takes, in the
239 order it takes them. If a function holds lock A while taking lock
240 B, then we write "A, B". If a function locks A, unlocks A, then
241 locks B, then we write "A | B". If function F1 invokes function F2,
242 then we write F2's name in parentheses in the list of locks for F1.
243
244 Sys_var_gtid_mode::global_update:
245 Gtid_mode::lock.wrlock, channel_map->wrlock, binlog.LOCK_log,
246 global_tsid_lock->wrlock
247
248 change_master_cmd:
249 channel_map.wrlock, (change_master)
250
251 change_master:
252 mi.channel_wrlock, mi.run_lock, rli.run_lock, (global_init_info),
253 (purge_relay_logs), (init_relay_log_pos), rli.err_lock
254
255 global_init_info:
256 mi.data_lock, rli.data_lock
257
258 purge_relay_logs:
259 rli.data_lock, (relay_log.reset_logs)
260
261 relay_log.reset_logs:
262 .LOCK_log, .LOCK_index, .tsid_lock->wrlock
263
264 init_relay_log_pos:
265 rli.data_lock
266
267 queue_event:
268 rli.LOCK_log, relay_log.tsid_lock->rdlock, mi.data_lock
269
270 stop_slave:
271 channel_map rdlock,
272 ( mi.channel_wrlock, mi.run_lock, thd.LOCK_thd_data
273 | rli.run_lock, thd.LOCK_thd_data
274 | relay.LOCK_log
275 )
276
277 start_slave:
278 mi.channel_wrlock, mi.run_lock, rli.run_lock, rli.data_lock,
279 global_tsid_lock->wrlock
280
281 mysql_bin_log.reset_logs:
282 .LOCK_log, .LOCK_index, global_tsid_lock->wrlock
283
284 purge_relay_logs:
285 rli.data_lock, (relay.reset_logs) THD::LOCK_thd_data,
286 relay.LOCK_log, relay.LOCK_index, global_tsid_lock->wrlock
287
288 reset_binary_logs_and_gtids:
289 (binlog.reset_logs) THD::LOCK_thd_data, binlog.LOCK_log,
290 binlog.LOCK_index, global_tsid_lock->wrlock, LOCK_reset_gtid_table
291
292 reset_slave:
293 mi.channel_wrlock, mi.run_lock, rli.run_lock, (purge_relay_logs)
294 rli.data_lock, THD::LOCK_thd_data, relay.LOCK_log, relay.LOCK_index,
295 global_tsid_lock->wrlock
296
297 purge_logs:
298 .LOCK_index, LOCK_thd_list, thd.linfo.lock
299
300 [Note: purge_logs contains a known bug: LOCK_index should not be
301 taken before LOCK_thd_list. This implies that, e.g.,
302 purge_source_logs_to_file can deadlock with reset_binary_logs_and_gtids.
303 However, although purge_first_log and reset_slave take locks in reverse order,
304 they cannot deadlock because they both first acquire rli.data_lock.]
305
306 purge_source_logs_to_file, purge_source_logs_before_date, purge:
307 (binlog.purge_logs) binlog.LOCK_index, LOCK_thd_list, thd.linfo.lock
308
309 purge_first_log:
310 rli.data_lock, relay.LOCK_index, rli.log_space_lock,
311 (relay.purge_logs) LOCK_thd_list, thd.linfo.lock
312
313 MYSQL_BIN_LOG::new_file_impl:
314 .LOCK_log, .LOCK_index,
315 ( [ if binlog: LOCK_prep_xids ]
316 | global_tsid_lock->wrlock
317 )
318
319 rotate_relay_log:
320 (relay.new_file_impl) relay.LOCK_log, relay.LOCK_index
321
322 kill_zombie_dump_threads:
323 LOCK_thd_list, thd.LOCK_thd_data
324
325 rli_init_info:
326 rli.data_lock,
327 ( relay.log_lock
328 | global_tsid_lock->wrlock
329 | (relay.open_binlog)
330 | (init_relay_log_pos) rli.data_lock, relay.log_lock
331 )
332
333 So the DAG of lock acquisition order (not counting the buggy
334 purge_logs) is, empirically:
335
336 Gtid_mode::lock, channel_map lock, mi.run_lock, rli.run_lock,
337 ( rli.data_lock,
338 ( LOCK_thd_list,
339 (
340 ( binlog.LOCK_log, binlog.LOCK_index
341 | relay.LOCK_log, relay.LOCK_index
342 ),
343 ( rli.log_space_lock | global_tsid_lock->wrlock )
344 | binlog.LOCK_log, binlog.LOCK_index, LOCK_prep_xids
345 | thd.LOCK_data
346 )
347 | mi.err_lock, rli.err_lock
348 )
349 )
350 )
351 | mi.data_lock, rli.data_lock
352*/
353
354extern ulong source_retry_count;
356extern char slave_skip_error_names[];
357extern bool use_slave_mask;
358extern char *replica_load_tmpdir;
362extern char *opt_binlog_index_name;
363extern bool opt_skip_replica_start;
364extern bool opt_log_replica_updates;
365extern char *opt_replica_skip_errors;
368
369extern const char *relay_log_index;
370extern const char *relay_log_basename;
371
372/// Global CSA object handle initialized in init_replica
373extern std::unique_ptr<mysql::csa::Csa_service> csa_service;
374
375/// @brief Helper class used to initialize the replica (includes init_replica())
376/// @details init_replica is called once during the mysqld start-up
378 public:
379 /// @brief Constructor, calls init_replica()
380 /// @param[in] opt_initialize Server option used to indicate whether mysqld
381 /// has been started with --initialize
382 /// @param[in] opt_skip_replica_start When true, skips the start of
383 /// replication threads
384 /// @param[in] filters Replication filters
385 /// @param[in] replica_skip_erors TBD
387 Rpl_channel_filters &filters, char **replica_skip_erors);
388
389 /// @brief Gets initialization code set-up at replica initialization
390 /// @return Error code obtained during the replica initialization
391 int get_initialization_code() const;
392
393 private:
394 /// @brief This function starts replication threads
395 /// @param[in] skip_replica_start When true, skips the start of replication
396 /// threads threads
397 void start_replication_threads(bool skip_replica_start = true);
398
399 /// @brief Initializes replica PSI keys in case PSI interface is available
400 static void init_replica_psi_keys();
401
402 /// @brief Performs replica initialization, creates default replication
403 /// channel and sets channel filters
404 /// @returns Error code
405 int init_replica();
406
407 /// @brief In case debug mode is on, prints channel information
408 void print_channel_info() const;
409
410 /// @brief This function starts replication threads
411 void start_threads();
412
414 false; ///< Indicates whether to initialize replica
416 false; ///< Indicates whether replica threads should be started or not
417 int m_init_code = 0; ///< Replica initialization error code
418 int m_thread_mask = 0; ///< Thread mask indicating type of the thread
419};
420
421/// Obtain CSA service reference
423
424/*
425 3 possible values for Master_info::slave_running and
426 Relay_log_info::slave_running.
427 The values 0,1,2 are very important: to keep the diff small, I didn't
428 substitute places where we use 0/1 with the newly defined symbols. So don't
429 change these values. The same way, code is assuming that in Relay_log_info we
430 use only values 0/1. I started with using an enum, but enum_variable=1; is not
431 legal so would have required many line changes.
432*/
433#define MYSQL_SLAVE_NOT_RUN 0
434#define MYSQL_SLAVE_RUN_NOT_CONNECT 1
435#define MYSQL_SLAVE_RUN_CONNECT 2
436
437/*
438 If the following is set, if first gives an error, second will be
439 tried. Otherwise, if first fails, we fail.
440*/
441#define SLAVE_FORCE_ALL 4
442
443/* @todo: see if you can change to int */
444bool start_slave_cmd(THD *thd);
445bool stop_slave_cmd(THD *thd);
446bool change_master_cmd(THD *thd);
447int change_master(THD *thd, Master_info *mi, LEX_SOURCE_INFO *lex_mi,
448 bool preserve_logs = false);
449bool reset_slave_cmd(THD *thd);
450bool show_slave_status_cmd(THD *thd);
451bool flush_relay_logs_cmd(THD *thd);
452/**
453 Re-encrypt previous relay logs with current master key for all slave channels.
454
455 @retval false Success.
456 @retval true Error.
457*/
459int flush_relay_logs(Master_info *mi, THD *thd);
460int reset_slave(THD *thd, Master_info *mi, bool reset_all);
461int reset_slave(THD *thd);
463/**
464 Call mi->init_info() and/or mi->rli->init_info(), which will read
465 the replication configuration from repositories.
466
467 This takes care of creating a transaction context in case table
468 repository is needed.
469
470 @param mi The Master_info object to use.
471
472 @param ignore_if_no_info If this is false, and the repository does
473 not exist, it will be created. If this is true, and the repository
474 does not exist, nothing is done.
475
476 @param thread_mask Indicate which repositories will be initialized:
477 if (thread_mask&REPLICA_IO)!=0, then mi->init_info is called; if
478 (thread_mask&REPLICA_SQL)!=0, then mi->rli->init_info is called.
479
480 @param force_load repositories will only read information if they
481 are not yet initialized. When true this flag forces the repositories
482 to load information from table or file.
483
484 @param skip_received_gtid_set_and_relaylog_recovery When true, skips the
485 received GTID set and relay log recovery.
486
487 @retval 0 Success
488 @retval nonzero Error
489*/
491 Master_info *mi, bool ignore_if_no_info, int thread_mask,
492 bool skip_received_gtid_set_and_relaylog_recovery = false,
493 bool force_load = false);
494void end_info(Master_info *mi);
495/**
496 Clear the information regarding the `Master_info` and `Relay_log_info` objects
497 represented by the parameter, meaning, setting to `NULL` all attributes that
498 are not meant to be kept between slave resets.
499
500 @param mi the `Master_info` reference that holds both `Master_info` and
501 `Relay_log_info` data.
502 */
503void clear_info(Master_info *mi);
504int remove_info(Master_info *mi);
505/**
506 Resets the information regarding the `Master_info` and `Relay_log_info`
507 objects represented by the parameter, meaning, setting to `NULL` all
508 attributes that are not meant to be kept between slave resets and persisting
509 all other attribute values in the repository.
510
511 @param mi the `Master_info` reference that holds both `Master_info` and
512 `Relay_log_info` data.
513
514 @returns true if an error occurred and false otherwiser.
515 */
516bool reset_info(Master_info *mi);
517
518/**
519 This method flushes the current configuration for the channel into the
520 connection metadata repository. It will also flush the current contents
521 of the relay log file if instructed to.
522
523 @param mi the `Master_info` reference that holds both `Master_info` and
524 `Relay_log_info` data.
525
526 @param force shall the method ignore the server settings that limit flushes
527 to this repository
528
529 @param need_lock shall the method take the associated data lock and log lock
530 if false ownership is asserted
531
532 @param flush_relay_log should the method also flush the relay log file
533
534 @param skip_repo_persistence if this method shall skip the repository flush
535 This won't skip the relay log flush if
536 flush_relay_log = true
537
538 @returns 0 if no error occurred, !=0 if an error occurred
539*/
540int flush_master_info(Master_info *mi, bool force, bool need_lock = true,
541 bool flush_relay_log = true,
542 bool skip_repo_persistence = false);
543void add_replica_skip_errors(const char *arg);
544void set_replica_skip_errors(char **replica_skip_errors_ptr);
545int add_new_channel(Master_info **mi, const char *channel);
546
547/*
548 Function to check whether replication from a given source MySQL version
549 is allowed for a replica running the specified local version.
550
551 @param source_ver_str Version string reported by the source server
552 @param replica_ver_str Version string of the local replica server
553 @return true If the source version is compatible
554 @return false Otherwise
555*/
556[[nodiscard]] bool is_version_compatible(const char *source_ver_str,
557 const char *replica_ver_str);
558
559/**
560 Terminates the slave threads according to the given mask.
561
562 @param mi the master info repository
563 @param thread_mask the mask identifying which thread(s) to terminate
564 @param stop_wait_timeout the timeout after which the method returns and error
565 @param need_lock_term
566 If @c false the lock will not be acquired before waiting on
567 the condition. In this case, it is assumed that the calling
568 function acquires the lock before calling this function.
569
570 @return the operation status
571 @retval 0 OK
572 @retval ER_REPLICA_NOT_RUNNING
573 The slave is already stopped
574 @retval ER_STOP_REPLICA_SQL_THREAD_TIMEOUT
575 There was a timeout when stopping the SQL thread
576 @retval ER_STOP_REPLICA_IO_THREAD_TIMEOUT
577 There was a timeout when stopping the IO thread
578 @retval ER_ERROR_DURING_FLUSH_LOGS
579 There was an error while flushing the log/repositories
580*/
581int terminate_slave_threads(Master_info *mi, int thread_mask,
582 ulong stop_wait_timeout,
583 bool need_lock_term = true);
584bool start_slave_threads(bool need_lock_slave, bool wait_for_start,
585 Master_info *mi, int thread_mask);
586bool start_slave(THD *thd);
587int stop_slave(THD *thd);
588bool start_slave(THD *thd, LEX_REPLICA_CONNECTION *connection_param,
589 LEX_SOURCE_INFO *master_param, int thread_mask_input,
590 Master_info *mi, bool set_mts_settings);
591int stop_slave(THD *thd, Master_info *mi, bool net_report, bool for_one_channel,
592 bool *push_temp_table_warning);
593/*
594 cond_lock is usually same as start_lock. It is needed for the case when
595 start_lock is 0 which happens if start_slave_thread() is called already
596 inside the start_lock section, but at the same time we want a
597 mysql_cond_wait() on start_cond, start_lock
598*/
600 mysql_mutex_t *start_lock, mysql_mutex_t *cond_lock,
601 mysql_cond_t *start_cond,
602 std::atomic<uint> *slave_running,
603 std::atomic<ulong> *slave_run_id, Master_info *mi);
604
605bool show_slave_status(THD *thd, Master_info *mi);
606bool show_slave_status(THD *thd);
607
608const char *print_slave_db_safe(const char *db);
609
610void end_slave(); /* release slave threads */
611void delete_slave_info_objects(); /* clean up slave threads data */
614
615/// @brief Rotates the relay log
616/// @details Locking order:
617/// a) log_lock, log_space_lock
618/// b) log_lock, end_pos_lock
619/// @param mi Pointer to connection metadata object
620/// @param log_master_fd Information on whether rotate came from:
621/// - true - the origin is replica, this function will insert a source FDE
622/// - false - the origin is the source, we don't need to insert FDE as it
623/// will be send by the source
624/// @param need_lock When true, we acquire relay log lock,
625/// otherwise the caller must hold it
626/// @param need_log_space_lock When true, we acquire the log protecting
627/// data structures responsible for handling the relay_log_space_limit,
628/// otherwise the caller must hold it
629int rotate_relay_log(Master_info *mi, bool log_master_fd = true,
630 bool need_lock = true, bool need_log_space_lock = true);
631typedef enum {
637 ulong event_len, bool flush_mi = true);
638
640 std::string binlog_name, uint64_t position,
641 unsigned long &inc_pos, bool &do_flush_mi);
642
643extern "C" void *handle_slave_io(void *arg);
644extern "C" void *handle_slave_sql(void *arg);
645
646/*
647 SYNPOSIS
648 connect_to_master()
649
650 IMPLEMENTATION
651 Try to connect until successful or replica killed or we have retried
652
653 @param[in] thd The thread.
654 @param[in] mysql MySQL connection handle
655 @param[in] mi The Master_info object of the failed connection which
656 needs to be reconnected to the new source.
657 @param[in] reconnect If its need to reconnect to existing source.
658 @param[in] host The Host name or ip address of the source to which
659 connection need to be made.
660 @param[in] port The Port of the source to which connection need to
661 be made.
662 @param[in] is_io_thread To determine if its IO or Monitor IO thread.
663
664 @retval 0 Success connecting to the source.
665 @retval # Error connecting to the source.
666*/
668 bool suppress_warnings,
669 const std::string &host = std::string(),
670 const uint port = 0, bool is_io_thread = true);
671
672bool net_request_file(NET *net, const char *fname);
673
674extern bool replicate_same_server_id;
675/* the master variables are defaults read from my.cnf or command line */
676extern uint report_port;
677extern char *report_user;
679
681/**
682 Processing rli->gaq to find out the low-water-mark (lwm) coordinates
683 which is stored into the central recovery table. rli->data_lock will be
684 required, so the caller should not hold rli->data_lock.
685
686 @param rli pointer to Relay-log-info of Coordinator
687 @param force if true then hang in a loop till some progress
688 @retval false Success
689 @retval true Error
690*/
691bool mta_checkpoint_routine(Relay_log_info *rli, bool force);
692bool sql_slave_killed(THD *thd, Relay_log_info *rli);
693
694/*
695 Check if the error is caused by network.
696 @param[in] errorno Number of the error.
697 RETURNS:
698 true network error
699 false not network error
700*/
701bool is_network_error(uint errorno);
702
703int init_replica_thread(THD *thd, SLAVE_THD_TYPE thd_type);
704
705/// @brief Enables metric collection for replication structures
706/// It affects new and already created and running channels
708
709/// @brief Disables metric collection for replication structures
710/// It affects new and already created and running channels
712
713/**
714 @} (end of group Replication)
715*/
716#endif
Definition: rpl_mi.h:87
Definition: rpl_rli.h:208
Helper class used to initialize the replica (includes init_replica())
Definition: rpl_replica.h:377
int m_init_code
Replica initialization error code.
Definition: rpl_replica.h:417
int m_thread_mask
Thread mask indicating type of the thread.
Definition: rpl_replica.h:418
bool m_opt_skip_replica_start
Indicates whether replica threads should be started or not.
Definition: rpl_replica.h:415
bool m_opt_initialize_replica
Indicates whether to initialize replica.
Definition: rpl_replica.h:413
The class is a container for all the per-channel filters, both a map of Rpl_filter objects and a list...
Definition: rpl_msr.h:723
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Service class for the Change Streams Applier (CSA)
Definition: csa_service.h:54
bool stop_slave_cmd(THD *thd)
Entry point for the STOP REPLICA command.
Definition: rpl_replica.cc:879
char * replica_load_tmpdir
Definition: rpl_replica.cc:200
QUEUE_EVENT_RESULT
Definition: rpl_replica.h:631
bool opt_log_replica_updates
Definition: mysqld.cc:1280
bool sql_slave_killed(THD *thd, Relay_log_info *rli)
The function analyzes a possible killed status and makes a decision whether to accept it or not.
Definition: rpl_replica.cc:2322
int heartbeat_queue_event(bool is_valid, Master_info *&mi, std::string binlog_name, uint64_t position, unsigned long &inc_pos, bool &do_flush_mi)
Definition: rpl_replica.cc:7679
const char * relay_log_basename
Definition: rpl_replica.cc:205
bool net_request_file(NET *net, const char *fname)
Definition: rpl_replica.cc:2429
bool start_slave_threads(bool need_lock_slave, bool wait_for_start, Master_info *mi, int thread_mask)
Definition: rpl_replica.cc:2114
bool mta_checkpoint_routine(Relay_log_info *rli, bool force)
Processing rli->gaq to find out the low-water-mark (lwm) coordinates which is stored into the central...
Definition: rpl_replica.cc:6626
void clear_info(Master_info *mi)
Clear the information regarding the Master_info and Relay_log_info objects represented by the paramet...
Definition: rpl_replica.cc:1454
ulong source_retry_count
Definition: mysqld.cc:1686
void set_replica_skip_errors(char **replica_skip_errors_ptr)
Change arg to the string with the nice, human-readable skip error values.
Definition: rpl_replica.cc:1641
void start_threads()
This function starts replication threads.
Definition: rpl_replica.cc:549
bool change_master_cmd(THD *thd)
Entry point for the CHANGE REPLICATION SOURCE command.
Definition: rpl_replica.cc:11437
int load_mi_and_rli_from_repositories(Master_info *mi, bool ignore_if_no_info, int thread_mask, bool skip_received_gtid_set_and_relaylog_recovery, bool force_load)
Call mi->init_info() and/or mi->rli->init_info(), which will read the replication configuration from ...
Definition: rpl_replica.cc:1332
char * opt_relay_logname
Definition: mysqld.cc:1688
void end_info(Master_info *mi)
Definition: rpl_replica.cc:1442
bool replicate_same_server_id
Definition: rpl_replica.cc:201
int init_replica_thread(THD *thd, SLAVE_THD_TYPE thd_type)
Definition: rpl_replica.cc:4106
int remove_info(Master_info *mi)
Definition: rpl_replica.cc:1474
char * report_password
Definition: rpl_replica.h:678
ReplicaInitializer(bool opt_initialize, bool opt_skip_replica_start, Rpl_channel_filters &filters, char **replica_skip_erors)
Constructor, calls init_replica()
Definition: rpl_replica.cc:479
const char * print_slave_db_safe(const char *db)
Definition: rpl_replica.cc:2442
bool reencrypt_relay_logs()
Re-encrypt previous relay logs with current master key for all slave channels.
Definition: rpl_replica.cc:9089
QUEUE_EVENT_RESULT queue_event(Master_info *mi, const char *buf, ulong event_len, bool do_flush_mi)
Store an event received from the master connection into the relay log.
Definition: rpl_replica.cc:7870
void disable_applier_metric_collection()
Disables metric collection for replication structures It affects new and already created and running ...
Definition: rpl_replica.cc:11827
bool flush_relay_logs_cmd(THD *thd)
Entry point for FLUSH RELAYLOGS command or to flush relaylogs for the FLUSH LOGS command.
Definition: rpl_replica.cc:9021
char * report_user
Definition: mysqld.cc:1687
static void init_replica_psi_keys()
Initializes replica PSI keys in case PSI interface is available.
Definition: rpl_replica.cc:584
mysql::csa::Csa_service & get_csa_service()
Obtain CSA service reference.
Definition: rpl_replica.h:422
int stop_slave(THD *thd)
Function to stop a slave for all channels.
Definition: rpl_replica.cc:733
int add_new_channel(Master_info **mi, const char *channel)
This function is first called when the Master_info object corresponding to a channel in a multisource...
Definition: rpl_replica.cc:11285
void * handle_slave_io(void *arg)
Slave IO thread entry point.
Definition: rpl_replica.cc:5434
bool reset_slave_cmd(THD *thd)
Entry function for RESET REPLICA command.
Definition: rpl_replica.cc:9661
bool is_network_error(uint errorno)
Definition: rpl_replica.cc:2448
void add_replica_skip_errors(const char *arg)
Definition: rpl_replica.cc:1690
void enable_applier_metric_collection()
Enables metric collection for replication structures It affects new and already created and running c...
Definition: rpl_replica.cc:11823
ulonglong relay_log_space_limit
Definition: rpl_replica.cc:202
bool opt_skip_replica_start
If set, slave is not autostarted.
Definition: mysqld.cc:1275
int rotate_relay_log(Master_info *mi, bool log_master_fd, bool need_lock, bool need_log_space_lock)
Rotates the relay log.
Definition: rpl_replica.cc:8915
void start_replication_threads(bool skip_replica_start=true)
This function starts replication threads.
Definition: rpl_replica.cc:543
bool show_slave_status(THD *thd)
Method to the show the replication status in all channels.
Definition: rpl_replica.cc:3796
void print_channel_info() const
In case debug mode is on, prints channel information.
Definition: rpl_replica.cc:522
bool reset_info(Master_info *mi)
Resets the information regarding the Master_info and Relay_log_info objects represented by the parame...
Definition: rpl_replica.cc:1495
bool opt_collect_replica_applier_metrics
Definition: mysqld.cc:1283
const char * relay_log_index
Definition: rpl_replica.cc:204
int init_replica()
Performs replica initialization, creates default replication channel and sets channel filters.
Definition: rpl_replica.cc:597
int flush_relay_logs(Master_info *mi, THD *thd)
flushes the relay logs of a replication channel.
Definition: rpl_replica.cc:8975
void delete_slave_info_objects()
Free all resources used by slave threads at time of executing shutdown.
Definition: rpl_replica.cc:2241
bool mts_recovery_groups(Relay_log_info *rli)
Definition: rpl_replica.cc:6370
int change_master(THD *thd, Master_info *mi, LEX_SOURCE_INFO *lex_mi, bool preserve_logs)
Execute a CHANGE REPLICATION SOURCE statement.
Definition: rpl_replica.cc:10931
bool start_slave_cmd(THD *thd)
Entry point to the START REPLICA command.
Definition: rpl_replica.cc:780
int flush_master_info(Master_info *mi, bool force, bool need_lock, bool do_flush_relay_log, bool skip_repo_persistence)
This method flushes the current configuration for the channel into the connection metadata repository...
Definition: rpl_replica.cc:1530
char * report_host
Definition: mysqld.cc:1687
uint report_port
Definition: mysqld.cc:1685
bool opt_relaylog_index_name_supplied
Definition: mysqld.cc:1693
bool start_slave_thread(PSI_thread_key thread_key, my_start_routine h_func, mysql_mutex_t *start_lock, mysql_mutex_t *cond_lock, mysql_cond_t *start_cond, std::atomic< uint > *slave_running, std::atomic< ulong > *slave_run_id, Master_info *mi)
Definition: rpl_replica.cc:2038
void set_slave_thread_options(THD *thd)
Set slave thread default options.
Definition: rpl_replica.cc:4037
int get_initialization_code() const
Gets initialization code set-up at replica initialization.
Definition: rpl_replica.cc:477
bool server_id_supplied
Definition: mysqld.cc:1234
char * opt_relaylog_index_name
Definition: rpl_replica.h:359
int connect_to_master(THD *thd, MYSQL *mysql, Master_info *mi, bool reconnect, bool suppress_warnings, const std::string &host, const uint port, bool is_io_thread)
Definition: rpl_replica.cc:8681
int terminate_slave_threads(Master_info *mi, int thread_mask, ulong stop_wait_timeout, bool need_lock_term)
Terminates the slave threads according to the given mask.
Definition: rpl_replica.cc:1762
int init_recovery(Master_info *mi)
Definition: rpl_replica.cc:1214
std::unique_ptr< mysql::csa::Csa_service > csa_service
Global CSA object handle initialized in init_replica.
Definition: rpl_replica.cc:207
char slave_skip_error_names[]
Definition: rpl_replica.cc:198
void end_slave()
Definition: rpl_replica.cc:2210
MY_BITMAP slave_error_mask
Definition: rpl_replica.cc:197
char * opt_binlog_index_name
Definition: mysqld.cc:1717
bool show_slave_status_cmd(THD *thd)
Entry point for SHOW REPLICA STATUS command.
Definition: rpl_replica.cc:3992
void * handle_slave_sql(void *arg)
Slave SQL thread entry point.
Definition: rpl_replica.cc:7124
bool use_slave_mask
Definition: rpl_replica.cc:196
void set_slave_thread_default_charset(THD *thd, Relay_log_info const *rli)
Definition: rpl_replica.cc:4083
bool opt_relay_logname_supplied
Definition: mysqld.cc:1698
bool start_slave(THD *thd)
Function to start a slave for all channels.
Definition: rpl_replica.cc:670
char * opt_replica_skip_errors
Definition: mysqld.cc:1281
bool is_version_compatible(const char *source_ver_str, const char *replica_ver_str)
Definition: rpl_replica.cc:418
@ QUEUE_EVENT_OK
Definition: rpl_replica.h:632
@ QUEUE_EVENT_ERROR_QUEUING
Definition: rpl_replica.h:633
@ QUEUE_EVENT_ERROR_FLUSHING_INFO
Definition: rpl_replica.h:634
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:50
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Defines to make different thread packages compatible.
void *(* my_start_routine)(void *)
Definition: my_thread.h:72
static int reconnect()
Definition: mysql.cc:3371
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
Common definition between mysql server & client.
const char * host
Definition: mysqladmin.cc:66
bool opt_initialize
Definition: mysqld.cc:1274
Definition: buf0block_hint.cc:30
constexpr value_type reset_slave
Definition: classic_protocol_constants.h:314
bool is_valid(const dd::Spatial_reference_system *srs, const Geometry *g, const char *func_name, bool *is_valid) noexcept
Decides if a geometry is valid.
Definition: is_valid.cc:95
Definition: channel.cpp:28
Definition: instrumented_condition_variable.h:32
Definition: buffer.h:45
Performance schema instrumentation interface.
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
const long mts_online_stat_period
Definition: rpl_replica.h:56
SLAVE_THD_TYPE
Definition: rpl_replica.h:60
@ SLAVE_THD_SQL
Definition: rpl_replica.h:62
@ SLAVE_THD_IO
Definition: rpl_replica.h:61
@ SLAVE_THD_WORKER
Definition: rpl_replica.h:63
@ SLAVE_THD_MONITOR
Definition: rpl_replica.h:64
Declarations for the Debug Sync Facility.
Structure to hold parameters for CHANGE REPLICATION SOURCE, START REPLICA, and STOP REPLICA.
Definition: sql_lex.h:370
Definition: mysql.h:303
Definition: my_bitmap.h:43
Definition: mysql_com.h:915
Definition: task.h:427
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: sql_lex.h:2630