MySQL 9.1.0
Source Code Documentation
gtid_generator_for_sidno.h
Go to the documentation of this file.
1// Copyright (c) 2023, 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 GR_CERTIFICATION_gtid_generator_for_sidno_INCLUDED
25#define GR_CERTIFICATION_gtid_generator_for_sidno_INCLUDED
26
27#include <unordered_map>
28
30#include "sql/rpl_gtid.h"
31
32namespace gr {
33
34/// @brief Class that is responsible for holding available GTIDs and assigning
35/// GTID blocks to specific group members
37 public:
38 /// @brief Constructs Gtid_generator_for_sidno for a given sidno and
39 /// block_size
40 /// @param sidno Sidno assigned to this object
41 /// @param block_size Object will reserve blocks of this size
42 Gtid_generator_for_sidno(rpl_sidno sidno, std::size_t block_size);
43
44 /// @brief Generates gno for transaction originating from server
45 /// identified with the 'member_uuid'
46 /// When needed, function will consult gtid_set for the list of available
47 /// GTIDs
48 /// @param member_uuid UUID of a group member from which trx originates
49 /// @param gtid_set Currently used GTID set
50 /// @returns A pair of:
51 /// - Generated gno and OK in case gno generation was possible
52 /// - invalid gno and a corresponding error code:
53 /// (-1) when there are no available gnos for this SIDNO
54 /// (-2) when assigned GTIDs block is exhausted
55 std::pair<rpl_gno, mysql::utils::Return_status> get_next_available_gtid(
56 const char *member_uuid, const Gtid_set &gtid_set);
57
58 /// @brief For a given sidno, clear the assigned blocks for all members,
59 /// and compute the available GTID intervals for the sidno.
60 /// @details Clearing the assigned blocks implies that subsequent
61 /// GTID assignments will assign new blocks for any member that commits
62 /// a transaction, picking them from the available intervals for the sidno.
63 /// The available intervals for the sidno, which this function also
64 /// recomputes, consists of the list of intervals that are *not* in the
65 /// given gtid_set, i.e., the complement of the set for that sidno.
66 /// For example, if gtid_set is equal to UUID1:11-47,UUID2:1-100, and sidno
67 /// corresponds to UUID1, then this will compute the set consisting of the
68 /// two intervals [1,10] and [48,MAX_GNO].
69 /// @param gtid_set Gtid set under consideration
71
72 private:
73 /// @brief Represents result of GNO generation function
75 ok, ///< successfully generated
76 gno_exhausted, ///< gno exausted for the given sidno/uuid (error)
77 gtid_block_overflow, ///< generated GNO > GNO_MAX defined for the current
78 ///< interval
79 error ///< Other error, such as OOM
80 };
81
82 /// @brief This function reserves a block of GTIDs from the list of
83 /// available GTIDs
84 /// @param block_size Size of the reserved block
85 /// @param gtid_set Gtid set under consideration
86 /// @return Assigned interval
88 const Gtid_set &gtid_set);
89
90 /// @brief Generate the candidate GNO for the current transaction.
91 /// The candidate will be on the interval [start, end] or a error
92 /// be returned.
93 /// This method will consult group_gtid_executed (or group_gtid_extracted)
94 /// to avoid generate the same value twice.
95
96 /// @param start The first possible value for the GNO
97 /// @param end The last possible value for the GNO
98 /// @param gtid_set Gtid set under consideration
99
100 /// @details This method walks through available intervals for the given sidno
101 /// until it finds the correct one. Returns a free GTID or one of the error
102 /// codes.
103 /// @return generated gno, gno_generation_result (possible error states or ok
104 /// code)
105 /// @see Gno_generation_result for possible error states
106 std::pair<rpl_gno, Gno_generation_result> get_next_available_gtid_candidate(
107 rpl_gno start, rpl_gno end, const Gtid_set &gtid_set) const;
108
109 /// Interval container type, list of intervals
110 using Interval_container_type = std::list<Gtid_set::Interval>;
111
112 /// Container type hold currently assigned intervals (value)
113 /// for the given member (key)
115 std::unordered_map<std::string, Gtid_set::Interval>;
116
117 /// Type of iterator of assigned_gtids
118 using Assigned_intervals_it = Assigned_intervals_container_type::iterator;
119
120 /// @brief gets Interval assigned to the given member
121 /// @param member_uuid UUID of a group member
122 /// @param gtid_set Gtid set under consideration
123 /// @returns Block assigned iterator, which may be invalid in case GNO
124 /// intervals exhausted for this map
125 Assigned_intervals_it get_assigned_interval(const std::string &member_uuid,
126 const Gtid_set &gtid_set);
127
128 /// @brief Allocates GTID block for the given member
129 /// @param member_uuid UUID of a group member
130 /// @param gtid_set Gtid set under consideration
131 /// @returns Block assigned iterator, which may be invalid in case GNO
132 /// intervals exhausted for this map
133 Assigned_intervals_it reserve_gtid_block(const std::string &member_uuid,
134 const Gtid_set &gtid_set);
135
136 rpl_sidno m_sidno; ///< Sidno for which this map has been created
137 long m_block_size; ///< Block size used to assign GTIDs
138 std::size_t m_counter; ///< The number of assigned GTIDs
141 m_assigned_intervals; ///< Holds currently assigned intervals for the
142 ///< given member
143};
144
145} // namespace gr
146
147#endif // GR_CERTIFICATION_gtid_generator_for_sidno_INCLUDED
Represents a set of GTIDs.
Definition: rpl_gtid.h:1557
Class that is responsible for holding available GTIDs and assigning GTID blocks to specific group mem...
Definition: gtid_generator_for_sidno.h:36
rpl_sidno m_sidno
Sidno for which this map has been created.
Definition: gtid_generator_for_sidno.h:136
std::list< Gtid_set::Interval > Interval_container_type
Interval container type, list of intervals.
Definition: gtid_generator_for_sidno.h:110
Gno_generation_result
Represents result of GNO generation function.
Definition: gtid_generator_for_sidno.h:74
@ gno_exhausted
gno exausted for the given sidno/uuid (error)
@ gtid_block_overflow
generated GNO > GNO_MAX defined for the current interval
std::pair< rpl_gno, Gno_generation_result > get_next_available_gtid_candidate(rpl_gno start, rpl_gno end, const Gtid_set &gtid_set) const
Generate the candidate GNO for the current transaction.
Definition: gtid_generator_for_sidno.cc:109
Assigned_intervals_container_type::iterator Assigned_intervals_it
Type of iterator of assigned_gtids.
Definition: gtid_generator_for_sidno.h:118
Assigned_intervals_container_type m_assigned_intervals
Holds currently assigned intervals for the given member.
Definition: gtid_generator_for_sidno.h:141
Interval_container_type m_available_intervals
Free intervals.
Definition: gtid_generator_for_sidno.h:139
Assigned_intervals_it get_assigned_interval(const std::string &member_uuid, const Gtid_set &gtid_set)
gets Interval assigned to the given member
Definition: gtid_generator_for_sidno.cc:187
long m_block_size
Block size used to assign GTIDs.
Definition: gtid_generator_for_sidno.h:137
std::pair< rpl_gno, mysql::utils::Return_status > get_next_available_gtid(const char *member_uuid, const Gtid_set &gtid_set)
Generates gno for transaction originating from server identified with the 'member_uuid' When needed,...
Definition: gtid_generator_for_sidno.cc:56
void compute_group_available_gtid_intervals(const Gtid_set &gtid_set)
For a given sidno, clear the assigned blocks for all members, and compute the available GTID interval...
Definition: gtid_generator_for_sidno.cc:142
Gtid_generator_for_sidno(rpl_sidno sidno, std::size_t block_size)
Constructs Gtid_generator_for_sidno for a given sidno and block_size.
Definition: gtid_generator_for_sidno.cc:104
std::size_t m_counter
The number of assigned GTIDs.
Definition: gtid_generator_for_sidno.h:138
Gtid_set::Interval reserve_gtid_block(longlong block_size, const Gtid_set &gtid_set)
This function reserves a block of GTIDs from the list of available GTIDs.
std::unordered_map< std::string, Gtid_set::Interval > Assigned_intervals_container_type
Container type hold currently assigned intervals (value) for the given member (key)
Definition: gtid_generator_for_sidno.h:115
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
long long int longlong
Definition: my_inttypes.h:55
Definition: group_replication_priv.h:44
mysql::gtid::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
Definition: rpl_gtid.h:113
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:109
Represents one element in the linked list of intervals associated with a SIDNO.
Definition: rpl_gtid.h:2041