MySQL 9.1.0
Source Code Documentation
gtid.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 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 MYSQL_GTID_GTID_H
25#define MYSQL_GTID_GTID_H
26
27#include <set>
28#include <sstream>
29
30#include "mysql/gtid/global.h"
31#include "mysql/gtid/tsid.h"
34
35/// @addtogroup GroupLibsMysqlGtid
36/// @{
37
38namespace mysql::gtid {
39
40/**
41 * @brief Represents a MySQL Global Transaction Identifier.
42 *
43 * This class abstracts the representation of a Global Transaction Identifier.
44 *
45 * It contains two fields, a TSID, composed of UUID and tag, and a sequence
46 * number.
47 */
48class Gtid {
49 public:
50 /// In 'UUID:SEQNO', this is the ':'
51 static constexpr auto separator_gtid{':'};
52
53 protected:
56
57 public:
58 /**
59 * @brief Construct an empty GTID
60 */
61 Gtid() = default;
62
63 /**
64 * @brief Construct a new Gtid object
65 *
66 * @param tsid TSID part of the transaction identifier
67 * @param gno The gno part of the transaction identfier.
68 */
69 Gtid(const Tsid &tsid, gno_t gno);
70
71 /**
72 * @brief Destroy the Gtid object
73 *
74 */
75 virtual ~Gtid();
76
77 /**
78 * @brief Get the sequence number of this transaction identifier.
79 *
80 * @return The sequence number part of this transaction identifier.
81 */
82 virtual gno_t get_gno() const;
83
84 /**
85 * @brief Get the uuid of this transaction identifier.
86 *
87 * @return The uuid part of this transaction identifier.
88 */
89 virtual const Uuid &get_uuid() const;
90
91 /**
92 * @brief Get the tsid of this transaction identifier.
93 *
94 * @return The tsid part of this transaction identifier.
95 */
96 virtual const Tsid &get_tsid() const;
97
98 /**
99 * @brief Get the tag of this transaction identifier.
100 *
101 * @return The tag part of this transaction identifier.
102 */
103 virtual const Tag &get_tag() const;
104
105 /**
106 * @brief Gets a human readable representation of this transaction identifier.
107 *
108 * @return A human readable representation of this transaction identifier.
109 */
110 virtual std::string to_string() const;
111
112 /**
113 * @brief Encodes GTID into a binary format. Supported is only tagged format
114 * of a GTID. Buf must be preallocated with a required number of bytes
115 *
116 * @param buf Buffer to write to
117 *
118 * @return Number of bytes written
119 */
120 virtual std::size_t encode_gtid_tagged(unsigned char *buf) const;
121
122 /**
123 * @brief Decodes GTID from a given buffer. Supported is only tagged format
124 * of a GTID. Buf must contain required number of bytes
125 *
126 * @param buf Buffer to read from
127 * @param buf_len Buffer length in bytes
128 *
129 * @return Number of bytes read from the buffer or 0 in case decoding is not
130 * possible
131 */
132 [[NODISCARD]] virtual std::size_t decode_gtid_tagged(const unsigned char *buf,
133 std::size_t buf_len);
134
135 /**
136 * @brief Gets maximum length of encoded GTID in compile time
137 *
138 * @return Maximum number of bytes needed to store GTID
139 */
140 static constexpr std::size_t get_max_encoded_length() {
142 mysql::serialization::Archive_binary::get_max_size<int64_t, 0>();
143 }
144
145 /**
146 * @brief Compares two identifiers and returns whether they match or not.
147 *
148 * @param other The other transaction identifier to compare to this one.
149 * @return true if the identifiers are equal.
150 * @return false otherwise.
151 */
152 virtual bool operator==(const Gtid &other) const;
153
154 /**
155 * @brief Compares two identifiers and returns whether they are different.
156 *
157 * @param other The other transaction identifier to compare to this one.
158 * @return true if the identifiers are different.
159 * @return false otherwise.
160 */
161 virtual bool operator!=(const Gtid &other) const;
162
163 /**
164 * @brief Copy assignment.
165 *
166 * Note that this operator will do a deep copy of the other identifier.
167 *
168 * @param other Copies the uuid and gno of the other identifier.
169 * @return a copy of the other identifier.
170 */
171 virtual Gtid &operator=(const Gtid &other);
172
173 /**
174 * @brief Construct a new Gtid object from another one, by deep copying its
175 * contents.
176 *
177 * @param other the other gtid to construct this gtid from.
178 */
179 Gtid(const Gtid &other);
180};
181
182} // namespace mysql::gtid
183
184/// @}
185
186#endif // MYSQL_GTID_GTID_H
Experimental API header.
Represents a MySQL Global Transaction Identifier.
Definition: gtid.h:48
virtual std::size_t encode_gtid_tagged(unsigned char *buf) const
Encodes GTID into a binary format.
Definition: gtid.cpp:65
static constexpr std::size_t get_max_encoded_length()
Gets maximum length of encoded GTID in compile time.
Definition: gtid.h:140
virtual ~Gtid()
Destroy the Gtid object.
virtual std::string to_string() const
Gets a human readable representation of this transaction identifier.
Definition: gtid.cpp:45
virtual bool operator==(const Gtid &other) const
Compares two identifiers and returns whether they match or not.
Definition: gtid.cpp:59
static constexpr auto separator_gtid
In 'UUID:SEQNO', this is the ':'.
Definition: gtid.h:51
virtual Gtid & operator=(const Gtid &other)
Copy assignment.
Definition: gtid.cpp:51
Tsid m_tsid
Definition: gtid.h:54
virtual const Tsid & get_tsid() const
Get the tsid of this transaction identifier.
Definition: gtid.cpp:41
Gtid()=default
Construct an empty GTID.
virtual gno_t get_gno() const
Get the sequence number of this transaction identifier.
Definition: gtid.cpp:38
virtual const Uuid & get_uuid() const
Get the uuid of this transaction identifier.
Definition: gtid.cpp:39
gno_t m_gno
Definition: gtid.h:55
virtual std::size_t decode_gtid_tagged(const unsigned char *buf, std::size_t buf_len)
Decodes GTID from a given buffer.
Definition: gtid.cpp:73
virtual bool operator!=(const Gtid &other) const
Compares two identifiers and returns whether they are different.
Definition: gtid.cpp:63
virtual const Tag & get_tag() const
Get the tag of this transaction identifier.
Definition: gtid.cpp:43
Representation of the GTID tag.
Definition: tag.h:50
Represents Transaction Source Identifier which is composed of source UUID and transaction tag.
Definition: tsid.h:44
static constexpr std::size_t get_max_encoded_length()
Obtains maximum length of encoded TSID (compile time)
Definition: tsid.h:146
Definition: buf0block_hint.cc:30
Definition: global.h:35
std::int64_t gno_t
Definition: global.h:37
#define NODISCARD
The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug.
Definition: nodiscard.h:47
Uuid is a trivial and of standard layout The structure contains the following components.
Definition: uuid.h:64