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