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