MySQL 26.7.0
Source Code Documentation
rpl_msr.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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_MSR_H
25#define RPL_MSR_H
26
27#include "my_config.h"
28
29#include <stddef.h>
30#include <sys/types.h>
31#include <cstdint> // std::ptrdiff_t
32#include <iterator> // std::forward_iterator
33#include <map>
34#include <string>
35#include <utility>
36#include <vector>
37
38#include "my_dbug.h"
39#include "my_psi_config.h"
40#include "sql/mysqld.h" // key_rwlock_channel_map_lock
41#include "sql/rpl_channel_service_interface.h" // enum_channel_type
42#include "sql/rpl_filter.h"
43#include "sql/rpl_gtid.h"
44#include "sql/rpl_io_monitor.h"
45#include "sql/rpl_mi.h"
46
47class Master_info;
48
49/**
50 Maps a channel name to it's Master_info.
51*/
52
53// Maps a master info object to a channel name
54typedef std::map<std::string, Master_info *> mi_map;
55// Maps a channel type to a map of channels of that type.
56typedef std::map<int, mi_map> replication_channel_map;
57// Maps a replication filter to a channel name.
58typedef std::map<std::string, Rpl_filter *> filter_map;
59
60// Deduce the iterator type for a range/collection/container as the return
61// type for begin(). This is usually either T::iterator or T::const_iterator,
62// depending on the const-ness of T.
63template <class T>
64using Iterator_for = decltype(std::begin(std::declval<T>()));
65
66/// Iterator that provides the elements of a nested map as a linear sequence.
67///
68/// This satisfies std::forward_iterator.
69///
70/// @tparam Outer_iterator_t Forward iterator over the outer map.
71///
72/// @tparam outer_is_map If true, the outer map iterator yields pairs, and the
73/// second component of each pair contains the inner map. If false, the outer
74/// map iterator yields inner maps directly.
75///
76/// @tparam inner_is_map If true, the inner map iterator yields pairs, and the
77/// second component of each pair contains the value. If false, the inner
78/// map iterator yields values directly.
79///
80/// @todo move this to a library
81///
82/// @todo support bidirectional/random_access/contiguous iterators when both
83/// maps support it.
84///
85/// @todo Once we have ranges, remove the build-in map support and let users use
86/// Denested_map_view<Map | std::ranges::value_view> |
87/// std::ranges::value_view instead
88template <std::forward_iterator Outer_iterator_t, bool outer_is_map,
89 bool inner_is_map>
91 using Self_t =
93
94 /// @return Reference to the container that the given outer iterator points
95 /// to, taking the 'second' element of the pair in case the outer iterator is
96 /// a map.
97 static auto &mapped_value(const Outer_iterator_t &outer_iterator) {
98 if constexpr (outer_is_map)
99 return outer_iterator->second;
100 else
101 return *outer_iterator;
102 }
103
104 using Inner_map_t = decltype(mapped_value(Outer_iterator_t()));
106
107 /// @return Reference to the value that the given inner iterator points to,
108 /// taking the 'second' element of the pair in case the inner iterator is a
109 /// map.
110 static auto &mapped_value(const Inner_iterator_t &inner_iterator) {
111 if constexpr (inner_is_map)
112 return inner_iterator->second;
113 else
114 return *inner_iterator;
115 }
116
117 public:
119 using difference_type = std::ptrdiff_t;
120
121 /// Default constructor.
122 ///
123 /// The result is an object that is useless in itself since all member
124 /// functions are undefined. It can be assigned or moved to, and it is
125 /// required for iterators to be default-constructible.
127
128 /// Constructor.
129 ///
130 /// @param outer_begin Iterator to the first element of the nested map.
131 ///
132 /// @param outer_end Iterator to the one-past-the-last element of the nested
133 /// map.
134 ///
135 /// @param at_end If true, position at the end; if false, position at the
136 /// beginning.
137 explicit constexpr Denested_map_iterator(const Outer_iterator_t &outer_begin,
138 const Outer_iterator_t &outer_end,
139 bool at_end)
140 : m_outer_begin(outer_begin),
141 m_outer_end(outer_end),
142 m_outer_it(at_end ? outer_end : outer_begin),
143 m_inner_it(m_outer_it == outer_end
147 }
148
149 /// Pre-increment
150 constexpr Self_t &operator++() {
151 ++m_inner_it;
153 return *this;
154 }
155
156 /// Post-increment
157 constexpr Self_t operator++(int) {
158 auto tmp = *this;
159 ++*this;
160 return tmp;
161 }
162
163 /// Dereference
164 constexpr decltype(auto) operator*() const {
165 return mapped_value(m_inner_it);
166 }
167
168 /// Comparison
169 constexpr bool operator==(const Self_t &other) const {
170 // Different outer iterators -> different
171 if (m_outer_it != other.m_outer_it) return false;
172 // Both outer iterators positioned at end -> equal (don't compare inner
173 // iterators)
174 if (m_outer_it == m_outer_end) return true;
175 // Outer iterators point to same inner array -> inner iterators determine
176 // equality.
177 return m_inner_it == other.m_inner_it;
178 }
179
180 private:
181 /// Maintain the invariant that *either* m_outer_it points to the end, *or*
182 /// m_inner_it *doesn't* point to the end.
183 ///
184 /// This may moves the iterators forward until the condition is met.
185 constexpr void skip_inner_end_positions() {
186 if (m_outer_it != m_outer_end) {
187 while (m_inner_it == std::end(mapped_value(m_outer_it))) {
188 ++m_outer_it;
189 if (m_outer_it == m_outer_end) break;
191 }
192 }
193 }
194
195 /// Beginning of outer map.
196 Outer_iterator_t m_outer_begin{};
197
198 /// End of outer map.
199 Outer_iterator_t m_outer_end{};
200
201 /// Iterator to the outer map.
202 Outer_iterator_t m_outer_it{};
203
204 /// Iterator to the inner map, or undefined if the outer map points to the
205 /// end.
207};
208
209/// View over a nested map structure, which provides iterators over the elements
210/// of the second-level map.
211///
212/// For example, a view over std::map<int, std::map<std::string, T>> provides
213/// iterators over the T objects.
214///
215/// @tparam Nested_map_t The nested map type.
216///
217/// @tparam outer_is_map If true, the outer map is assumed to be a map, i.e.,
218/// its iterators yield pairs that hold inner maps in their second components.
219/// Otherwise, it is assumed that iterators of the outer map provide inner maps
220/// directly.
221///
222/// @tparam inner_is_map If true, the inner maps are assumed to be maps, i.e.,
223/// their iterators yield pairs and the view's iterator provides the second
224/// components. Otherwise, the view's iterator provides the values of the
225/// iterators of the inner maps directly.
226template <class Nested_map_t, bool outer_is_map, bool inner_is_map>
229 outer_is_map, inner_is_map>;
230
231 public:
232 Denested_map_view(Nested_map_t &map) : m_map(&map) {}
233
234 auto begin() { return Iterator_t(m_map->begin(), m_map->end(), false); }
235 auto end() { return Iterator_t(m_map->begin(), m_map->end(), true); }
236 auto begin() const { return Iterator_t(m_map->begin(), m_map->end(), false); }
237 auto end() const { return Iterator_t(m_map->begin(), m_map->end(), true); }
238
239 private:
240 Nested_map_t *m_map;
241};
242
243/**
244 Class to store all the Master_info objects of a slave
245 to access them in the replication code base or performance
246 schema replication tables.
247
248 In a Multisourced replication setup, a slave connects
249 to several masters (also called as sources). This class
250 stores the Master_infos where each Master_info belongs
251 to a slave.
252
253 The important objects for a slave are the following:
254 i) Master_info and Relay_log_info (replica_parallel_workers == 0)
255 ii) Master_info, Relay_log_info and Slave_worker(replica_parallel_workers >0 )
256
257 Master_info is always associated with a Relay_log_info per channel.
258 So, it is enough to store Master_infos and call the corresponding
259 Relay_log_info by mi->rli;
260
261 This class is not yet thread safe. Any part of replication code that
262 calls this class member function should always lock the channel_map.
263
264 Only a single global object for a server instance should be created.
265
266 The two important data structures in this class are
267 i) C++ std map to store the Master_info pointers with channel name as a key.
268 These are the base channel maps.
269 @todo Convert to boost after it's introduction.
270
271 ii) C++ std map to store the channel maps with a channel type as its key.
272 This map stores slave channel maps, group replication channels or others
273 iii) An array of Master_info pointers to access from performance schema
274 tables. This array is specifically implemented in a way to make
275 a) pfs indices simple i.e a simple integer counter
276 b) To avoid recalibration of data structure if master info is deleted.
277 * Consider the following high level implementation of a pfs table
278 to make a row.
279 @code
280 highlevel_pfs_funciton()
281 {
282 while(replication_table_xxxx.rnd_next())
283 {
284 do stuff;
285 }
286 }
287 @endcode
288 However, we lock channel_map lock for every rnd_next(); There is a gap
289 where an addition/deletion of a channel would rearrange the map
290 making the integer indices of the pfs table point to a wrong value.
291 Either missing a row or duplicating a row.
292
293 We solve this problem, by using an array exclusively to use in
294 replciation pfs tables, by marking a master_info defeated as 0
295 (i.e NULL). A new master info is added to this array at the
296 first NULL always.
297*/
299 private:
300 /* Maximum number of channels per slave */
301 static const unsigned int MAX_CHANNELS = 256;
302
303 /* A Map that maps, a channel name to a Master_info grouped by channel type */
305
306 /* Number of master_infos at the moment*/
308
309 /**
310 Default_channel for this instance, currently is predefined
311 and cannot be modified.
312 */
313 static const char *default_channel;
316
317 /**
318 This lock was designed to protect the channel_map from adding or removing
319 master_info objects from the map (adding or removing replication channels).
320 In fact it also acts like the LOCK_active_mi of MySQL 5.6, preventing two
321 replication administrative commands to run in parallel.
322 */
324
325 /// In order to avoid locks when gathering
326 /// statistics, CSA needs to have a unique size_t identifier pinned to each
327 /// channel. This is maximum id of the channel that was created.
328 std::size_t m_channel_counter{0};
329 /// Ids restored from channels that have been removed from multi-source info
330 std::vector<std::size_t> m_restored_channels_ids;
331
332#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
333
334 /* Array for replication performance schema related tables */
336
337#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
338
339 /*
340 A empty mi_map to allow Multisource_info::end() to return a
341 valid constant value.
342 */
344
345 public:
346 /* Constructor for this class.*/
348 /*
349 This class should be a singleton.
350 The assert below is to prevent it to be instantiated more than once.
351 */
352#ifndef NDEBUG
353 static int instance_count = 0;
354 instance_count++;
355 assert(instance_count == 1);
356#endif
358 default_channel_mi = nullptr;
359#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
361#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
362
366#endif
367 );
368 }
369
370 /* Destructor for this class.*/
372
373 /**
374 Adds the Master_info object to both replication_channel_map and rpl_pfs_mi
375
376 @param[in] channel_name channel name
377 @param[in] mi pointer to master info corresponding
378 to this channel
379 @retval false successfully added
380 @retval true couldn't add channel
381 */
382 bool add_mi(const char *channel_name, Master_info *mi);
383
384 /**
385 Find the master_info object corresponding to a channel explicitly
386 from replication channel_map;
387 Return if it exists, otherwise return 0
388
389 @param[in] channel_name channel name for the master info object.
390
391 @returns pointer to the master info object if exists
392 in the map. Otherwise, NULL;
393 */
394 Master_info *get_mi(const char *channel_name);
395
396 /**
397 Return the master_info object corresponding to the default channel.
398 @retval pointer to the master info object if exists.
399 Otherwise, NULL;
400 */
403 return default_channel_mi;
404 }
405
406 /**
407 Remove the entry corresponding to the channel, from the
408 replication_channel_map and sets index in the multisource_mi to 0;
409 And also delete the {mi, rli} pair corresponding to this channel
410
411 @note this requires the caller to hold the mi->channel_wrlock.
412 If the method succeeds the master info object is deleted and the lock
413 is released. If the an error occurs and the method return true, the {mi}
414 object won't be deleted and the caller should release the channel_wrlock.
415
416 @param[in] channel_name Name of the channel for a Master_info
417 object which must exist.
418
419 @return true if an error occurred, false otherwise
420 */
421 bool delete_mi(const char *channel_name);
422
423 /**
424 Get the default channel for this multisourced_slave;
425 */
426 inline const char *get_default_channel() { return default_channel; }
427
428 /**
429 Get the number of instances of Master_info in the map.
430
431 @param all If it should count all channels.
432 If false, only slave channels are counted.
433
434 @return The number of channels or 0 if empty.
435 */
436 inline size_t get_num_instances(bool all = false) {
438
440
441 replication_channel_map::iterator map_it;
442
443 if (all) {
444 size_t count = 0;
445
446 for (map_it = rep_channel_map.begin(); map_it != rep_channel_map.end();
447 map_it++) {
448 count += map_it->second.size();
449 }
450 return count;
451 } else // Return only the slave channels
452 {
454
455 if (map_it == rep_channel_map.end())
456 return 0;
457 else
458 return map_it->second.size();
459 }
460 }
461
462 /**
463 Get the number of configured asynchronous replication channels,
464 ignoring the Group Replication channels.
465
466 @return The number of channels.
467 */
471 size_t count = 0;
472
473 replication_channel_map::iterator map_it =
475
476 for (mi_map::iterator it = map_it->second.begin();
477 it != map_it->second.end(); it++) {
478 Master_info *mi = it->second;
480 count++;
481 }
482 }
483
484 return count;
485 }
486
487 /**
488 Get the number of running channels which have asynchronous replication
489 failover feature, i.e. CHANGE REPLICATION SOURCE TO option
490 SOURCE_CONNECTION_AUTO_FAILOVER, enabled.
491
492 @return The number of channels.
493 */
497 size_t count = 0;
498
499 replication_channel_map::iterator map_it =
501
502 for (mi_map::iterator it = map_it->second.begin();
503 it != map_it->second.end(); it++) {
504 Master_info *mi = it->second;
508 if (mi->slave_running || mi->is_error()) {
509 count++;
510 }
512 }
513 }
514
515#ifndef NDEBUG
516 if (Source_IO_monitor::get_instance()->is_monitoring_process_running()) {
517 assert(count > 0);
518 }
519#endif
520
521 return count;
522 }
523
524 /**
525 Get max channels allowed for this map.
526 */
527 inline uint get_max_channels() { return MAX_CHANNELS; }
528
529 /**
530 Returns true if the current number of channels in this slave
531 is less than the MAX_CHANNLES
532 */
536 DBUG_EXECUTE_IF("max_replication_channels_exceeded", is_valid = false;);
537 return (is_valid);
538 }
539
540 /// @brief Checks if a channel is the group replication applier channel
541 /// @param[in] channel Name of the channel to check
542 /// @returns true if it is the gr applier channel
543 static bool is_group_replication_applier_channel_name(const char *channel);
544
545 /// @brief Checks if a channel is the group replication recovery channel
546 /// @param[in] channel Name of the channel to check
547 /// @returns true if it is the gr recovery channel
549
550 /**
551 Returns if a channel name is one of the reserved group replication names
552
553 @param channel the channel name to test
554
555 @retval true the name is a reserved name
556 @retval false non reserved name
557 */
558 static bool is_group_replication_channel_name(const char *channel);
559
560 /// @brief Check if the channel has an hostname or is a GR channel
561 /// @return true if the channel is configured or is a gr channel,
562 /// false otherwise
563 static bool is_channel_configured(const Master_info *mi) {
564 return mi && (mi->host[0] ||
566 }
567
568 /**
569 Forward iterators to initiate traversing of a map.
570
571 @todo: Not to expose iterators. But instead to return
572 only Master_infos or create generators when
573 c++11 is introduced.
574 */
575 mi_map::iterator begin(
577 replication_channel_map::iterator map_it;
578 map_it = rep_channel_map.find(channel_type);
579
580 if (map_it != rep_channel_map.end()) {
581 return map_it->second.begin();
582 }
583
584 return end(channel_type);
585 }
586
587 mi_map::iterator end(
589 replication_channel_map::iterator map_it;
590 map_it = rep_channel_map.find(channel_type);
591
592 if (map_it != rep_channel_map.end()) {
593 return map_it->second.end();
594 }
595
596 return empty_mi_map.end();
597 }
598
602 }
603
604 auto all_channels_view() const {
607 }
608
609 private:
610#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
611
612 /* Initialize the rpl_pfs_mi array to NULLs */
613 inline void init_rpl_pfs_mi() {
614 for (uint i = 0; i < MAX_CHANNELS; i++) rpl_pfs_mi[i] = nullptr;
615 }
616
617 /**
618 Add a master info pointer to the rpl_pfs_mi array at the first
619 NULL;
620
621 @param[in] mi master info object to be added.
622
623 @return false if success.Else true.
624 */
626
627 /**
628 Get the index of the master info corresponding to channel name
629 from the rpl_pfs_mi array.
630 @param[in] channel_name Channel name to get the index from
631
632 @return index of mi for the channel_name. Else -1;
633 */
634 int get_index_from_rpl_pfs_mi(const char *channel_name);
635
636 /// Helper function called during channel creation in order to prepare
637 /// metadata unilized by CSA service (unique
638 /// channel identifier, statistics initialization...).
639 /// @param rli RLI pointer for newly created channel
640 /// @return False if succeeded. True otherwise.
642
643 public:
644 /**
645 Used only by replication performance schema indices to get the master_info
646 at the position 'pos' from the rpl_pfs_mi array.
647
648 @param[in] pos the index in the rpl_pfs_mi array
649
650 @retval pointer to the master info object at pos 'pos';
651 */
652 Master_info *get_mi_at_pos(uint pos);
653#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
654
655 /**
656 Acquire the read lock.
657 */
658 inline void rdlock() { m_channel_map_lock->rdlock(); }
659
660 /**
661 Try to acquire a read lock, return 0 if the read lock is held,
662 otherwise an error will be returned.
663
664 @return 0 in case of success, or 1 otherwise.
665 */
666 inline int tryrdlock() { return m_channel_map_lock->tryrdlock(); }
667
668 /**
669 Acquire the write lock.
670 */
671 inline void wrlock() { m_channel_map_lock->wrlock(); }
672
673 /**
674 Try to acquire a write lock, return 0 if the write lock is held,
675 otherwise an error will be returned.
676
677 @return 0 in case of success, or 1 otherwise.
678 */
679 inline int trywrlock() { return m_channel_map_lock->trywrlock(); }
680
681 /**
682 Release the lock (whether it is a write or read lock).
683 */
684 inline void unlock() { m_channel_map_lock->unlock(); }
685
686 /**
687 Assert that some thread holds either the read or the write lock.
688 */
689 inline void assert_some_lock() const {
691 }
692
693 /**
694 Assert that some thread holds the write lock.
695 */
696 inline void assert_some_wrlock() const {
698 }
699};
700
701/**
702 The class is a container for all the per-channel filters, both a map of
703 Rpl_filter objects and a list of Rpl_pfs_filter objects.
704 It maintains a filter map which maps a replication filter to a channel
705 name. Which is needed, because replication channels are not created and
706 channel_map is not filled in when these global and per-channel replication
707 filters are evaluated with current code frame.
708 In theory, after instantiating all channels from the repository and throwing
709 all the warnings about the filters configured for non-existent channels, we
710 can forget about its global object rpl_channel_filters and rely only on the
711 global and per channel Rpl_filter objects. But to avoid holding the
712 channel_map.rdlock() when querying P_S.replication_applier_filters table,
713 we keep the rpl_channel_filters. So that we just need to hold the small
714 rpl_channel_filters.rdlock() when querying P_S.replication_applier_filters
715 table. Many operations (RESET REPLICA [FOR CHANNEL], START REPLICA, INIT
716 SLAVE, END SLAVE, CHANGE REPLICATION SOURCE TO, FLUSH RELAY LOGS, START
717 CHANNEL, PURGE CHANNEL, and so on) hold the channel_map.wrlock().
718
719 There is one instance, rpl_channel_filters, created globally for Multisource
720 channel filters. The rpl_channel_filters is created when the server is
721 started, destroyed when the server is stopped.
722*/
724 private:
725 /* Store all replication filters with channel names. */
727 /* Store all Rpl_pfs_filter objects in the channel_to_filter. */
728 std::vector<Rpl_pfs_filter> rpl_pfs_filter_vec;
729 /*
730 This lock was designed to protect the channel_to_filter from reading,
731 adding, or removing its objects from the map. It is used to preventing
732 the following commands to run in parallel:
733 RESET REPLICA ALL [FOR CHANNEL '<channel_name>']
734 CHANGE REPLICATION SOURCE TO ... FOR CHANNEL
735 SELECT FROM performance_schema.replication_applier_filters
736
737 Please acquire a wrlock when modifying the map structure (RESET REPLICA ALL
738 [FOR CHANNEL '<channel_name>'], CHANGE REPLICATION SOURCE TO ... FOR
739 CHANNEL). Please acqurie a rdlock when querying existing filter(s) (SELECT
740 FROM performance_schema.replication_applier_filters).
741
742 Note: To modify the object from the map, please see the protection of
743 m_rpl_filter_lock in Rpl_filter.
744 */
746
747 public:
748 /**
749 Create a new replication filter and add it into a filter map.
750
751 @param channel_name A name of a channel.
752
753 @retval Rpl_filter A pointer to a replication filter, or NULL
754 if we failed to add it into fiter_map.
755 */
756 Rpl_filter *create_filter(const char *channel_name);
757 /**
758 Delete the replication filter from the filter map.
759
760 @param rpl_filter A pointer to point to a replication filter.
761 */
763 /**
764 Discard all replication filters if they are not attached to channels.
765 */
767 /**
768 discard filters on group replication channels.
769 */
771 /**
772 Get a replication filter of a channel.
773
774 @param channel_name A name of a channel.
775
776 @retval Rpl_filter A pointer to a replication filter, or NULL
777 if we failed to add a replication filter
778 into fiter_map when creating it.
779 */
780 Rpl_filter *get_channel_filter(const char *channel_name);
781
782#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
783
784 /**
785 This member function is called every time a filter is created or deleted,
786 or its filter rules are changed. Once that happens the PFS view is
787 recreated.
788 */
789 void reset_pfs_view();
790
791 /**
792 Used only by replication performance schema indices to get the replication
793 filter at the position 'pos' from the rpl_pfs_filter_vec vector.
794
795 @param pos the index in the rpl_pfs_filter_vec vector.
796
797 @retval Rpl_filter A pointer to a Rpl_pfs_filter, or NULL if it
798 arrived the end of the rpl_pfs_filter_vec.
799 */
801 /**
802 Used only by replication performance schema indices to get the count
803 of replication filters from the rpl_pfs_filter_vec vector.
804
805 @retval the count of the replication filters.
806 */
807 uint get_filter_count();
808#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
809
810 /**
811 Traverse the filter map, build do_table and ignore_table
812 rules to hashes for every filter.
813
814 @retval
815 0 OK
816 @retval
817 -1 Error
818 */
820
821 /* Constructor for this class.*/
826#endif
827 );
828 }
829
830 /* Destructor for this class. */
832
833 /**
834 Traverse the filter map and free all filters. Delete all objects
835 in the rpl_pfs_filter_vec vector and then clear the vector.
836 */
837 void clean_up() {
838 /* Traverse the filter map and free all filters */
839 for (filter_map::iterator it = channel_to_filter.begin();
840 it != channel_to_filter.end(); it++) {
841 if (it->second != nullptr) {
842 delete it->second;
843 it->second = nullptr;
844 }
845 }
846
847 rpl_pfs_filter_vec.clear();
848 }
849
850 /**
851 Acquire the write lock.
852 */
854
855 /**
856 Acquire the read lock.
857 */
859
860 /**
861 Release the lock (whether it is a write or read lock).
862 */
864};
865
866/* Global object for multisourced slave. */
868
869/* Global object for storing per-channel replication filters */
871
872static bool inline is_slave_configured() {
873 /* Server was started with server_id == 0
874 OR
875 failure to load applier metadata repositories
876 */
877 return (channel_map.get_default_channel_mi() != nullptr);
878}
879
880#endif /*RPL_MSR_H*/
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:326
int trywrlock()
Return 0 if the write lock is held, otherwise an error will be returned.
Definition: rpl_gtid.h:539
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:487
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:496
int tryrdlock()
Return 0 if the read lock is held, otherwise an error will be returned.
Definition: rpl_gtid.h:558
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_gtid.h:573
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:507
void assert_some_wrlock() const
Assert that some thread holds the write lock.
Definition: rpl_gtid.h:577
Iterator that provides the elements of a nested map as a linear sequence.
Definition: rpl_msr.h:90
decltype(mapped_value(Outer_iterator_t())) Inner_map_t
Definition: rpl_msr.h:104
std::ptrdiff_t difference_type
Definition: rpl_msr.h:119
static auto & mapped_value(const Outer_iterator_t &outer_iterator)
Definition: rpl_msr.h:97
constexpr Self_t & operator++()
Pre-increment.
Definition: rpl_msr.h:150
Outer_iterator_t m_outer_end
End of outer map.
Definition: rpl_msr.h:199
constexpr Denested_map_iterator(const Outer_iterator_t &outer_begin, const Outer_iterator_t &outer_end, bool at_end)
Constructor.
Definition: rpl_msr.h:137
Outer_iterator_t m_outer_begin
Beginning of outer map.
Definition: rpl_msr.h:196
Iterator_for< Inner_map_t > Inner_iterator_t
Definition: rpl_msr.h:105
decltype(mapped_value(Inner_iterator_t())) value_type
Definition: rpl_msr.h:118
Outer_iterator_t m_outer_it
Iterator to the outer map.
Definition: rpl_msr.h:202
constexpr void skip_inner_end_positions()
Maintain the invariant that either m_outer_it points to the end, or m_inner_it doesn't point to the e...
Definition: rpl_msr.h:185
Inner_iterator_t m_inner_it
Iterator to the inner map, or undefined if the outer map points to the end.
Definition: rpl_msr.h:206
constexpr Self_t operator++(int)
Post-increment.
Definition: rpl_msr.h:157
constexpr bool operator==(const Self_t &other) const
Comparison.
Definition: rpl_msr.h:169
Denested_map_iterator()=default
Default constructor.
static auto & mapped_value(const Inner_iterator_t &inner_iterator)
Definition: rpl_msr.h:110
View over a nested map structure, which provides iterators over the elements of the second-level map.
Definition: rpl_msr.h:227
auto begin() const
Definition: rpl_msr.h:236
Denested_map_iterator< Iterator_for< Nested_map_t >, outer_is_map, inner_is_map > Iterator_t
Definition: rpl_msr.h:229
auto end()
Definition: rpl_msr.h:235
auto begin()
Definition: rpl_msr.h:234
Denested_map_view(Nested_map_t &map)
Definition: rpl_msr.h:232
Nested_map_t * m_map
Definition: rpl_msr.h:240
auto end() const
Definition: rpl_msr.h:237
Definition: rpl_mi.h:87
bool is_source_connection_auto_failover()
Checks if Asynchronous Replication Connection Failover feature is enabled.
Definition: rpl_mi.h:545
static bool is_configured(Master_info *mi)
Definition: rpl_mi.h:109
char host[HOSTNAME_LENGTH+1]
Host name or ip address stored in the master.info.
Definition: rpl_mi.h:99
Class to store all the Master_info objects of a slave to access them in the replication code base or ...
Definition: rpl_msr.h:298
Master_info * get_mi_at_pos(uint pos)
Used only by replication performance schema indices to get the master_info at the position 'pos' from...
Definition: rpl_msr.cc:247
bool add_mi_to_rpl_pfs_mi(Master_info *mi)
Add a master info pointer to the rpl_pfs_mi array at the first NULL;.
Definition: rpl_msr.cc:216
Multisource_info()
Definition: rpl_msr.h:347
size_t get_number_of_connection_auto_failover_channels_running()
Get the number of running channels which have asynchronous replication failover feature,...
Definition: rpl_msr.h:494
mi_map::iterator end(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Definition: rpl_msr.h:587
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_msr.h:689
static const char * group_replication_channel_names[]
Definition: rpl_msr.h:315
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:671
static const char * default_channel
Default_channel for this instance, currently is predefined and cannot be modified.
Definition: rpl_msr.h:313
size_t get_number_of_configured_channels()
Get the number of configured asynchronous replication channels, ignoring the Group Replication channe...
Definition: rpl_msr.h:468
std::vector< std::size_t > m_restored_channels_ids
Ids restored from channels that have been removed from multi-source info.
Definition: rpl_msr.h:330
int trywrlock()
Try to acquire a write lock, return 0 if the write lock is held, otherwise an error will be returned.
Definition: rpl_msr.h:679
Master_info * get_default_channel_mi()
Return the master_info object corresponding to the default channel.
Definition: rpl_msr.h:401
int get_index_from_rpl_pfs_mi(const char *channel_name)
Get the index of the master info corresponding to channel name from the rpl_pfs_mi array.
Definition: rpl_msr.cc:234
uint get_max_channels()
Get max channels allowed for this map.
Definition: rpl_msr.h:527
void init_rpl_pfs_mi()
Definition: rpl_msr.h:613
Checkable_rwlock * m_channel_map_lock
This lock was designed to protect the channel_map from adding or removing master_info objects from th...
Definition: rpl_msr.h:323
Master_info * default_channel_mi
Definition: rpl_msr.h:314
uint current_mi_count
Definition: rpl_msr.h:307
static bool is_group_replication_applier_channel_name(const char *channel)
Checks if a channel is the group replication applier channel.
Definition: rpl_msr.cc:199
std::size_t m_channel_counter
In order to avoid locks when gathering statistics, CSA needs to have a unique size_t identifier pinne...
Definition: rpl_msr.h:328
bool delete_mi(const char *channel_name)
Remove the entry corresponding to the channel, from the replication_channel_map and sets index in the...
Definition: rpl_msr.cc:130
static bool is_group_replication_recovery_channel_name(const char *channel)
Checks if a channel is the group replication recovery channel.
Definition: rpl_msr.cc:204
~Multisource_info()
Definition: rpl_msr.h:371
auto all_channels_view()
Definition: rpl_msr.h:599
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:658
static bool is_group_replication_channel_name(const char *channel)
Returns if a channel name is one of the reserved group replication names.
Definition: rpl_msr.cc:209
void assert_some_wrlock() const
Assert that some thread holds the write lock.
Definition: rpl_msr.h:696
bool add_mi(const char *channel_name, Master_info *mi)
Adds the Master_info object to both replication_channel_map and rpl_pfs_mi.
Definition: rpl_msr.cc:54
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_msr.h:684
mi_map::iterator begin(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Forward iterators to initiate traversing of a map.
Definition: rpl_msr.h:575
auto all_channels_view() const
Definition: rpl_msr.h:604
Master_info * get_mi(const char *channel_name)
Find the master_info object corresponding to a channel explicitly from replication channel_map; Retur...
Definition: rpl_msr.cc:99
bool is_valid_channel_count()
Returns true if the current number of channels in this slave is less than the MAX_CHANNLES.
Definition: rpl_msr.h:533
const char * get_default_channel()
Get the default channel for this multisourced_slave;.
Definition: rpl_msr.h:426
int tryrdlock()
Try to acquire a read lock, return 0 if the read lock is held, otherwise an error will be returned.
Definition: rpl_msr.h:666
Master_info * rpl_pfs_mi[MAX_CHANNELS]
Definition: rpl_msr.h:335
replication_channel_map rep_channel_map
Definition: rpl_msr.h:304
bool prepare_csa_service_metadata(Relay_log_info *rli)
Helper function called during channel creation in order to prepare metadata unilized by CSA service (...
Definition: rpl_msr.cc:41
static bool is_channel_configured(const Master_info *mi)
Check if the channel has an hostname or is a GR channel.
Definition: rpl_msr.h:563
mi_map empty_mi_map
Definition: rpl_msr.h:343
static const unsigned int MAX_CHANNELS
Definition: rpl_msr.h:301
size_t get_num_instances(bool all=false)
Get the number of instances of Master_info in the map.
Definition: rpl_msr.h:436
Definition: rpl_rli.h:208
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
Checkable_rwlock * m_channel_to_filter_lock
Definition: rpl_msr.h:745
uint get_filter_count()
Used only by replication performance schema indices to get the count of replication filters from the ...
Definition: rpl_msr.cc:404
Rpl_pfs_filter * get_filter_at_pos(uint pos)
Used only by replication performance schema indices to get the replication filter at the position 'po...
Definition: rpl_msr.cc:394
Rpl_filter * get_channel_filter(const char *channel_name)
Get a replication filter of a channel.
Definition: rpl_msr.cc:356
std::vector< Rpl_pfs_filter > rpl_pfs_filter_vec
Definition: rpl_msr.h:728
void reset_pfs_view()
This member function is called every time a filter is created or deleted, or its filter rules are cha...
Definition: rpl_msr.cc:379
void clean_up()
Traverse the filter map and free all filters.
Definition: rpl_msr.h:837
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_msr.h:863
void delete_filter(Rpl_filter *rpl_filter)
Delete the replication filter from the filter map.
Definition: rpl_msr.cc:286
void discard_group_replication_filters()
discard filters on group replication channels.
Definition: rpl_msr.cc:307
void discard_all_unattached_filters()
Discard all replication filters if they are not attached to channels.
Definition: rpl_msr.cc:325
Rpl_channel_filters()
Definition: rpl_msr.h:822
bool build_do_and_ignore_table_hashes()
Traverse the filter map, build do_table and ignore_table rules to hashes for every filter.
Definition: rpl_msr.cc:413
filter_map channel_to_filter
Definition: rpl_msr.h:726
Rpl_filter * create_filter(const char *channel_name)
Create a new replication filter and add it into a filter map.
Definition: rpl_msr.cc:257
~Rpl_channel_filters()
Definition: rpl_msr.h:831
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:853
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:858
Rpl_filter.
Definition: rpl_filter.h:214
char * get_channel() const
Definition: rpl_info.h:125
std::atomic< uint > slave_running
Definition: rpl_info.h:82
The class Rpl_pfs_filter is introduced to serve the performance_schema.replication_applier_filters ta...
Definition: rpl_filter.h:167
mysql_mutex_t err_lock
lock used to synchronize m_last_error on 'SHOW REPLICA STATUS'
Definition: rpl_reporting.h:58
bool is_error() const
Definition: rpl_reporting.h:156
static Source_IO_monitor * get_instance()
Fetch Source_IO_monitor class instance.
Definition: rpl_io_monitor.cc:1103
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
#define DBUG_TRACE
Definition: my_dbug.h:146
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:39
static int count
Definition: myisam_ftdump.cc:45
PSI_rwlock_key key_rwlock_channel_to_filter_lock
Definition: mysqld.cc:14165
PSI_rwlock_key key_rwlock_channel_map_lock
Definition: mysqld.cc:14161
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
const char * begin(const char *const c)
Definition: base64.h:44
Define std::hash<Gtid>.
Definition: gtid.h:355
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2742
enum_channel_type
Types of channels.
Definition: rpl_channel_service_interface.h:51
@ SLAVE_REPLICATION_CHANNEL
Definition: rpl_channel_service_interface.h:52
Rpl_filter * rpl_filter
decltype(std::begin(std::declval< T >())) Iterator_for
Definition: rpl_msr.h:64
std::map< std::string, Master_info * > mi_map
Maps a channel name to it's Master_info.
Definition: rpl_msr.h:47
static bool is_slave_configured()
Definition: rpl_msr.h:872
std::map< std::string, Rpl_filter * > filter_map
Definition: rpl_msr.h:58
Multisource_info channel_map
Definition: rpl_msr.cc:434
std::map< int, mi_map > replication_channel_map
Definition: rpl_msr.h:56
Rpl_channel_filters rpl_channel_filters
Definition: rpl_msr.cc:436
Definition: task.h:427