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