MySQL 9.6.0
Source Code Documentation
gtid_set.h
Go to the documentation of this file.
1// Copyright (c) 2025, 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 MYSQL_GTIDS_GTID_SET_H
25#define MYSQL_GTIDS_GTID_SET_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // same_as
31#include "mysql/gtids/gtid.h" // Gtid
32#include "mysql/gtids/sequence_number.h" // Sequence_number
33#include "mysql/gtids/tsid.h" // Tsid
34#include "mysql/meta/not_decayed.h" // Not_decayed
35#include "mysql/sets/aliases.h" // Map_interval_container
36#include "mysql/sets/int_set_traits.h" // Int_set_traits
37#include "mysql/sets/nested_set_predicates.h" // contains_element
38#include "mysql/sets/ordered_set_traits_interface.h" // Ordered_set_traits_interface
39
40/// @addtogroup GroupLibsMysqlGtids
41/// @{
42
43namespace mysql::gtids {
44
45/// Set_traits used when TSIDs are stored in sets.
47 : public mysql::sets::Ordered_set_traits_interface<Tsid_traits, Tsid> {
48 [[nodiscard]] static bool lt(const Tsid &left, const Tsid &right) {
49 return left < right;
50 }
51};
52
53namespace detail {
54/// Type alias that defines Set_traits for gtids::Sequence_number.
55///
56/// Use Sequence_number_traits instead: that is less verbose when it appears
57/// in error messages or stack traces.
61} // namespace detail
62
63/// Class that defines Set_traits for gtids::Sequence_number.
65
66namespace detail {
67/// Type alias that defines the Interval type used for Gtid intervals.
68///
69/// Use Gtid_interval instead: that is less verbose when it appears in error
70/// messages or stack traces.
72} // namespace detail
73
74/// Class that defines the Interval type used for Gtid intervals.
77
78 /// Construct an interval with the given values for start and exclusive end.
79 ///
80 /// @throw std::domain_error if the values are out of range or out of order.
81 explicit Gtid_interval(const Element_t &start_arg,
82 const Element_t &exclusive_end_arg)
83 : Base_t(start_arg, exclusive_end_arg) {}
84
85 /// Construct a singleton interval.
86 ///
87 /// @throw std::domain_error if the value is out of range.
88 explicit Gtid_interval(const Element_t &singleton) : Base_t(singleton) {}
89
90 public:
91 // Default-construct an interval. The resulting interval has a single element,
92 // the smallest value in the Set traits.
94
95 // default rule-of-5
96
97 /// Construct an interval with the given values for start and exclusive end.
98 ///
99 /// @throw std::domain_error if the values are out of range or out of order.
100 static Gtid_interval throwing_make(const Element_t &start_arg,
101 const Element_t &exclusive_end_arg) {
102 return Gtid_interval(start_arg, exclusive_end_arg);
103 }
104
105 /// Construct a singleton interval.
106 ///
107 /// @throw std::domain_error if the value is out of range.
108 static Gtid_interval throwing_make(const Element_t &singleton) {
109 return Gtid_interval(singleton);
110 }
111};
112
113namespace detail {
114/// Type alias that defines the Interval set type used for Gtid intervals.
115///
116/// Use Gtid_interval_set instead: that is less verbose when it appears in error
117/// messages or stack traces.
120} // namespace detail
121
122/// Class that defines the Interval set type used for Gtid intervals.
125
126 public:
129
130 /// Enable all constructors from Map_interval_container.
131 template <class... Args_t>
133 explicit Gtid_interval_set(Args_t &&...args) noexcept
134 : detail::Gtid_interval_set_alias(std::forward<Args_t>(args)...) {}
135};
136
137namespace detail {
138/// Type alias that defines the Set type used for Gtid sets.
139///
140/// Use Gtid_set instead: that is less verbose when it appears in error messages
141/// or stack traces.
144} // namespace detail
145
146/// Class that defines the Set type used for Gtid sets.
149
150 public:
151 /// Enable all constructors from Map_nested_container.
152 template <class... Args_t>
153 requires mysql::meta::Not_decayed<Gtid_set, Args_t...>
154 explicit Gtid_set(Args_t &&...args) noexcept
155 : Base_t(std::forward<Args_t>(args)...) {}
156
157 /// Enable all `insert` overloads from the base class, as well as the one
158 /// defined below.
159 using Base_t::insert;
160
161 /// `insert` taking a Gtid argument.
162 [[nodiscard]] auto insert(const Is_gtid auto &gtid) {
163 return Base_t::insert(gtid.tsid(), gtid.get_sequence_number());
164 }
165
166 /// Enable all `remove` overloads from the base class, as well as the one
167 /// defined below.
168 using Base_t::remove;
169
170 /// `remove` taking a Gtid argument.
171 [[nodiscard]] auto remove(const Is_gtid auto &gtid) noexcept {
172 return Base_t::remove(gtid.tsid(), gtid.get_sequence_number());
173 }
174};
175
176/// True for all Gtid set types.
177template <class Test>
178concept Is_gtid_set =
180
181} // namespace mysql::gtids
182
183namespace mysql::sets {
184
185/// `contains_element` for Gtid_sets, accepting a Gtid for the element.
186[[nodiscard]] bool contains_element(
187 const mysql::gtids::Is_gtid_set auto &gtid_set,
188 const mysql::gtids::Is_gtid auto &gtid) noexcept {
189 return contains_element(gtid_set, gtid.tsid(), gtid.get_sequence_number());
190}
191
192} // namespace mysql::sets
193
194// addtogroup GroupLibsMysqlGtids
195/// @}
196
197#endif // ifndef MYSQL_GTIDS_GTID_SET_H
Experimental API header.
Class that defines the Interval set type used for Gtid intervals.
Definition: gtid_set.h:123
Gtid_interval_set(Args_t &&...args) noexcept
Enable all constructors from Map_interval_container.
Definition: gtid_set.h:133
Class that defines the Interval type used for Gtid intervals.
Definition: gtid_set.h:75
Gtid_interval(const Element_t &start_arg, const Element_t &exclusive_end_arg)
Construct an interval with the given values for start and exclusive end.
Definition: gtid_set.h:81
static Gtid_interval throwing_make(const Element_t &start_arg, const Element_t &exclusive_end_arg)
Construct an interval with the given values for start and exclusive end.
Definition: gtid_set.h:100
static Gtid_interval throwing_make(const Element_t &singleton)
Construct a singleton interval.
Definition: gtid_set.h:108
Gtid_interval()
Definition: gtid_set.h:93
Gtid_interval(const Element_t &singleton)
Construct a singleton interval.
Definition: gtid_set.h:88
Class that defines the Set type used for Gtid sets.
Definition: gtid_set.h:147
auto insert(const Is_gtid auto &gtid)
insert taking a Gtid argument.
Definition: gtid_set.h:162
Gtid_set(Args_t &&...args) noexcept
Enable all constructors from Map_nested_container.
Definition: gtid_set.h:154
auto remove(const Is_gtid auto &gtid) noexcept
remove taking a Gtid argument.
Definition: gtid_set.h:171
detail::Gtid_set_alias Base_t
Definition: gtid_set.h:148
Definition: tsid.h:90
Boundary_set_t::Set_traits_t Set_traits_t
Definition: interval_set_interface.h:95
Holds the start boundary and endpoint boundary of an interval.
Definition: interval.h:178
Interval container using std::map as backing storage.
Definition: aliases.h:263
Nested set container using std::map as backing storage.
Definition: aliases.h:291
Return_status_t remove(const Key_t &key, const auto &...value) noexcept
Remove the given element from the set, if it is there.
Definition: nested_container.h:181
Return_status_t insert(const Key_t &key, Mapped_args_t &&...mapped_args) noexcept
Insert the given element (inplace union).
Definition: nested_container.h:155
Set_traits_t::Element_t Element_t
Definition: interval.h:56
True for all Gtid set types.
Definition: gtid_set.h:178
Definition: gtid.h:53
false if Args is exactly one type, say A, and std::decay_t<A> equals Type.
Definition: not_decayed.h:84
True if Test satisfies Is_nested_set and its traits is Set_traits_t.
Definition: nested_set_meta.h:128
Experimental API header.
Experimental API header.
Experimental API header.
Definition: fts0fts.cc:236
void right(std::string *to_trim)
Definition: trim.h:41
void left(std::string *to_trim)
Definition: trim.h:35
mysql::sets::Map_interval_container< Sequence_number_traits > Gtid_interval_set_alias
Type alias that defines the Interval set type used for Gtid intervals.
Definition: gtid_set.h:119
mysql::sets::Interval< Sequence_number_traits > Gtid_interval_alias
Type alias that defines the Interval type used for Gtid intervals.
Definition: gtid_set.h:71
mysql::sets::Map_nested_container< Tsid_traits, Gtid_interval_set > Gtid_set_alias
Type alias that defines the Set type used for Gtid sets.
Definition: gtid_set.h:143
Definition: gtid.h:45
uint64_t Sequence_number
The type of the sequence number component of a GTID.
Definition: sequence_number.h:39
constexpr Sequence_number sequence_number_max_exclusive
One plus the largest allowed value for a GTID sequence number.
Definition: sequence_number.h:42
constexpr Sequence_number sequence_number_min
The smallest allowed value for a GTID sequence number.
Definition: sequence_number.h:50
Definition: gtid_set.h:183
bool contains_element(const mysql::gtids::Is_gtid_set auto &gtid_set, const mysql::gtids::Is_gtid auto &gtid) noexcept
contains_element for Gtid_sets, accepting a Gtid for the element.
Definition: gtid_set.h:186
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Class that defines Set_traits for gtids::Sequence_number.
Definition: gtid_set.h:64
Set_traits used when TSIDs are stored in sets.
Definition: gtid_set.h:47
static bool lt(const Tsid &left, const Tsid &right)
Definition: gtid_set.h:48
Set traits for integral types.
Definition: int_set_traits.h:58
Helper CRTP base class to define Ordered Set traits classes, which are optionally Bounded and/or Metr...
Definition: ordered_set_traits_interface.h:90