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