MySQL 9.1.0
Source Code Documentation
gtid_generator.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_INCLUDED
25#define GR_CERTIFICATION_GTID_GENERATOR_INCLUDED
26
27#include <unordered_map>
28
31#include "sql/rpl_gtid.h"
32
33namespace gr {
34
35/// @brief This class is responsible for generating GTIDs in the Certifier
36/// @details Gtid certifier uses one instance of this class for generation of
37/// GTIDs.
38/// Gtid generator keeps track of free GTIDs for specific sidnos for each
39/// GR member. To achieve that, it consults gtid_set provided.
40/// When gtid generation is requested, GTID generator
41/// will reserve for each member a block
42/// of free GTIDS of size provided during the initialization
43/// (gtid_assignment_block_size). Recalculation of GTID blocks may be requested
44/// by the call to the "reset" function. New GTID may be generated by the call
45/// to the "get_next_available_gtid" function.
46/// Access to Gtid_generator must be synchronized by the user.
48 public:
49 /// @brief This method is used to get the next valid GNO for the given sidno,
50 /// for the transaction originating from the group member identified by
51 /// the 'member_uuid'.
52 /// This method may consult gtid_set for the list of available GTIDs
53 /// @param member_uuid The UUID of the member from which this
54 /// transaction originates. It will be NULL
55 /// on View_change_log_event.
56 /// @param sidno The sidno that will be used on GTID
57 /// @param gtid_set Gtid set under consideration
58 /// @returns A pair of:
59 /// - Generated gno and OK in case gno generation was possible
60 /// - invalid gno and ERROR:
61 /// (-1) when there are no available gnos for this SIDNO
62 /// (-2) when assigned GTIDs block is exhausted
63 std::pair<rpl_gno, mysql::utils::Return_status> get_next_available_gtid(
64 const char *member_uuid, rpl_sidno sidno, const Gtid_set &gtid_set);
65
66 /// @brief This function recomputes generator state
67 /// @param gtid_set Gtid set under consideration
68 void recompute(const Gtid_set &gtid_set);
69
70 /// @brief This is initialization function that will be called in the
71 /// certifier
72 /// @param gtid_assignment_block_size This is the size of gtid assignment
73 /// block
74 void initialize(uint64 gtid_assignment_block_size);
75
76 /// @brief Accesses gtid assignment block size the Gtid_generator was
77 /// initialized with
78 /// @return Gtid assignment block size
81 }
82
83 private:
84 /// GTID bookkeeping for each sidno
85 std::unordered_map<rpl_sidno, Gtid_generator_for_sidno>
87
88 /// The group GTID assignment block size.
90};
91
92} // namespace gr
93
94#endif // GR_CERTIFICATION_GTID_GENERATOR_INCLUDED
Represents a set of GTIDs.
Definition: rpl_gtid.h:1557
This class is responsible for generating GTIDs in the Certifier.
Definition: gtid_generator.h:47
uint64 m_gtid_assignment_block_size
The group GTID assignment block size.
Definition: gtid_generator.h:89
void initialize(uint64 gtid_assignment_block_size)
This is initialization function that will be called in the certifier.
Definition: gtid_generator.cc:62
std::unordered_map< rpl_sidno, Gtid_generator_for_sidno > m_gtid_generator_for_sidno
GTID bookkeeping for each sidno.
Definition: gtid_generator.h:86
void recompute(const Gtid_set &gtid_set)
This function recomputes generator state.
Definition: gtid_generator.cc:54
std::pair< rpl_gno, mysql::utils::Return_status > get_next_available_gtid(const char *member_uuid, rpl_sidno sidno, const Gtid_set &gtid_set)
This method is used to get the next valid GNO for the given sidno, for the transaction originating fr...
Definition: gtid_generator.cc:32
auto get_gtid_assignment_block_size() const
Accesses gtid assignment block size the Gtid_generator was initialized with.
Definition: gtid_generator.h:79
uint64_t uint64
Definition: my_inttypes.h:69
Definition: group_replication_priv.h:44
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:109