MySQL 8.3.0
Source Code Documentation
trx_boundary_parser.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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/**
24 @file
25
26 @brief Transaction boundary parser definitions. This includes code for
27 parsing a stream of events identifying the transaction boundaries (like
28 if the event is starting a transaction, is in the middle of a transaction
29 or if the event is ending a transaction).
30*/
31
32#ifndef MYSQL_BINLOG_EVENT_TRX_BOUNDARY_PARSER_H
33#define MYSQL_BINLOG_EVENT_TRX_BOUNDARY_PARSER_H
34
35#include <stddef.h>
36
38
39/// @addtogroup GroupLibsMysqlBinlogEvent
40/// @{
41
42namespace mysql::binlog::event {
43
44/**
45 @class Transaction_boundary_parser
46
47 This is the base class for verifying transaction boundaries.
48*/
50 public:
51 /**
52 The context where the parser is used
53 */
55 /* Parser used on a receiver, like an IO thread */
57 /* Parser used in an applier parsing Relay Log files */
59 };
60
61 /**
62 Constructor.
63 @param context If this parser is used on a receiver or applier context
64 */
70
71 /**
72 Destructor
73 */
75
76 /**
77 Reset the transaction boundary parser state.
78 */
79 void reset();
80
81 /*
82 In an event stream, an event is considered safe to be separated from the
83 next if it is not inside a transaction.
84 We need to know this in order to evaluate if we will let the relay log
85 to be rotated or not.
86 */
87
88 /**
89 State if the transaction boundary parser is inside a transaction.
90 This "inside a transaction" means that the parser was fed with at least
91 one event of a transaction, but the transaction wasn't completely fed yet.
92 This also means that the last event fed depends on following event(s) to
93 be correctly applied.
94
95 @return false if the boundary parser is not inside a transaction.
96 true if the boundary parser is inside a transaction.
97 */
98 inline bool is_inside_transaction() {
101 }
102
103 /**
104 State if the transaction boundary parser is not inside a transaction.
105 This "not inside a transaction" means that the parser was fed with an
106 event that doesn't depend on following events.
107
108 @return false if the boundary parser is inside a transaction.
109 true if the boundary parser is not inside a transaction.
110 */
113 }
114
115 /**
116 State if the transaction boundary parser was fed with a sequence of events
117 that the parser wasn't able to parse correctly.
118
119 @return false if the boundary parser is not in the error state.
120 true if the boundary parser is in the error state.
121 */
122 inline bool is_error() {
124 }
125
126 /**
127 Feed the transaction boundary parser with a Log_event of any type
128 in object type.
129
130 @param log_event_info the event object
131 @param throw_warnings If the function should throw warning messages while
132 updating the boundary parser state.
133 While initializing the Relay_log_info the
134 relay log is scanned backwards and this could
135 generate false errors. So, in this case, we
136 don't want to throw warnings.
137
138 @return false if the transaction boundary parser accepted the event.
139 true if the transaction boundary parser didn't accepted the event.
140 */
142 bool throw_warnings);
143
144 /**
145 Evaluate given the current info about boundary type, event type and
146 parser state if the given event violates any restriction associated
147 to row based only modes.
148
149 @param event_info the event information: type, query, is it ignorable
150
151 @return true if it violates any restrictions
152 false if it passes all tests
153 */
156
157 /**
158 Rolls back to the last parser state.
159
160 This should be called in the case of a failed queued event.
161 */
163
164 /**
165 Internal error indentifiers for parser issues
166 */
168 /* Unexpected event that the parser can't ignore */
170 /* Unexpected GTID event in the stream */
172 /* Unexpected BEGIN event in the stream */
174 /* Unexpected Commit event in the stream */
176 /* Unexpected XA Rollback event in the stream */
178 };
179
180 private:
183 /* Gtid_log_event */
185 /* Query_log_event(BEGIN), Query_log_event(XA START) */
187 /* Xid, Query_log_event(COMMIT), Query_log_event(ROLLBACK),
188 XA_Prepare_log_event */
190 /* Query_log_event(XA ROLLBACK) */
192 /* User_var, Intvar and Rand */
194 /*
195 All other Query_log_events and all other DML events
196 (Rows, Load_data, etc.)
197 */
199 /* Incident */
201 /*
202 All non DDL/DML events: Format_desc, Rotate,
203 Previous_gtids, Stop, etc.
204 */
206 /*
207 Transaction payload boundary.
208 */
210 };
211
212 /*
213 Internal states for parsing a stream of events.
214
215 DDL has the format:
216 DDL-1: [GTID]
217 DDL-2: [User] [Intvar] [Rand]
218 DDL-3: Query
219
220 DML has the format:
221 DML-1: [GTID]
222 DML-2: Query(BEGIN)
223 DML-3: Statements
224 DML-4: (Query(COMMIT) | Query([XA] ROLLBACK) | Xid | Xa_prepare)
225
226 Compressed DML/DDL has the format:
227 DDL-1: GTID
228 RAW-1: Transaction_Payload
229 */
231 /* NONE is set after DDL-3 or DML-4 or RAW-1*/
233 /* GTID is set after DDL-1 or DML-1 */
235 /* DDL is set after DDL-2 */
237 /* DML is set after DML-2 */
239 /* ERROR is set whenever the above pattern is not followed */
241 };
242
243 /**
244 Current internal state of the event parser.
245 */
247
248 /**
249 Last internal state of the event parser.
250
251 This should be used if we had to roll back the last parsed event.
252 */
254
255 /**
256 The last processed boundary event type
257 */
259
260 /**
261 In which context of the boundary parser is used
262 */
264
265 /**
266 Parses an raw event based on the event parser logic.
267
268 @param event_info Info about an event: type, query, is it ignorable
269 @param throw_warnings If the function should throw warning messages
270 while updating the boundary parser state.
271 @return What is the boundary type associated to this event
272 */
275 bool throw_warnings);
276
277 /**
278 Set the boundary parser state based on the event parser logic.
279
280 @param event_boundary_type the current event boundary type
281 @param throw_warnings If the function should throw warning messages
282 while updating the boundary parser state.
283
284 @return true if there is an error while updating the state, like unexpected
285 event order
286 */
287 bool update_state(enum_event_boundary_type event_boundary_type,
288 bool throw_warnings);
289
290 /**
291 Log warnings using some defined logging interface.
292
293 @note: this method is empty by default. Extend it to add a logging routine.
294
295 @param error the error number
296 @param message the error message
297 */
298 virtual void log_server_warning(int error, const char *message);
299};
300
301} // namespace mysql::binlog::event
302
303/// @}
304
305#endif // MYSQL_BINLOG_EVENT_TRX_BOUNDARY_PARSER_H
This is the base class for verifying transaction boundaries.
Definition: trx_boundary_parser.h:49
enum_event_parser_state
Definition: trx_boundary_parser.h:230
@ EVENT_PARSER_DDL
Definition: trx_boundary_parser.h:236
@ EVENT_PARSER_DML
Definition: trx_boundary_parser.h:238
@ EVENT_PARSER_GTID
Definition: trx_boundary_parser.h:234
@ EVENT_PARSER_NONE
Definition: trx_boundary_parser.h:232
@ EVENT_PARSER_ERROR
Definition: trx_boundary_parser.h:240
bool is_not_inside_transaction()
State if the transaction boundary parser is not inside a transaction.
Definition: trx_boundary_parser.h:111
enum_event_parser_state last_parser_state
Last internal state of the event parser.
Definition: trx_boundary_parser.h:253
void reset()
Reset the transaction boundary parser state.
Definition: trx_boundary_parser.cpp:53
void rollback()
Rolls back to the last parser state.
Definition: trx_boundary_parser.h:162
enum_event_boundary_type m_current_boundary_state
The last processed boundary event type.
Definition: trx_boundary_parser.h:258
bool feed_event(mysql::binlog::event::Log_event_basic_info log_event_info, bool throw_warnings)
Feed the transaction boundary parser with a Log_event of any type in object type.
Definition: trx_boundary_parser.cpp:63
bool check_row_logging_constraints(mysql::binlog::event::Log_event_basic_info event_info)
Evaluate given the current info about boundary type, event type and parser state if the given event v...
Definition: trx_boundary_parser.cpp:73
enum_event_boundary_type get_event_boundary_type(mysql::binlog::event::Log_event_basic_info event_info, bool throw_warnings)
Parses an raw event based on the event parser logic.
Definition: trx_boundary_parser.cpp:145
bool is_inside_transaction()
State if the transaction boundary parser is inside a transaction.
Definition: trx_boundary_parser.h:98
enum_trx_boundary_parser_context
The context where the parser is used.
Definition: trx_boundary_parser.h:54
@ TRX_BOUNDARY_PARSER_APPLIER
Definition: trx_boundary_parser.h:58
@ TRX_BOUNDARY_PARSER_RECEIVER
Definition: trx_boundary_parser.h:56
enum_event_boundary_type
Definition: trx_boundary_parser.h:181
@ EVENT_BOUNDARY_TYPE_END_TRX
Definition: trx_boundary_parser.h:189
@ EVENT_BOUNDARY_TYPE_ERROR
Definition: trx_boundary_parser.h:182
@ EVENT_BOUNDARY_TYPE_INCIDENT
Definition: trx_boundary_parser.h:200
@ EVENT_BOUNDARY_TYPE_STATEMENT
Definition: trx_boundary_parser.h:198
@ EVENT_BOUNDARY_TYPE_TRANSACTION_PAYLOAD
Definition: trx_boundary_parser.h:209
@ EVENT_BOUNDARY_TYPE_IGNORE
Definition: trx_boundary_parser.h:205
@ EVENT_BOUNDARY_TYPE_GTID
Definition: trx_boundary_parser.h:184
@ EVENT_BOUNDARY_TYPE_PRE_STATEMENT
Definition: trx_boundary_parser.h:193
@ EVENT_BOUNDARY_TYPE_BEGIN_TRX
Definition: trx_boundary_parser.h:186
@ EVENT_BOUNDARY_TYPE_END_XA_TRX
Definition: trx_boundary_parser.h:191
enum_event_parser_error
Internal error indentifiers for parser issues.
Definition: trx_boundary_parser.h:167
@ ER_TRX_BOUND_UNEXPECTED_COMMIT_ROLLBACK_OR_XID_LOG_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:175
@ ER_TRX_BOUND_GTID_LOG_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:171
@ ER_TRX_BOUND_UNEXPECTED_BEGIN_IN_STREAM
Definition: trx_boundary_parser.h:173
@ ER_TRX_BOUND_UNEXPECTED_XA_ROLLBACK_IN_STREAM
Definition: trx_boundary_parser.h:177
@ ER_TRX_BOUND_UNSUPPORTED_UNIGNORABLE_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:169
enum_trx_boundary_parser_context m_trx_boundary_parser_context
In which context of the boundary parser is used.
Definition: trx_boundary_parser.h:263
bool is_error()
State if the transaction boundary parser was fed with a sequence of events that the parser wasn't abl...
Definition: trx_boundary_parser.h:122
Transaction_boundary_parser(enum_trx_boundary_parser_context context)
Constructor.
Definition: trx_boundary_parser.h:65
enum_event_parser_state current_parser_state
Current internal state of the event parser.
Definition: trx_boundary_parser.h:246
bool update_state(enum_event_boundary_type event_boundary_type, bool throw_warnings)
Set the boundary parser state based on the event parser logic.
Definition: trx_boundary_parser.cpp:301
virtual void log_server_warning(int error, const char *message)
Log warnings using some defined logging interface.
Definition: trx_boundary_parser.cpp:538
Contains the classes representing events operating in the replication stream properties.
The namespace contains classes representing events that can occur in a replication stream.
Definition: binlog_event.cpp:35
Struct to pass basic information about a event: type, query, is it ignorable.
Definition: binlog_event.h:405