MySQL 8.0.40
Source Code Documentation
classic_protocol_session_track.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_SESSION_TRACK_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_SESSION_TRACK_H_
28
29// session_track as used by message::server::Ok and message::server::Eof
30
31#include <string>
32
33namespace classic_protocol {
34
35namespace borrowable {
36namespace session_track {
37
38/**
39 * Field of a session-track array.
40 *
41 * used in server::Ok and server::Eof
42 */
43template <bool Borrowed>
44class Field {
45 public:
47 std::conditional_t<Borrowed, std::string_view, std::string>;
48
49 constexpr Field(uint8_t type, string_type data)
50 : type_{type}, data_{std::move(data)} {}
51
52 constexpr uint8_t type() const noexcept { return type_; }
53 constexpr string_type data() const noexcept { return data_; }
54
55 private:
56 uint8_t type_;
58};
59
60template <bool Borrowed>
61inline bool operator==(const Field<Borrowed> &a, const Field<Borrowed> &b) {
62 return (a.type() == b.type()) && (a.data() == b.data());
63}
64
65/**
66 * system-variable changed.
67 *
68 * see: session_track_system_variable
69 */
70template <bool Borrowed>
72 public:
74 std::conditional_t<Borrowed, std::string_view, std::string>;
76 : key_{std::move(key)}, value_{std::move(value)} {}
77
78 constexpr string_type key() const noexcept { return key_; }
79 constexpr string_type value() const noexcept { return value_; }
80
81 private:
84};
85
86template <bool Borrowed>
88 const SystemVariable<Borrowed> &b) {
89 return (a.key() == b.key()) && (a.value() == b.value());
90}
91
92/**
93 * schema changed.
94 *
95 * see: session_track_schema
96 */
97template <bool Borrowed>
98class Schema {
99 public:
101 std::conditional_t<Borrowed, std::string_view, std::string>;
102
103 constexpr Schema(string_type schema) : schema_{std::move(schema)} {}
104
105 constexpr string_type schema() const noexcept { return schema_; }
106
107 private:
109};
110
111template <bool Borrowed>
112inline bool operator==(const Schema<Borrowed> &a, const Schema<Borrowed> &b) {
113 return (a.schema() == b.schema());
114}
115
116/**
117 * state changed.
118 *
119 * see: session_track_session_state
120 */
121class State {
122 public:
123 constexpr State(int8_t state) : state_{std::move(state)} {}
124
125 constexpr int8_t state() const noexcept { return state_; }
126
127 private:
128 int8_t state_;
129};
130
131constexpr inline bool operator==(const State &a, const State &b) {
132 return (a.state() == b.state());
133}
134
135/**
136 * gtid changed.
137 *
138 * - FixedInt<1> spec
139 * - gtid-string
140 * -
141 *
142 * see: session_track_gtid
143 */
144template <bool Borrowed>
145class Gtid {
146 public:
148 std::conditional_t<Borrowed, std::string_view, std::string>;
149 constexpr Gtid(uint8_t spec, string_type gtid)
150 : spec_{spec}, gtid_{std::move(gtid)} {}
151
152 constexpr uint8_t spec() const noexcept { return spec_; }
153 constexpr string_type gtid() const { return gtid_; }
154
155 private:
156 uint8_t spec_;
158};
159
160template <bool Borrowed>
161inline bool operator==(const Gtid<Borrowed> &a, const Gtid<Borrowed> &b) {
162 return (a.spec() == b.spec()) && (a.gtid() == b.gtid());
163}
164
165/**
166 * TransactionState changed.
167 *
168 * - trx_type: Explicit|Implicit|none
169 * - read_unsafe: one_or_more|none
170 * - read_trx: one_or_more|none
171 * - write_unsafe: one_or_more|none
172 * - write_trx: one_or_more|none
173 * - stmt_unsafe: one_or_more|none
174 * - resultset: one_or_more|none
175 * - locked_tables: one_or_more|none
176 *
177 * implicit transaction: no autocommit, stmt against transactionable table
178 * without START TRANSACTION
179 * explicit transaction: START TRANSACTION
180 *
181 * read_unsafe: read-operation against non-transactionable table
182 * read_trx: read-operation against transactionable table
183 * write_unsafe: write-operation against non-transactionable table
184 * write_trx: write-operation against transactionable table
185 * stmt_unsafe: an unusafe statement was executed like RAND()
186 * resultset: some resultset was sent
187 * locked_tables: some tables got locked explicitly
188 *
189 * 'resultset' may be triggered without 'read_trx' and 'read_unsafe' if a
190 * 'SELECT' was executed against 'dual' or without table.
191 *
192 * see: session_track_transaction_info
193 */
195 public:
196 constexpr TransactionState(char trx_type, char read_unsafe, char read_trx,
197 char write_unsafe, char write_trx,
198 char stmt_unsafe, char resultset,
199 char locked_tables)
208
209 constexpr char trx_type() const noexcept { return trx_type_; }
210 constexpr char read_unsafe() const noexcept { return read_unsafe_; }
211 constexpr char read_trx() const noexcept { return read_trx_; }
212 constexpr char write_unsafe() const noexcept { return write_unsafe_; }
213 constexpr char write_trx() const noexcept { return write_trx_; }
214 constexpr char stmt_unsafe() const noexcept { return stmt_unsafe_; }
215 constexpr char resultset() const noexcept { return resultset_; }
216 constexpr char locked_tables() const noexcept { return locked_tables_; }
217
218 private:
219 char trx_type_; // T|I|_
220 char read_unsafe_; // r|_
221 char read_trx_; // R|_
222 char write_unsafe_; // w|_
223 char write_trx_; // W|_
224 char stmt_unsafe_; // s|_
225 char resultset_; // S|_
226 char locked_tables_; // L|_
227};
228
229inline bool operator==(const TransactionState &a, const TransactionState &b) {
230 return (a.trx_type() == b.trx_type()) &&
231 (a.read_unsafe() == b.read_unsafe()) &&
232 (a.read_trx() == b.read_trx()) &&
233 (a.write_unsafe() == b.write_unsafe()) &&
234 (a.write_trx() == b.write_trx()) &&
235 (a.stmt_unsafe() == b.stmt_unsafe()) &&
236 (a.resultset() == b.resultset()) &&
237 (a.locked_tables() == b.locked_tables());
238}
239
240/**
241 * TransactionCharacteristics changed.
242 *
243 * resembles the SQL-text which started the transaction.
244 *
245 * see: session_track_transaction_info
246 */
247template <bool Borrowed>
249 public:
251 std::conditional_t<Borrowed, std::string_view, std::string>;
252
255
256 constexpr string_type characteristics() const { return characteristics_; }
257
258 private:
260};
261
262template <bool Borrowed>
265 return (a.characteristics() == b.characteristics());
266}
267} // namespace session_track
268} // namespace borrowable
269
270namespace borrowed {
271namespace session_track {
280} // namespace session_track
281} // namespace borrowed
282
283namespace session_track {
292} // namespace session_track
293
294} // namespace classic_protocol
295
296#endif
Field of a session-track array.
Definition: classic_protocol_session_track.h:44
uint8_t type_
Definition: classic_protocol_session_track.h:56
string_type data_
Definition: classic_protocol_session_track.h:57
constexpr string_type data() const noexcept
Definition: classic_protocol_session_track.h:53
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:47
constexpr uint8_t type() const noexcept
Definition: classic_protocol_session_track.h:52
constexpr Field(uint8_t type, string_type data)
Definition: classic_protocol_session_track.h:49
gtid changed.
Definition: classic_protocol_session_track.h:145
constexpr string_type gtid() const
Definition: classic_protocol_session_track.h:153
string_type gtid_
Definition: classic_protocol_session_track.h:157
constexpr Gtid(uint8_t spec, string_type gtid)
Definition: classic_protocol_session_track.h:149
constexpr uint8_t spec() const noexcept
Definition: classic_protocol_session_track.h:152
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:148
uint8_t spec_
Definition: classic_protocol_session_track.h:156
schema changed.
Definition: classic_protocol_session_track.h:98
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:101
constexpr Schema(string_type schema)
Definition: classic_protocol_session_track.h:103
constexpr string_type schema() const noexcept
Definition: classic_protocol_session_track.h:105
string_type schema_
Definition: classic_protocol_session_track.h:108
state changed.
Definition: classic_protocol_session_track.h:121
constexpr State(int8_t state)
Definition: classic_protocol_session_track.h:123
constexpr int8_t state() const noexcept
Definition: classic_protocol_session_track.h:125
int8_t state_
Definition: classic_protocol_session_track.h:128
system-variable changed.
Definition: classic_protocol_session_track.h:71
string_type key_
Definition: classic_protocol_session_track.h:82
constexpr string_type key() const noexcept
Definition: classic_protocol_session_track.h:78
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:74
constexpr string_type value() const noexcept
Definition: classic_protocol_session_track.h:79
constexpr SystemVariable(string_type key, string_type value)
Definition: classic_protocol_session_track.h:75
string_type value_
Definition: classic_protocol_session_track.h:83
TransactionCharacteristics changed.
Definition: classic_protocol_session_track.h:248
std::conditional_t< Borrowed, std::string_view, std::string > string_type
Definition: classic_protocol_session_track.h:251
string_type characteristics_
Definition: classic_protocol_session_track.h:259
constexpr string_type characteristics() const
Definition: classic_protocol_session_track.h:256
constexpr TransactionCharacteristics(string_type characteristics)
Definition: classic_protocol_session_track.h:253
TransactionState changed.
Definition: classic_protocol_session_track.h:194
constexpr char write_trx() const noexcept
Definition: classic_protocol_session_track.h:213
constexpr char read_unsafe() const noexcept
Definition: classic_protocol_session_track.h:210
char read_unsafe_
Definition: classic_protocol_session_track.h:220
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:196
char write_unsafe_
Definition: classic_protocol_session_track.h:222
char trx_type_
Definition: classic_protocol_session_track.h:219
constexpr char resultset() const noexcept
Definition: classic_protocol_session_track.h:215
constexpr char trx_type() const noexcept
Definition: classic_protocol_session_track.h:209
constexpr char write_unsafe() const noexcept
Definition: classic_protocol_session_track.h:212
char resultset_
Definition: classic_protocol_session_track.h:225
constexpr char read_trx() const noexcept
Definition: classic_protocol_session_track.h:211
char read_trx_
Definition: classic_protocol_session_track.h:221
constexpr char locked_tables() const noexcept
Definition: classic_protocol_session_track.h:216
char stmt_unsafe_
Definition: classic_protocol_session_track.h:224
constexpr char stmt_unsafe() const noexcept
Definition: classic_protocol_session_track.h:214
char locked_tables_
Definition: classic_protocol_session_track.h:226
char write_trx_
Definition: classic_protocol_session_track.h:223
bool operator==(const Field< Borrowed > &a, const Field< Borrowed > &b)
Definition: classic_protocol_session_track.h:61
constexpr value_type session_track
Definition: classic_protocol_constants.h:61
borrowable::session_track::TransactionState TransactionState
Definition: classic_protocol_session_track.h:287
borrowable::session_track::State State
Definition: classic_protocol_session_track.h:290
Definition: classic_protocol_binary.h:39
Definition: gcs_xcom_synode.h:64