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