MySQL 9.1.0
Source Code Documentation
load_data_events.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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 LOAD DATA INFILE is not written to the binary log like other
28 statements. It is written as one or more events in a packed format,
29 not as a cleartext statement in the binary log. The events indicate
30 what options are present in the statement and how to process the data file.
31*/
32
33#ifndef MYSQL_BINLOG_EVENT_LOAD_DATA_EVENTS_H
34#define MYSQL_BINLOG_EVENT_LOAD_DATA_EVENTS_H
35
36#include <sys/types.h>
39
40/// @addtogroup GroupLibsMysqlBinlogEvent
41/// @{
42
43/*
44 These are flags and structs to handle all the LOAD DATA INFILE options (LINES
45 TERMINATED etc).
46 DUMPFILE_FLAG is probably not used (DUMPFILE is a clause of SELECT,
47 not of LOAD DATA).
48*/
49#define DUMPFILE_FLAG 0x1
50#define OPT_ENCLOSED_FLAG 0x2
51#define REPLACE_FLAG 0x4
52#define IGNORE_FLAG 0x8
53
54#define FIELD_TERM_EMPTY 0x1
55#define ENCLOSED_EMPTY 0x2
56#define LINE_TERM_EMPTY 0x4
57#define LINE_START_EMPTY 0x8
58#define ESCAPED_EMPTY 0x10
59
60namespace mysql::binlog::event {
61/**
62 Elements of this enum describe how LOAD DATA handles duplicates.
63*/
68};
69
70/**
71 @class Execute_load_query_event
72
73 Event responsible for LOAD DATA execution, it similar to Query_event
74 but before executing the query it substitutes original filename in LOAD DATA
75 query with name of temporary file.
76
77 The first 13 bytes of the Post-Header for this event are the same as for
78 Query_event, as is the initial status variable block in the Body.
79
80 @section Execute_load_query_event_binary_format Binary Format
81
82 The additional members of the events are the following:
83
84 <table>
85 <caption>Body for Execute_load_query_event</caption>
86
87 <tr>
88 <th>Name</th>
89 <th>Format</th>
90 <th>Description</th>
91 </tr>
92
93 <tr>
94 <td>file_id</td>
95 <td>4 byte unsigned integer</td>
96 <td>ID of the temporary file to load</td>
97 </tr>
98
99 <tr>
100 <td>fn_pos_start</td>
101 <td>4 byte unsigned integer</td>
102 <td>The start position within the statement for filename substitution</td>
103 </tr>
104 <tr>
105
106 <td>fn_pos_end</td>
107 <td>4 byte unsigned integer</td>
108 <td>The end position within the statement for filename substitution</td>
109 </tr>
110
111 <tr>
112 <td>dup_handling</td>
113 <td>enum_load_dup_handling</td>
114 <td>Represents information on how to handle duplicates:
115 LOAD_DUP_ERROR= 0, LOAD_DUP_IGNORE= 1, LOAD_DUP_REPLACE= 2</td>
116 </tr>
117 </table>
118*/
119class Execute_load_query_event : public virtual Query_event {
120 public:
122 /** ELQ = "Execute Load Query" */
127 };
128
129 int32_t file_id; /** file_id of temporary file */
130 uint32_t fn_pos_start; /** pointer to the part of the query that should
131 be substituted */
132 uint32_t fn_pos_end; /** pointer to the end of this part of query */
133
134 /**
135 We have to store type of duplicate handling explicitly, because
136 for LOAD DATA it also depends on LOCAL option. And this part
137 of query will be rewritten during replication so this information
138 may be lost...
139 */
141
142 Execute_load_query_event(uint32_t file_id_arg, uint32_t fn_pos_start,
143 uint32_t fn_pos_end, enum_load_dup_handling dup);
144
145 /**
146 The constructor receives a buffer and instantiates a
147 Execute_load_query_event filled in with the data from the buffer.
148
149 <pre>
150 The fixed event data part buffer layout is as follows:
151 +---------------------------------------------------------------------+
152 | thread_id | query_exec_time | db_len | error_code | status_vars_len |
153 +---------------------------------------------------------------------+
154 +----------------------------------------------------+
155 | file_id | fn_pos_start | fn_pos_end | dup_handling |
156 +----------------------------------------------------+
157 </pre>
158
159 <pre>
160 The fixed event data part buffer layout is as follows:
161 +------------------------------------------------------------------+
162 | Zero or more status variables | db | LOAD DATA INFILE statement |
163 +------------------------------------------------------------------+
164 </pre>
165
166 @param buf Contains the serialized event.
167 @param fde An FDE event (see Rotate_event constructor for more info).
168 */
169 Execute_load_query_event(const char *buf,
170 const Format_description_event *fde);
171
172 ~Execute_load_query_event() override = default;
173};
174
175/**
176 @class Delete_file_event
177
178 DELETE_FILE_EVENT occurs when the LOAD DATA failed on the master.
179 This event notifies the slave not to do the load and to delete
180 the temporary file.
181
182 @section Delete_file_event_binary_format Binary Format
183
184 The variable data part is empty. The post header contains the following:
185
186 <table>
187 <caption>Post header for Delete_file_event</caption>
188
189 <tr>
190 <th>Name</th>
191 <th>Format</th>
192 <th>Description</th>
193 </tr>
194
195 <tr>
196 <td>file_id</td>
197 <td>32 bit integer</td>
198 <td>The ID of the file to be deleted</td>
199 </tr>
200 </table>
201*/
203 protected:
204 // Required by Delete_file_log_event(THD* ..)
205 Delete_file_event(uint32_t file_id_arg, const char *db_arg)
206 : Binary_log_event(DELETE_FILE_EVENT), file_id(file_id_arg), db(db_arg) {}
207
208 public:
210 /** DF = "Delete File" */
212 };
213
214 uint32_t file_id;
215 const char *db; /** see comment in Append_block_event */
216
217 /**
218 The buffer layout for fixed data part is as follows:
219 <pre>
220 +---------+
221 | file_id |
222 +---------+
223 </pre>
224
225 @param buf Contains the serialized event.
226 @param fde An FDE event (see Rotate_event constructor for more info).
227 */
228 Delete_file_event(const char *buf, const Format_description_event *fde);
229
230 ~Delete_file_event() override = default;
231
232#ifndef HAVE_MYSYS
233 // TODO(WL#7684): Implement the method print_event_info and print_long_info
234 // for
235 // all the events supported in MySQL Binlog
236 void print_event_info(std::ostream &) override {}
237 void print_long_info(std::ostream &) override {}
238#endif
239};
240
241/**
242 @class Append_block_event
243
244 This event is created to contain the file data. One LOAD_DATA_INFILE
245 can have 0 or more instances of this event written to the binary log
246 depending on the size of the file. If the file to be loaded is greater
247 than the threshold value, which is roughly 2^17 bytes, the file is
248 divided into blocks of size equal to the threshold, and each block
249 is sent across as a separate event.
250
251 @section Append_block_event_binary_format Binary Format
252
253 The post header contains the following:
254
255 <table>
256 <caption>Post header for Append_block_event</caption>
257
258 <tr>
259 <th>Name</th>
260 <th>Format</th>
261 <th>Description</th>
262 </tr>
263
264 <tr>
265 <td>file_id</td>
266 <td>32 bit integer</td>
267 <td>The ID of the file to append the block to</td>
268 </tr>
269 </table>
270
271 The body of the event contains the raw data to load. The raw data
272 size is the event size minus the size of all the fixed event parts.
273*/
275 protected:
276 /**
277 This constructor is used by the MySQL server.
278 */
279 Append_block_event(const char *db_arg, unsigned char *block_arg,
280 unsigned int block_len_arg, uint32_t file_id_arg)
282 block(block_arg),
283 block_len(block_len_arg),
284 file_id(file_id_arg),
285 db(db_arg) {}
286
288 : Binary_log_event(type_arg) {}
289
290 public:
292 /** AB = "Append Block" */
295 };
296
297 unsigned char *block;
298 unsigned int block_len;
299 uint32_t file_id;
300 /**
301 'db' is filled when the event is created in mysql_load() (the
302 event needs to have a 'db' member to be well filtered by
303 binlog-*-db rules). 'db' is not written to the binlog (it's not
304 used by Append_block_log_event::write()), so it can't be read in
305 the Append_block_event(const char* buf, int event_len)
306 constructor. In other words, 'db' is used only for filtering by
307 binlog-*-db rules. Create_file_event is different: it's 'db'
308 (which is inherited from Load_event) is written to the binlog
309 and can be re-read.
310 */
311 const char *db;
312
313 /**
314 Appends the buffered data, received as a parameter, to the file being loaded
315 via LOAD_DATA_FILE.
316
317 The buffer layout for fixed data part is as follows:
318 <pre>
319 +---------+
320 | file_id |
321 +---------+
322 </pre>
323
324 The buffer layout for variable data part is as follows:
325 <pre>
326 +-------------------+
327 | block | block_len |
328 +-------------------+
329 </pre>
330
331 @param buf Contains the serialized event.
332 @param fde An FDE event (see Rotate_event constructor for more info).
333 */
334 Append_block_event(const char *buf, const Format_description_event *fde);
335 ~Append_block_event() override = default;
336
337#ifndef HAVE_MYSYS
338 // TODO(WL#7684): Implement the method print_event_info and print_long_info
339 // for
340 // all the events supported in MySQL Binlog
341 void print_event_info(std::ostream &) override {}
342 void print_long_info(std::ostream &) override {}
343#endif
344};
345
346/**
347 @class Begin_load_query_event
348
349 Event for the first block of file to be loaded, its only difference from
350 Append_block event is that this event creates or truncates existing file
351 before writing data.
352
353 @section Begin_load_query_event_binary_format Binary Format
354
355 The Post-Header and Body for this event type are empty; it only has
356 the Common-Header.
357*/
359 protected:
361
362 public:
363 /**
364 The buffer layout for fixed data part is as follows:
365 <pre>
366 +---------+
367 | file_id |
368 +---------+
369 </pre>
370
371 The buffer layout for variable data part is as follows:
372 <pre>
373 +-------------------+
374 | block | block_len |
375 +-------------------+
376 </pre>
377
378 @param buf Contains the serialized event.
379 @param fde An FDE event (see Rotate_event constructor for more info).
380 */
381 Begin_load_query_event(const char *buf, const Format_description_event *fde);
382
383 ~Begin_load_query_event() override = default;
384
385#ifndef HAVE_MYSYS
386 // TODO(WL#7684): Implement the method print_event_info and print_long_info
387 // for
388 // all the events supported in MySQL Binlog
389 void print_event_info(std::ostream &) override {}
390 void print_long_info(std::ostream &) override {}
391#endif
392};
393} // end namespace mysql::binlog::event
394
395/// @}
396
397#endif // MYSQL_BINLOG_EVENT_LOAD_DATA_EVENTS_H
This event is created to contain the file data.
Definition: load_data_events.h:274
Append_block_offset
Definition: load_data_events.h:291
@ AB_DATA_OFFSET
Definition: load_data_events.h:294
@ AB_FILE_ID_OFFSET
AB = "Append Block".
Definition: load_data_events.h:293
uint32_t file_id
Definition: load_data_events.h:299
Append_block_event(const char *db_arg, unsigned char *block_arg, unsigned int block_len_arg, uint32_t file_id_arg)
This constructor is used by the MySQL server.
Definition: load_data_events.h:279
const char * db
'db' is filled when the event is created in mysql_load() (the event needs to have a 'db' member to be...
Definition: load_data_events.h:311
unsigned int block_len
Definition: load_data_events.h:298
unsigned char * block
Definition: load_data_events.h:297
Append_block_event(Log_event_type type_arg=APPEND_BLOCK_EVENT)
Definition: load_data_events.h:287
Event for the first block of file to be loaded, its only difference from Append_block event is that t...
Definition: load_data_events.h:358
Begin_load_query_event()
Definition: load_data_events.h:360
This is the abstract base class for binary log events.
Definition: binlog_event.h:851
@ QUERY_HEADER_LEN
Definition: binlog_event.h:868
@ APPEND_BLOCK_HEADER_LEN
Definition: binlog_event.h:874
DELETE_FILE_EVENT occurs when the LOAD DATA failed on the master.
Definition: load_data_events.h:202
uint32_t file_id
Definition: load_data_events.h:214
Delete_file_offset
Definition: load_data_events.h:209
@ DF_FILE_ID_OFFSET
DF = "Delete File".
Definition: load_data_events.h:211
const char * db
Definition: load_data_events.h:215
Delete_file_event(uint32_t file_id_arg, const char *db_arg)
Definition: load_data_events.h:205
Event responsible for LOAD DATA execution, it similar to Query_event but before executing the query i...
Definition: load_data_events.h:119
Execute_load_query_event(uint32_t file_id_arg, uint32_t fn_pos_start, uint32_t fn_pos_end, enum_load_dup_handling dup)
The constructor is called by MySQL slave, while applying the events.
Definition: load_data_events.cpp:31
uint32_t fn_pos_start
file_id of temporary file
Definition: load_data_events.h:130
uint32_t fn_pos_end
pointer to the part of the query that should be substituted
Definition: load_data_events.h:132
int32_t file_id
Definition: load_data_events.h:129
Execute_load_query_event_offset
Definition: load_data_events.h:121
@ ELQ_FN_POS_END_OFFSET
Definition: load_data_events.h:125
@ ELQ_FILE_ID_OFFSET
ELQ = "Execute Load Query".
Definition: load_data_events.h:123
@ ELQ_DUP_HANDLING_OFFSET
Definition: load_data_events.h:126
@ ELQ_FN_POS_START_OFFSET
Definition: load_data_events.h:124
enum_load_dup_handling dup_handling
pointer to the end of this part of query
Definition: load_data_events.h:140
For binlog version 4.
Definition: control_events.h:240
A Query_event is created for each query that modifies the database, unless the query is logged row-ba...
Definition: statement_events.h:451
Definition: buf0block_hint.cc:30
The namespace contains classes representing events that can occur in a replication stream.
Definition: binlog_event.cpp:38
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:278
@ BEGIN_LOAD_QUERY_EVENT
Definition: binlog_event.h:306
@ DELETE_FILE_EVENT
Definition: binlog_event.h:300
@ APPEND_BLOCK_EVENT
Definition: binlog_event.h:299
enum_load_dup_handling
Elements of this enum describe how LOAD DATA handles duplicates.
Definition: load_data_events.h:64
@ LOAD_DUP_IGNORE
Definition: load_data_events.h:66
@ LOAD_DUP_ERROR
Definition: load_data_events.h:65
@ LOAD_DUP_REPLACE
Definition: load_data_events.h:67
Contains the classes representing statement events occurring in the replication stream.
Contains the class Table_id, mainly used for row based replication.