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