MySQL 9.0.0
Source Code Documentation
trx_boundary_parser.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 /**
105 State if the transaction boundary parser is not inside a transaction.
106 This "not inside a transaction" means that the parser was fed with an
107 event that doesn't depend on following events.
108
109 @return false if the boundary parser is inside a transaction.
110 true if the boundary parser is not inside a transaction.
111 */
114 }
115
116 /**
117 State if the transaction boundary parser was fed with a sequence of events
118 that the parser wasn't able to parse correctly.
119
120 @return false if the boundary parser is not in the error state.
121 true if the boundary parser is in the error state.
122 */
123 inline bool is_error() {
125 }
126
127 /**
128 Feed the transaction boundary parser with a Log_event of any type
129 in object type.
130
131 @param log_event_info the event object
132 @param throw_warnings If the function should throw warning messages while
133 updating the boundary parser state.
134 While initializing the Relay_log_info the
135 relay log is scanned backwards and this could
136 generate false errors. So, in this case, we
137 don't want to throw warnings.
138
139 @return false if the transaction boundary parser accepted the event.
140 true if the transaction boundary parser didn't accepted the event.
141 */
143 bool throw_warnings);
144
145 /**
146 Evaluate given the current info about boundary type, event type and
147 parser state if the given event violates any restriction associated
148 to row based only modes.
149
150 @param event_info the event information: type, query, is it ignorable
151
152 @return true if it violates any restrictions
153 false if it passes all tests
154 */
157
158 /**
159 Rolls back to the last parser state.
160
161 This should be called in the case of a failed queued event.
162 */
164
165 /**
166 Internal error indentifiers for parser issues
167 */
169 /* Unexpected event that the parser can't ignore */
171 /* Unexpected GTID event in the stream */
173 /* Unexpected BEGIN event in the stream */
175 /* Unexpected Commit event in the stream */
177 /* Unexpected XA Rollback event in the stream */
179 };
180
181 private:
184 /* Gtid_log_event */
186 /* Query_log_event(BEGIN), Query_log_event(XA START) */
188 /* Xid, Query_log_event(COMMIT), Query_log_event(ROLLBACK),
189 XA_Prepare_log_event */
191 /* Query_log_event(XA ROLLBACK) */
193 /* User_var, Intvar and Rand */
195 /*
196 All other Query_log_events and all other DML events
197 (Rows, Load_data, etc.)
198 */
200 /* Incident */
202 /*
203 All non DDL/DML events: Format_desc, Rotate,
204 Previous_gtids, Stop, etc.
205 */
207 /*
208 Transaction payload boundary.
209 */
211 };
212
213 /*
214 Internal states for parsing a stream of events.
215
216 DDL has the format:
217 DDL-1: [GTID]
218 DDL-2: [User] [Intvar] [Rand]
219 DDL-3: Query
220
221 DML has the format:
222 DML-1: [GTID]
223 DML-2: Query(BEGIN)
224 DML-3: Statements
225 DML-4: (Query(COMMIT) | Query([XA] ROLLBACK) | Xid | Xa_prepare)
226
227 Compressed DML/DDL has the format:
228 DDL-1: GTID
229 RAW-1: Transaction_Payload
230 */
232 /* NONE is set after DDL-3 or DML-4 or RAW-1*/
234 /* GTID is set after DDL-1 or DML-1 */
236 /* DDL is set after DDL-2 */
238 /* DML is set after DML-2 */
240 /* ERROR is set whenever the above pattern is not followed */
242 };
243
244 /**
245 Current internal state of the event parser.
246 */
248
249 /**
250 Last internal state of the event parser.
251
252 This should be used if we had to roll back the last parsed event.
253 */
255
256 /**
257 The last processed boundary event type
258 */
260
261 /**
262 In which context of the boundary parser is used
263 */
265
266 /**
267 Parses an raw event based on the event parser logic.
268
269 @param event_info Info about an event: type, query, is it ignorable
270 @param throw_warnings If the function should throw warning messages
271 while updating the boundary parser state.
272 @return What is the boundary type associated to this event
273 */
276 bool throw_warnings);
277
278 /**
279 Set the boundary parser state based on the event parser logic.
280
281 @param event_boundary_type the current event boundary type
282 @param throw_warnings If the function should throw warning messages
283 while updating the boundary parser state.
284
285 @return true if there is an error while updating the state, like unexpected
286 event order
287 */
288 bool update_state(enum_event_boundary_type event_boundary_type,
289 bool throw_warnings);
290
291 /**
292 Log warnings using some defined logging interface.
293
294 @note: this method is empty by default. Extend it to add a logging routine.
295
296 @param error the error number
297 @param message the error message
298 */
299 virtual void log_server_warning(int error, const char *message);
300};
301
302} // namespace mysql::binlog::event
303
304/// @}
305
306#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:231
@ EVENT_PARSER_DDL
Definition: trx_boundary_parser.h:237
@ EVENT_PARSER_DML
Definition: trx_boundary_parser.h:239
@ EVENT_PARSER_GTID
Definition: trx_boundary_parser.h:235
@ EVENT_PARSER_NONE
Definition: trx_boundary_parser.h:233
@ EVENT_PARSER_ERROR
Definition: trx_boundary_parser.h:241
bool is_not_inside_transaction()
State if the transaction boundary parser is not inside a transaction.
Definition: trx_boundary_parser.h:112
enum_event_parser_state last_parser_state
Last internal state of the event parser.
Definition: trx_boundary_parser.h:254
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:163
enum_event_boundary_type m_current_boundary_state
The last processed boundary event type.
Definition: trx_boundary_parser.h:259
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:182
@ EVENT_BOUNDARY_TYPE_END_TRX
Definition: trx_boundary_parser.h:190
@ EVENT_BOUNDARY_TYPE_ERROR
Definition: trx_boundary_parser.h:183
@ EVENT_BOUNDARY_TYPE_INCIDENT
Definition: trx_boundary_parser.h:201
@ EVENT_BOUNDARY_TYPE_STATEMENT
Definition: trx_boundary_parser.h:199
@ EVENT_BOUNDARY_TYPE_TRANSACTION_PAYLOAD
Definition: trx_boundary_parser.h:210
@ EVENT_BOUNDARY_TYPE_IGNORE
Definition: trx_boundary_parser.h:206
@ EVENT_BOUNDARY_TYPE_GTID
Definition: trx_boundary_parser.h:185
@ EVENT_BOUNDARY_TYPE_PRE_STATEMENT
Definition: trx_boundary_parser.h:194
@ EVENT_BOUNDARY_TYPE_BEGIN_TRX
Definition: trx_boundary_parser.h:187
@ EVENT_BOUNDARY_TYPE_END_XA_TRX
Definition: trx_boundary_parser.h:192
enum_event_parser_error
Internal error indentifiers for parser issues.
Definition: trx_boundary_parser.h:168
@ ER_TRX_BOUND_UNEXPECTED_COMMIT_ROLLBACK_OR_XID_LOG_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:176
@ ER_TRX_BOUND_GTID_LOG_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:172
@ ER_TRX_BOUND_UNEXPECTED_BEGIN_IN_STREAM
Definition: trx_boundary_parser.h:174
@ ER_TRX_BOUND_UNEXPECTED_XA_ROLLBACK_IN_STREAM
Definition: trx_boundary_parser.h:178
@ ER_TRX_BOUND_UNSUPPORTED_UNIGNORABLE_EVENT_IN_STREAM
Definition: trx_boundary_parser.h:170
enum_trx_boundary_parser_context m_trx_boundary_parser_context
In which context of the boundary parser is used.
Definition: trx_boundary_parser.h:264
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:123
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:247
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
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:36
Struct to pass basic information about a event: type, query, is it ignorable.
Definition: binlog_event.h:407