MySQL 8.3.0
Source Code Documentation
classic_protocol_session_track.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
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 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
25#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_SESSION_TRACK_H_
26#define MYSQL_ROUTER_CLASSIC_PROTOCOL_SESSION_TRACK_H_
27
28// session_track as used by message::server::Ok and message::server::Eof
29
30#include <string>
31
33
34namespace classic_protocol {
35
36namespace borrowable {
37namespace session_track {
38
39/**
40 * Field of a session-track array.
41 *
42 * used in server::Ok and server::Eof
43 */
44template <bool Borrowed>
45class Field {
46 public:
48 std::conditional_t<Borrowed, std::string_view, std::string>;
49
50 constexpr Field(uint8_t type, string_type data)
51 : type_{type}, data_{std::move(data)} {}
52
53 constexpr uint8_t type() const noexcept { return type_; }
54 constexpr string_type data() const noexcept { return data_; }
55
56 private:
57 uint8_t type_;
59};
60
61template <bool Borrowed>
62inline bool operator==(const Field<Borrowed> &a, const Field<Borrowed> &b) {
63 return (a.type() == b.type()) && (a.data() == b.data());
64}
65
66/**
67 * system-variable changed.
68 *
69 * see: session_track_system_variable
70 */
71template <bool Borrowed>
73 public:
75 std::conditional_t<Borrowed, std::string_view, std::string>;
77 : key_{std::move(key)}, value_{std::move(value)} {}
78
79 constexpr string_type key() const noexcept { return key_; }
80 constexpr string_type value() const noexcept { return value_; }
81
82 private:
85};
86
87template <bool Borrowed>
89 const SystemVariable<Borrowed> &b) {
90 return (a.key() == b.key()) && (a.value() == b.value());
91}
92
93/**
94 * schema changed.
95 *
96 * see: session_track_schema
97 */
98template <bool Borrowed>
99class Schema {
100 public:
102 std::conditional_t<Borrowed, std::string_view, std::string>;
103
104 constexpr Schema(string_type schema) : schema_{std::move(schema)} {}
105
106 constexpr string_type schema() const noexcept { return schema_; }
107
108 private:
110};
111
112template <bool Borrowed>
113inline bool operator==(const Schema<Borrowed> &a, const Schema<Borrowed> &b) {
114 return (a.schema() == b.schema());
115}
116
117/**
118 * state changed.
119 *
120 * see: session_track_session_state
121 */
122class State {
123 public:
124 constexpr State(int8_t state) : state_{std::move(state)} {}
125
126 constexpr int8_t state() const noexcept { return state_; }
127
128 private:
129 int8_t state_;
130};
131
132constexpr inline bool operator==(const State &a, const State &b) {
133 return (a.state() == b.state());
134}
135
136/**
137 * gtid changed.
138 *
139 * - FixedInt<1> spec
140 * - gtid-string
141 * -
142 *
143 * see: session_track_gtid
144 */
145template <bool Borrowed>
146class Gtid {
147 public:
149 std::conditional_t<Borrowed, std::string_view, std::string>;
150 constexpr Gtid(uint8_t spec, string_type gtid)
151 : spec_{spec}, gtid_{std::move(gtid)} {}
152
153 constexpr uint8_t spec() const noexcept { return spec_; }
154 constexpr string_type gtid() const { return gtid_; }
155
156 private:
157 uint8_t spec_;
159};
160
161template <bool Borrowed>
162inline bool operator==(const Gtid<Borrowed> &a, const Gtid<Borrowed> &b) {
163 return (a.spec() == b.spec()) && (a.gtid() == b.gtid());
164}
165
166/**
167 * TransactionState changed.
168 *
169 * - trx_type: Explicit|Implicit|none
170 * - read_unsafe: one_or_more|none
171 * - read_trx: one_or_more|none
172 * - write_unsafe: one_or_more|none
173 * - write_trx: one_or_more|none
174 * - stmt_unsafe: one_or_more|none
175 * - resultset: one_or_more|none
176 * - locked_tables: one_or_more|none
177 *
178 * implicit transaction: no autocommit, stmt against transactionable table
179 * without START TRANSACTION
180 * explicit transaction: START TRANSACTION
181 *
182 * read_unsafe: read-operation against non-transactionable table
183 * read_trx: read-operation against transactionable table
184 * write_unsafe: write-operation against non-transactionable table
185 * write_trx: write-operation against transactionable table
186 * stmt_unsafe: an unusafe statement was executed like RAND()
187 * resultset: some resultset was sent
188 * locked_tables: some tables got locked explicitly
189 *
190 * 'resultset' may be triggered without 'read_trx' and 'read_unsafe' if a
191 * 'SELECT' was executed against 'dual' or without table.
192 *
193 * see: session_track_transaction_info
194 */
196 public:
197 constexpr TransactionState(char trx_type, char read_unsafe, char read_trx,
198 char write_unsafe, char write_trx,
199 char stmt_unsafe, char resultset,
200 char locked_tables)
209
211 : trx_type_{val[0]},
212 read_unsafe_{val[1]},
213 read_trx_{val[2]},
214 write_unsafe_{val[3]},
215 write_trx_{val[4]},
216 stmt_unsafe_{val[5]},
217 resultset_{val[6]},
218 locked_tables_{val[7]} {}
219
220 constexpr char trx_type() const noexcept { return trx_type_; }
221 constexpr char read_unsafe() const noexcept { return read_unsafe_; }
222 constexpr char read_trx() const noexcept { return read_trx_; }
223 constexpr char write_unsafe() const noexcept { return write_unsafe_; }
224 constexpr char write_trx() const noexcept { return write_trx_; }
225 constexpr char stmt_unsafe() const noexcept { return stmt_unsafe_; }
226 constexpr char resultset() const noexcept { return resultset_; }
227 constexpr char locked_tables() const noexcept { return locked_tables_; }
228
229 private:
230 char trx_type_; // T|I|_
231 char read_unsafe_; // r|_
232 char read_trx_; // R|_
233 char write_unsafe_; // w|_
234 char write_trx_; // W|_
235 char stmt_unsafe_; // s|_
236 char resultset_; // S|_
237 char locked_tables_; // L|_
238};
239
240inline bool operator==(const TransactionState &a, const TransactionState &b) {
241 return (a.trx_type() == b.trx_type()) &&
242 (a.read_unsafe() == b.read_unsafe()) &&
243 (a.read_trx() == b.read_trx()) &&
244 (a.write_unsafe() == b.write_unsafe()) &&
245 (a.write_trx() == b.write_trx()) &&
246 (a.stmt_unsafe() == b.stmt_unsafe()) &&
247 (a.resultset() == b.resultset()) &&
248 (a.locked_tables() == b.locked_tables());
249}
250
251/**
252 * TransactionCharacteristics changed.
253 *
254 * resembles the SQL-text which started the transaction.
255 *
256 * see: session_track_transaction_info
257 */
258template <bool Borrowed>
260 public:
262 std::conditional_t<Borrowed, std::string_view, std::string>;
263
266
267 constexpr string_type characteristics() const { return characteristics_; }
268
269 private:
271};
272
273template <bool Borrowed>
276 return (a.characteristics() == b.characteristics());
277}
278} // namespace session_track
279} // namespace borrowable
280
281namespace borrowed {
282namespace session_track {
291} // namespace session_track
292} // namespace borrowed
293
294namespace session_track {
303} // namespace session_track
304
305} // namespace classic_protocol
306
307#endif
Field of a session-track array.
Definition: classic_protocol_session_track.h:45
uint8_t type_
Definition: classic_protocol_session_track.h:57
string_type data_
Definition: classic_protocol_session_track.h:58
constexpr string_type data() const noexcept
Definition: classic_protocol_session_track.h:54
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:48
constexpr uint8_t type() const noexcept
Definition: classic_protocol_session_track.h:53
constexpr Field(uint8_t type, string_type data)
Definition: classic_protocol_session_track.h:50
gtid changed.
Definition: classic_protocol_session_track.h:146
constexpr string_type gtid() const
Definition: classic_protocol_session_track.h:154
string_type gtid_
Definition: classic_protocol_session_track.h:158
constexpr Gtid(uint8_t spec, string_type gtid)
Definition: classic_protocol_session_track.h:150
constexpr uint8_t spec() const noexcept
Definition: classic_protocol_session_track.h:153
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:149
uint8_t spec_
Definition: classic_protocol_session_track.h:157
schema changed.
Definition: classic_protocol_session_track.h:99
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:102
constexpr Schema(string_type schema)
Definition: classic_protocol_session_track.h:104
constexpr string_type schema() const noexcept
Definition: classic_protocol_session_track.h:106
string_type schema_
Definition: classic_protocol_session_track.h:109
state changed.
Definition: classic_protocol_session_track.h:122
constexpr State(int8_t state)
Definition: classic_protocol_session_track.h:124
constexpr int8_t state() const noexcept
Definition: classic_protocol_session_track.h:126
int8_t state_
Definition: classic_protocol_session_track.h:129
system-variable changed.
Definition: classic_protocol_session_track.h:72
string_type key_
Definition: classic_protocol_session_track.h:83
constexpr string_type key() const noexcept
Definition: classic_protocol_session_track.h:79
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:75
constexpr string_type value() const noexcept
Definition: classic_protocol_session_track.h:80
constexpr SystemVariable(string_type key, string_type value)
Definition: classic_protocol_session_track.h:76
string_type value_
Definition: classic_protocol_session_track.h:84
TransactionCharacteristics changed.
Definition: classic_protocol_session_track.h:259
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:262
string_type characteristics_
Definition: classic_protocol_session_track.h:270
constexpr string_type characteristics() const
Definition: classic_protocol_session_track.h:267
constexpr TransactionCharacteristics(string_type characteristics)
Definition: classic_protocol_session_track.h:264
TransactionState changed.
Definition: classic_protocol_session_track.h:195
constexpr char write_trx() const noexcept
Definition: classic_protocol_session_track.h:224
constexpr char read_unsafe() const noexcept
Definition: classic_protocol_session_track.h:221
char read_unsafe_
Definition: classic_protocol_session_track.h:231
constexpr TransactionState(stdx::span< char, 8 > val)
Definition: classic_protocol_session_track.h:210
constexpr TransactionState(char trx_type, char read_unsafe, char read_trx, char write_unsafe, char write_trx, char stmt_unsafe, char resultset, char locked_tables)
Definition: classic_protocol_session_track.h:197
char write_unsafe_
Definition: classic_protocol_session_track.h:233
char trx_type_
Definition: classic_protocol_session_track.h:230
constexpr char resultset() const noexcept
Definition: classic_protocol_session_track.h:226
constexpr char trx_type() const noexcept
Definition: classic_protocol_session_track.h:220
constexpr char write_unsafe() const noexcept
Definition: classic_protocol_session_track.h:223
char resultset_
Definition: classic_protocol_session_track.h:236
constexpr char read_trx() const noexcept
Definition: classic_protocol_session_track.h:222
char read_trx_
Definition: classic_protocol_session_track.h:232
constexpr char locked_tables() const noexcept
Definition: classic_protocol_session_track.h:227
char stmt_unsafe_
Definition: classic_protocol_session_track.h:235
constexpr char stmt_unsafe() const noexcept
Definition: classic_protocol_session_track.h:225
char locked_tables_
Definition: classic_protocol_session_track.h:237
char write_trx_
Definition: classic_protocol_session_track.h:234
Definition: span.h:264
bool operator==(const Field< Borrowed > &a, const Field< Borrowed > &b)
Definition: classic_protocol_session_track.h:62
constexpr value_type session_track
Definition: classic_protocol_constants.h:60
borrowable::session_track::TransactionState TransactionState
Definition: classic_protocol_session_track.h:298
borrowable::session_track::State State
Definition: classic_protocol_session_track.h:301
Definition: classic_protocol_binary.h:38
Definition: varlen_sort.h:174