MySQL 9.1.0
Source Code Documentation
rpl_msr.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 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#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
326
327 /* Array for replication performance schema related tables */
329
330#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
331
332 /*
333 A empty mi_map to allow Multisource_info::end() to return a
334 valid constant value.
335 */
337
338 public:
339 /* Constructor for this class.*/
341 /*
342 This class should be a singleton.
343 The assert below is to prevent it to be instantiated more than once.
344 */
345#ifndef NDEBUG
346 static int instance_count = 0;
347 instance_count++;
348 assert(instance_count == 1);
349#endif
351 default_channel_mi = nullptr;
352#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
354#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
355
359#endif
360 );
361 }
362
363 /* Destructor for this class.*/
365
366 /**
367 Adds the Master_info object to both replication_channel_map and rpl_pfs_mi
368
369 @param[in] channel_name channel name
370 @param[in] mi pointer to master info corresponding
371 to this channel
372 @retval false successfully added
373 @retval true couldn't add channel
374 */
375 bool add_mi(const char *channel_name, Master_info *mi);
376
377 /**
378 Find the master_info object corresponding to a channel explicitly
379 from replication channel_map;
380 Return if it exists, otherwise return 0
381
382 @param[in] channel_name channel name for the master info object.
383
384 @returns pointer to the master info object if exists
385 in the map. Otherwise, NULL;
386 */
387 Master_info *get_mi(const char *channel_name);
388
389 /**
390 Return the master_info object corresponding to the default channel.
391 @retval pointer to the master info object if exists.
392 Otherwise, NULL;
393 */
396 return default_channel_mi;
397 }
398
399 /**
400 Remove the entry corresponding to the channel, from the
401 replication_channel_map and sets index in the multisource_mi to 0;
402 And also delete the {mi, rli} pair corresponding to this channel
403
404 @note this requires the caller to hold the mi->channel_wrlock.
405 If the method succeeds the master info object is deleted and the lock
406 is released. If the an error occurs and the method return true, the {mi}
407 object won't be deleted and the caller should release the channel_wrlock.
408
409 @param[in] channel_name Name of the channel for a Master_info
410 object which must exist.
411
412 @return true if an error occurred, false otherwise
413 */
414 bool delete_mi(const char *channel_name);
415
416 /**
417 Get the default channel for this multisourced_slave;
418 */
419 inline const char *get_default_channel() { return default_channel; }
420
421 /**
422 Get the number of instances of Master_info in the map.
423
424 @param all If it should count all channels.
425 If false, only slave channels are counted.
426
427 @return The number of channels or 0 if empty.
428 */
429 inline size_t get_num_instances(bool all = false) {
431
433
434 replication_channel_map::iterator map_it;
435
436 if (all) {
437 size_t count = 0;
438
439 for (map_it = rep_channel_map.begin(); map_it != rep_channel_map.end();
440 map_it++) {
441 count += map_it->second.size();
442 }
443 return count;
444 } else // Return only the slave channels
445 {
447
448 if (map_it == rep_channel_map.end())
449 return 0;
450 else
451 return map_it->second.size();
452 }
453 }
454
455 /**
456 Get the number of running channels which have asynchronous replication
457 failover feature, i.e. CHANGE REPLICATION SOURCE TO option
458 SOURCE_CONNECTION_AUTO_FAILOVER, enabled.
459
460 @return The number of channels.
461 */
465 size_t count = 0;
466
467 replication_channel_map::iterator map_it =
469
470 for (mi_map::iterator it = map_it->second.begin();
471 it != map_it->second.end(); it++) {
472 Master_info *mi = it->second;
476 if (mi->slave_running || mi->is_error()) {
477 count++;
478 }
480 }
481 }
482
483#ifndef NDEBUG
484 if (Source_IO_monitor::get_instance()->is_monitoring_process_running()) {
485 assert(count > 0);
486 }
487#endif
488
489 return count;
490 }
491
492 /**
493 Get max channels allowed for this map.
494 */
495 inline uint get_max_channels() { return MAX_CHANNELS; }
496
497 /**
498 Returns true if the current number of channels in this slave
499 is less than the MAX_CHANNLES
500 */
504 DBUG_EXECUTE_IF("max_replication_channels_exceeded", is_valid = false;);
505 return (is_valid);
506 }
507
508 /// @brief Checks if a channel is the group replication applier channel
509 /// @param[in] channel Name of the channel to check
510 /// @returns true if it is the gr applier channel
511 static bool is_group_replication_applier_channel_name(const char *channel);
512
513 /// @brief Checks if a channel is the group replication recovery channel
514 /// @param[in] channel Name of the channel to check
515 /// @returns true if it is the gr recovery channel
517
518 /**
519 Returns if a channel name is one of the reserved group replication names
520
521 @param channel the channel name to test
522
523 @retval true the name is a reserved name
524 @retval false non reserved name
525 */
526 static bool is_group_replication_channel_name(const char *channel);
527
528 /// @brief Check if the channel has an hostname or is a GR channel
529 /// @return true if the channel is configured or is a gr channel,
530 /// false otherwise
531 static bool is_channel_configured(const Master_info *mi) {
532 return mi && (mi->host[0] ||
534 }
535
536 /**
537 Forward iterators to initiate traversing of a map.
538
539 @todo: Not to expose iterators. But instead to return
540 only Master_infos or create generators when
541 c++11 is introduced.
542 */
543 mi_map::iterator begin(
545 replication_channel_map::iterator map_it;
546 map_it = rep_channel_map.find(channel_type);
547
548 if (map_it != rep_channel_map.end()) {
549 return map_it->second.begin();
550 }
551
552 return end(channel_type);
553 }
554
555 mi_map::iterator end(
557 replication_channel_map::iterator map_it;
558 map_it = rep_channel_map.find(channel_type);
559
560 if (map_it != rep_channel_map.end()) {
561 return map_it->second.end();
562 }
563
564 return empty_mi_map.end();
565 }
566
570 }
571
572 auto all_channels_view() const {
575 }
576
577 private:
578#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
579
580 /* Initialize the rpl_pfs_mi array to NULLs */
581 inline void init_rpl_pfs_mi() {
582 for (uint i = 0; i < MAX_CHANNELS; i++) rpl_pfs_mi[i] = nullptr;
583 }
584
585 /**
586 Add a master info pointer to the rpl_pfs_mi array at the first
587 NULL;
588
589 @param[in] mi master info object to be added.
590
591 @return false if success.Else true.
592 */
594
595 /**
596 Get the index of the master info corresponding to channel name
597 from the rpl_pfs_mi array.
598 @param[in] channel_name Channel name to get the index from
599
600 @return index of mi for the channel_name. Else -1;
601 */
602 int get_index_from_rpl_pfs_mi(const char *channel_name);
603
604 public:
605 /**
606 Used only by replication performance schema indices to get the master_info
607 at the position 'pos' from the rpl_pfs_mi array.
608
609 @param[in] pos the index in the rpl_pfs_mi array
610
611 @retval pointer to the master info object at pos 'pos';
612 */
613 Master_info *get_mi_at_pos(uint pos);
614#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
615
616 /**
617 Acquire the read lock.
618 */
619 inline void rdlock() { m_channel_map_lock->rdlock(); }
620
621 /**
622 Try to acquire a read lock, return 0 if the read lock is held,
623 otherwise an error will be returned.
624
625 @return 0 in case of success, or 1 otherwise.
626 */
627 inline int tryrdlock() { return m_channel_map_lock->tryrdlock(); }
628
629 /**
630 Acquire the write lock.
631 */
632 inline void wrlock() { m_channel_map_lock->wrlock(); }
633
634 /**
635 Try to acquire a write lock, return 0 if the write lock is held,
636 otherwise an error will be returned.
637
638 @return 0 in case of success, or 1 otherwise.
639 */
640 inline int trywrlock() { return m_channel_map_lock->trywrlock(); }
641
642 /**
643 Release the lock (whether it is a write or read lock).
644 */
645 inline void unlock() { m_channel_map_lock->unlock(); }
646
647 /**
648 Assert that some thread holds either the read or the write lock.
649 */
650 inline void assert_some_lock() const {
652 }
653
654 /**
655 Assert that some thread holds the write lock.
656 */
657 inline void assert_some_wrlock() const {
659 }
660};
661
662/**
663 The class is a container for all the per-channel filters, both a map of
664 Rpl_filter objects and a list of Rpl_pfs_filter objects.
665 It maintains a filter map which maps a replication filter to a channel
666 name. Which is needed, because replication channels are not created and
667 channel_map is not filled in when these global and per-channel replication
668 filters are evaluated with current code frame.
669 In theory, after instantiating all channels from the repository and throwing
670 all the warnings about the filters configured for non-existent channels, we
671 can forget about its global object rpl_channel_filters and rely only on the
672 global and per channel Rpl_filter objects. But to avoid holding the
673 channel_map.rdlock() when querying P_S.replication_applier_filters table,
674 we keep the rpl_channel_filters. So that we just need to hold the small
675 rpl_channel_filters.rdlock() when querying P_S.replication_applier_filters
676 table. Many operations (RESET REPLICA [FOR CHANNEL], START REPLICA, INIT
677 SLAVE, END SLAVE, CHANGE REPLICATION SOURCE TO, FLUSH RELAY LOGS, START
678 CHANNEL, PURGE CHANNEL, and so on) hold the channel_map.wrlock().
679
680 There is one instance, rpl_channel_filters, created globally for Multisource
681 channel filters. The rpl_channel_filters is created when the server is
682 started, destroyed when the server is stopped.
683*/
685 private:
686 /* Store all replication filters with channel names. */
688 /* Store all Rpl_pfs_filter objects in the channel_to_filter. */
689 std::vector<Rpl_pfs_filter> rpl_pfs_filter_vec;
690 /*
691 This lock was designed to protect the channel_to_filter from reading,
692 adding, or removing its objects from the map. It is used to preventing
693 the following commands to run in parallel:
694 RESET REPLICA ALL [FOR CHANNEL '<channel_name>']
695 CHANGE REPLICATION SOURCE TO ... FOR CHANNEL
696 SELECT FROM performance_schema.replication_applier_filters
697
698 Please acquire a wrlock when modifying the map structure (RESET REPLICA ALL
699 [FOR CHANNEL '<channel_name>'], CHANGE REPLICATION SOURCE TO ... FOR
700 CHANNEL). Please acqurie a rdlock when querying existing filter(s) (SELECT
701 FROM performance_schema.replication_applier_filters).
702
703 Note: To modify the object from the map, please see the protection of
704 m_rpl_filter_lock in Rpl_filter.
705 */
707
708 public:
709 /**
710 Create a new replication filter and add it into a filter map.
711
712 @param channel_name A name of a channel.
713
714 @retval Rpl_filter A pointer to a replication filter, or NULL
715 if we failed to add it into fiter_map.
716 */
717 Rpl_filter *create_filter(const char *channel_name);
718 /**
719 Delete the replication filter from the filter map.
720
721 @param rpl_filter A pointer to point to a replication filter.
722 */
724 /**
725 Discard all replication filters if they are not attached to channels.
726 */
728 /**
729 discard filters on group replication channels.
730 */
732 /**
733 Get a replication filter of a channel.
734
735 @param channel_name A name of a channel.
736
737 @retval Rpl_filter A pointer to a replication filter, or NULL
738 if we failed to add a replication filter
739 into fiter_map when creating it.
740 */
741 Rpl_filter *get_channel_filter(const char *channel_name);
742
743#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
744
745 /**
746 This member function is called every time a filter is created or deleted,
747 or its filter rules are changed. Once that happens the PFS view is
748 recreated.
749 */
750 void reset_pfs_view();
751
752 /**
753 Used only by replication performance schema indices to get the replication
754 filter at the position 'pos' from the rpl_pfs_filter_vec vector.
755
756 @param pos the index in the rpl_pfs_filter_vec vector.
757
758 @retval Rpl_filter A pointer to a Rpl_pfs_filter, or NULL if it
759 arrived the end of the rpl_pfs_filter_vec.
760 */
762 /**
763 Used only by replication performance schema indices to get the count
764 of replication filters from the rpl_pfs_filter_vec vector.
765
766 @retval the count of the replication filters.
767 */
768 uint get_filter_count();
769#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
770
771 /**
772 Traverse the filter map, build do_table and ignore_table
773 rules to hashes for every filter.
774
775 @retval
776 0 OK
777 @retval
778 -1 Error
779 */
781
782 /* Constructor for this class.*/
787#endif
788 );
789 }
790
791 /* Destructor for this class. */
793
794 /**
795 Traverse the filter map and free all filters. Delete all objects
796 in the rpl_pfs_filter_vec vector and then clear the vector.
797 */
798 void clean_up() {
799 /* Traverse the filter map and free all filters */
800 for (filter_map::iterator it = channel_to_filter.begin();
801 it != channel_to_filter.end(); it++) {
802 if (it->second != nullptr) {
803 delete it->second;
804 it->second = nullptr;
805 }
806 }
807
808 rpl_pfs_filter_vec.clear();
809 }
810
811 /**
812 Acquire the write lock.
813 */
815
816 /**
817 Acquire the read lock.
818 */
820
821 /**
822 Release the lock (whether it is a write or read lock).
823 */
825};
826
827/* Global object for multisourced slave. */
829
830/* Global object for storing per-channel replication filters */
832
833static bool inline is_slave_configured() {
834 /* Server was started with server_id == 0
835 OR
836 failure to load applier metadata repositories
837 */
838 return (channel_map.get_default_channel_mi() != nullptr);
839}
840
841#endif /*RPL_MSR_H*/
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:325
int trywrlock()
Return 0 if the write lock is held, otherwise an error will be returned.
Definition: rpl_gtid.h:538
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:486
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:495
int tryrdlock()
Return 0 if the read lock is held, otherwise an error will be returned.
Definition: rpl_gtid.h:557
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_gtid.h:572
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:506
void assert_some_wrlock() const
Assert that some thread holds the write lock.
Definition: rpl_gtid.h:576
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:542
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:231
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:200
Multisource_info()
Definition: rpl_msr.h:340
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:462
mi_map::iterator end(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Definition: rpl_msr.h:555
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_msr.h:650
static const char * group_replication_channel_names[]
Definition: rpl_msr.h:315
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:632
static const char * default_channel
Default_channel for this instance, currently is predefined and cannot be modified.
Definition: rpl_msr.h:313
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:640
Master_info * get_default_channel_mi()
Return the master_info object corresponding to the default channel.
Definition: rpl_msr.h:394
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:218
uint get_max_channels()
Get max channels allowed for this map.
Definition: rpl_msr.h:495
void init_rpl_pfs_mi()
Definition: rpl_msr.h:581
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:183
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:117
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:188
~Multisource_info()
Definition: rpl_msr.h:364
auto all_channels_view()
Definition: rpl_msr.h:567
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:619
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:193
void assert_some_wrlock() const
Assert that some thread holds the write lock.
Definition: rpl_msr.h:657
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:41
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_msr.h:645
mi_map::iterator begin(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Forward iterators to initiate traversing of a map.
Definition: rpl_msr.h:543
auto all_channels_view() const
Definition: rpl_msr.h:572
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:86
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:501
const char * get_default_channel()
Get the default channel for this multisourced_slave;.
Definition: rpl_msr.h:419
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:627
Master_info * rpl_pfs_mi[MAX_CHANNELS]
Definition: rpl_msr.h:328
replication_channel_map rep_channel_map
Definition: rpl_msr.h:304
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:531
mi_map empty_mi_map
Definition: rpl_msr.h:336
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:429
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:684
Checkable_rwlock * m_channel_to_filter_lock
Definition: rpl_msr.h:706
uint get_filter_count()
Used only by replication performance schema indices to get the count of replication filters from the ...
Definition: rpl_msr.cc:388
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:378
Rpl_filter * get_channel_filter(const char *channel_name)
Get a replication filter of a channel.
Definition: rpl_msr.cc:340
std::vector< Rpl_pfs_filter > rpl_pfs_filter_vec
Definition: rpl_msr.h:689
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:363
void clean_up()
Traverse the filter map and free all filters.
Definition: rpl_msr.h:798
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_msr.h:824
void delete_filter(Rpl_filter *rpl_filter)
Delete the replication filter from the filter map.
Definition: rpl_msr.cc:270
void discard_group_replication_filters()
discard filters on group replication channels.
Definition: rpl_msr.cc:291
void discard_all_unattached_filters()
Discard all replication filters if they are not attached to channels.
Definition: rpl_msr.cc:309
Rpl_channel_filters()
Definition: rpl_msr.h:783
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:397
filter_map channel_to_filter
Definition: rpl_msr.h:687
Rpl_filter * create_filter(const char *channel_name)
Create a new replication filter and add it into a filter map.
Definition: rpl_msr.cc:241
~Rpl_channel_filters()
Definition: rpl_msr.h:792
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:814
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:819
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:57
bool is_error() const
Definition: rpl_reporting.h:144
static Source_IO_monitor * get_instance()
Fetch Source_IO_monitor class instance.
Definition: rpl_io_monitor.cc:1092
#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:13884
PSI_rwlock_key key_rwlock_channel_map_lock
Definition: mysqld.cc:13880
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
Definition: gcs_xcom_synode.h:64
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
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:833
std::map< std::string, Rpl_filter * > filter_map
Definition: rpl_msr.h:58
Multisource_info channel_map
Definition: rpl_msr.cc:418
std::map< int, mi_map > replication_channel_map
Definition: rpl_msr.h:56
Rpl_channel_filters rpl_channel_filters
Definition: rpl_msr.cc:420
Definition: task.h:427