MySQL 9.2.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 configured asynchronous replication channels,
457 ignoring the Group Replication channels.
458
459 @return The number of channels.
460 */
464 size_t count = 0;
465
466 replication_channel_map::iterator map_it =
468
469 for (mi_map::iterator it = map_it->second.begin();
470 it != map_it->second.end(); it++) {
471 Master_info *mi = it->second;
473 count++;
474 }
475 }
476
477 return count;
478 }
479
480 /**
481 Get the number of running channels which have asynchronous replication
482 failover feature, i.e. CHANGE REPLICATION SOURCE TO option
483 SOURCE_CONNECTION_AUTO_FAILOVER, enabled.
484
485 @return The number of channels.
486 */
490 size_t count = 0;
491
492 replication_channel_map::iterator map_it =
494
495 for (mi_map::iterator it = map_it->second.begin();
496 it != map_it->second.end(); it++) {
497 Master_info *mi = it->second;
501 if (mi->slave_running || mi->is_error()) {
502 count++;
503 }
505 }
506 }
507
508#ifndef NDEBUG
509 if (Source_IO_monitor::get_instance()->is_monitoring_process_running()) {
510 assert(count > 0);
511 }
512#endif
513
514 return count;
515 }
516
517 /**
518 Get max channels allowed for this map.
519 */
520 inline uint get_max_channels() { return MAX_CHANNELS; }
521
522 /**
523 Returns true if the current number of channels in this slave
524 is less than the MAX_CHANNLES
525 */
529 DBUG_EXECUTE_IF("max_replication_channels_exceeded", is_valid = false;);
530 return (is_valid);
531 }
532
533 /// @brief Checks if a channel is the group replication applier channel
534 /// @param[in] channel Name of the channel to check
535 /// @returns true if it is the gr applier channel
536 static bool is_group_replication_applier_channel_name(const char *channel);
537
538 /// @brief Checks if a channel is the group replication recovery channel
539 /// @param[in] channel Name of the channel to check
540 /// @returns true if it is the gr recovery channel
542
543 /**
544 Returns if a channel name is one of the reserved group replication names
545
546 @param channel the channel name to test
547
548 @retval true the name is a reserved name
549 @retval false non reserved name
550 */
551 static bool is_group_replication_channel_name(const char *channel);
552
553 /// @brief Check if the channel has an hostname or is a GR channel
554 /// @return true if the channel is configured or is a gr channel,
555 /// false otherwise
556 static bool is_channel_configured(const Master_info *mi) {
557 return mi && (mi->host[0] ||
559 }
560
561 /**
562 Forward iterators to initiate traversing of a map.
563
564 @todo: Not to expose iterators. But instead to return
565 only Master_infos or create generators when
566 c++11 is introduced.
567 */
568 mi_map::iterator begin(
570 replication_channel_map::iterator map_it;
571 map_it = rep_channel_map.find(channel_type);
572
573 if (map_it != rep_channel_map.end()) {
574 return map_it->second.begin();
575 }
576
577 return end(channel_type);
578 }
579
580 mi_map::iterator end(
582 replication_channel_map::iterator map_it;
583 map_it = rep_channel_map.find(channel_type);
584
585 if (map_it != rep_channel_map.end()) {
586 return map_it->second.end();
587 }
588
589 return empty_mi_map.end();
590 }
591
595 }
596
597 auto all_channels_view() const {
600 }
601
602 private:
603#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
604
605 /* Initialize the rpl_pfs_mi array to NULLs */
606 inline void init_rpl_pfs_mi() {
607 for (uint i = 0; i < MAX_CHANNELS; i++) rpl_pfs_mi[i] = nullptr;
608 }
609
610 /**
611 Add a master info pointer to the rpl_pfs_mi array at the first
612 NULL;
613
614 @param[in] mi master info object to be added.
615
616 @return false if success.Else true.
617 */
619
620 /**
621 Get the index of the master info corresponding to channel name
622 from the rpl_pfs_mi array.
623 @param[in] channel_name Channel name to get the index from
624
625 @return index of mi for the channel_name. Else -1;
626 */
627 int get_index_from_rpl_pfs_mi(const char *channel_name);
628
629 public:
630 /**
631 Used only by replication performance schema indices to get the master_info
632 at the position 'pos' from the rpl_pfs_mi array.
633
634 @param[in] pos the index in the rpl_pfs_mi array
635
636 @retval pointer to the master info object at pos 'pos';
637 */
638 Master_info *get_mi_at_pos(uint pos);
639#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
640
641 /**
642 Acquire the read lock.
643 */
644 inline void rdlock() { m_channel_map_lock->rdlock(); }
645
646 /**
647 Try to acquire a read lock, return 0 if the read lock is held,
648 otherwise an error will be returned.
649
650 @return 0 in case of success, or 1 otherwise.
651 */
652 inline int tryrdlock() { return m_channel_map_lock->tryrdlock(); }
653
654 /**
655 Acquire the write lock.
656 */
657 inline void wrlock() { m_channel_map_lock->wrlock(); }
658
659 /**
660 Try to acquire a write lock, return 0 if the write lock is held,
661 otherwise an error will be returned.
662
663 @return 0 in case of success, or 1 otherwise.
664 */
665 inline int trywrlock() { return m_channel_map_lock->trywrlock(); }
666
667 /**
668 Release the lock (whether it is a write or read lock).
669 */
670 inline void unlock() { m_channel_map_lock->unlock(); }
671
672 /**
673 Assert that some thread holds either the read or the write lock.
674 */
675 inline void assert_some_lock() const {
677 }
678
679 /**
680 Assert that some thread holds the write lock.
681 */
682 inline void assert_some_wrlock() const {
684 }
685};
686
687/**
688 The class is a container for all the per-channel filters, both a map of
689 Rpl_filter objects and a list of Rpl_pfs_filter objects.
690 It maintains a filter map which maps a replication filter to a channel
691 name. Which is needed, because replication channels are not created and
692 channel_map is not filled in when these global and per-channel replication
693 filters are evaluated with current code frame.
694 In theory, after instantiating all channels from the repository and throwing
695 all the warnings about the filters configured for non-existent channels, we
696 can forget about its global object rpl_channel_filters and rely only on the
697 global and per channel Rpl_filter objects. But to avoid holding the
698 channel_map.rdlock() when querying P_S.replication_applier_filters table,
699 we keep the rpl_channel_filters. So that we just need to hold the small
700 rpl_channel_filters.rdlock() when querying P_S.replication_applier_filters
701 table. Many operations (RESET REPLICA [FOR CHANNEL], START REPLICA, INIT
702 SLAVE, END SLAVE, CHANGE REPLICATION SOURCE TO, FLUSH RELAY LOGS, START
703 CHANNEL, PURGE CHANNEL, and so on) hold the channel_map.wrlock().
704
705 There is one instance, rpl_channel_filters, created globally for Multisource
706 channel filters. The rpl_channel_filters is created when the server is
707 started, destroyed when the server is stopped.
708*/
710 private:
711 /* Store all replication filters with channel names. */
713 /* Store all Rpl_pfs_filter objects in the channel_to_filter. */
714 std::vector<Rpl_pfs_filter> rpl_pfs_filter_vec;
715 /*
716 This lock was designed to protect the channel_to_filter from reading,
717 adding, or removing its objects from the map. It is used to preventing
718 the following commands to run in parallel:
719 RESET REPLICA ALL [FOR CHANNEL '<channel_name>']
720 CHANGE REPLICATION SOURCE TO ... FOR CHANNEL
721 SELECT FROM performance_schema.replication_applier_filters
722
723 Please acquire a wrlock when modifying the map structure (RESET REPLICA ALL
724 [FOR CHANNEL '<channel_name>'], CHANGE REPLICATION SOURCE TO ... FOR
725 CHANNEL). Please acqurie a rdlock when querying existing filter(s) (SELECT
726 FROM performance_schema.replication_applier_filters).
727
728 Note: To modify the object from the map, please see the protection of
729 m_rpl_filter_lock in Rpl_filter.
730 */
732
733 public:
734 /**
735 Create a new replication filter and add it into a filter map.
736
737 @param channel_name A name of a channel.
738
739 @retval Rpl_filter A pointer to a replication filter, or NULL
740 if we failed to add it into fiter_map.
741 */
742 Rpl_filter *create_filter(const char *channel_name);
743 /**
744 Delete the replication filter from the filter map.
745
746 @param rpl_filter A pointer to point to a replication filter.
747 */
749 /**
750 Discard all replication filters if they are not attached to channels.
751 */
753 /**
754 discard filters on group replication channels.
755 */
757 /**
758 Get a replication filter of a channel.
759
760 @param channel_name A name of a channel.
761
762 @retval Rpl_filter A pointer to a replication filter, or NULL
763 if we failed to add a replication filter
764 into fiter_map when creating it.
765 */
766 Rpl_filter *get_channel_filter(const char *channel_name);
767
768#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
769
770 /**
771 This member function is called every time a filter is created or deleted,
772 or its filter rules are changed. Once that happens the PFS view is
773 recreated.
774 */
775 void reset_pfs_view();
776
777 /**
778 Used only by replication performance schema indices to get the replication
779 filter at the position 'pos' from the rpl_pfs_filter_vec vector.
780
781 @param pos the index in the rpl_pfs_filter_vec vector.
782
783 @retval Rpl_filter A pointer to a Rpl_pfs_filter, or NULL if it
784 arrived the end of the rpl_pfs_filter_vec.
785 */
787 /**
788 Used only by replication performance schema indices to get the count
789 of replication filters from the rpl_pfs_filter_vec vector.
790
791 @retval the count of the replication filters.
792 */
793 uint get_filter_count();
794#endif /*WITH_PERFSCHEMA_STORAGE_ENGINE */
795
796 /**
797 Traverse the filter map, build do_table and ignore_table
798 rules to hashes for every filter.
799
800 @retval
801 0 OK
802 @retval
803 -1 Error
804 */
806
807 /* Constructor for this class.*/
812#endif
813 );
814 }
815
816 /* Destructor for this class. */
818
819 /**
820 Traverse the filter map and free all filters. Delete all objects
821 in the rpl_pfs_filter_vec vector and then clear the vector.
822 */
823 void clean_up() {
824 /* Traverse the filter map and free all filters */
825 for (filter_map::iterator it = channel_to_filter.begin();
826 it != channel_to_filter.end(); it++) {
827 if (it->second != nullptr) {
828 delete it->second;
829 it->second = nullptr;
830 }
831 }
832
833 rpl_pfs_filter_vec.clear();
834 }
835
836 /**
837 Acquire the write lock.
838 */
840
841 /**
842 Acquire the read lock.
843 */
845
846 /**
847 Release the lock (whether it is a write or read lock).
848 */
850};
851
852/* Global object for multisourced slave. */
854
855/* Global object for storing per-channel replication filters */
857
858static bool inline is_slave_configured() {
859 /* Server was started with server_id == 0
860 OR
861 failure to load applier metadata repositories
862 */
863 return (channel_map.get_default_channel_mi() != nullptr);
864}
865
866#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:487
mi_map::iterator end(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Definition: rpl_msr.h:580
void assert_some_lock() const
Assert that some thread holds either the read or the write lock.
Definition: rpl_msr.h:675
static const char * group_replication_channel_names[]
Definition: rpl_msr.h:315
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:657
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:461
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:665
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:520
void init_rpl_pfs_mi()
Definition: rpl_msr.h:606
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:592
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:644
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:682
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:670
mi_map::iterator begin(enum_channel_type channel_type=SLAVE_REPLICATION_CHANNEL)
Forward iterators to initiate traversing of a map.
Definition: rpl_msr.h:568
auto all_channels_view() const
Definition: rpl_msr.h:597
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:526
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:652
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:556
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:709
Checkable_rwlock * m_channel_to_filter_lock
Definition: rpl_msr.h:731
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:714
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:823
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_msr.h:849
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:808
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:712
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:817
void wrlock()
Acquire the write lock.
Definition: rpl_msr.h:839
void rdlock()
Acquire the read lock.
Definition: rpl_msr.h:844
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:14063
PSI_rwlock_key key_rwlock_channel_map_lock
Definition: mysqld.cc:14059
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:858
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