/* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** @addtogroup Replication @{ @file load_data_events.h @brief LOAD DATA INFILE is not written to the binary log like other statements. It is written as one or more events in a packed format, not as a cleartext statement in the binary log. The events indicate what options are present in the statement and how to process the data file. */ #ifndef LOAD_DATA_EVENTS_INCLUDED #define LOAD_DATA_EVENTS_INCLUDED #include "statement_events.h" #include "table_id.h" /* These are flags and structs to handle all the LOAD DATA INFILE options (LINES TERMINATED etc). DUMPFILE_FLAG is probably not used (DUMPFILE is a clause of SELECT, not of LOAD DATA). */ #define DUMPFILE_FLAG 0x1 #define OPT_ENCLOSED_FLAG 0x2 #define REPLACE_FLAG 0x4 #define IGNORE_FLAG 0x8 #define FIELD_TERM_EMPTY 0x1 #define ENCLOSED_EMPTY 0x2 #define LINE_TERM_EMPTY 0x4 #define LINE_START_EMPTY 0x8 #define ESCAPED_EMPTY 0x10 namespace binary_log { /** @struct old_sql_ex This structure holds the single character field/line options in the LOAD_DATA_INFILE statement. It is used for server versions prior to 5.0.3, where a single character separator was supported for LOAD_DATA_INFILE statements. The structure contains the foloowing components.
| Name | Format | Description |
|---|---|---|
| field_term | a single character | field terminating character spcified by the subclause 'FIELDS TERMINATED BY' |
| enclosed | a single character | character used for enclosing field data, specified by the subclause 'FIELDS ENCLOSED BY' |
| line_term | a single character | line terminating character, specified by the subclause 'LINES TERMINATED BY' |
| line_start | a single character | character indicating the start of a line, specified by the subclause 'LINES STARTING BY' |
| escaped | a single character | escape character for a field, specified by the subclause 'FIELD ESCAPED BY' |
| opt_flags | 8 bit bitfield value | bitfield indicating the presence of the keywords REPLACE, IGNORE, and OPTIONALLY |
| empty_flags | 8 bit bitfield value | The low 5 bits of empty_flags indicate which of the five strings have length 0. For each of the following flags that is set, the corresponding string has length 0; for the flags that are not set, the string has length 1: FIELD_TERM_EMPTY==0x1, ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4, LINE_START_EMPTY==0x8, ESCAPED_EMPTY==0x10. |
| Name | Format | Description |
|---|---|---|
| file_id | 4 byte unsigned integer | ID of the temporary file to load |
| fn_pos_start | 4 byte unsigned integer | The start position within the statement for filename substitution |
| fn_pos_end | 4 byte unsigned integer | The end position within the statement for filename substitution |
| dup_handling | enum_load_dup_handling | Represents information on how to handle duplicates: LOAD_DUP_ERROR= 0, LOAD_DUP_IGNORE= 1, LOAD_DUP_REPLACE= 2 |
| Name | Format | Description |
|---|---|---|
| slave_proxy_id | 4 byte unsigned integer | An integer identifying the client thread that issued the query. The id is unique per server. (Note, however, that two threads on different servers may have the same slave_proxy_id.) This is used when a client thread creates a temporary table local to the client. The slave_proxy_id is used to distinguish temporary tables that belong to different clients. |
| load_exec_time | 4 byte unsigned integer | The time from when the query started to when it was logged in the binlog, in seconds. |
| skip_lines | 4 byte unsigned integer | The number on line (14) above, if present, or 0 if line (14) is left out. |
| table_name_len | 1 byte unsigned integer | The length of 'table_name' on line (4) above. |
| db_len | 1 byte unsigned integer | The length of 'db' on line (1) above. |
| num_fields | 4 byte unsigned integer | The number n of fields on line (15) above. |
| Name | Format | Description |
|---|---|---|
| sql_ex | variable length | Describes the part of the query on lines (3) and
(5)–(13) above. More precisely, it stores the five strings
(on lines) field_term (6), enclosed (7), escaped (8), line_term
(11), and line_start (12); as well as a bitfield indicating the
presence of the keywords REPLACE (3), IGNORE (3), and OPTIONALLY
(7).
The data is stored in one of two formats, called "old" and "new".
The type field of Common-Header determines which of these two
formats is used: type LOAD_EVENT means that the old format is
used, and type NEW_LOAD_EVENT means that the new format is used.
When MySQL writes a Load_event, it uses the new format if at
least one of the five strings is two or more bytes long.
Otherwise (i.e., if all strings are 0 or 1 bytes long), the old
format is used.
The new and old format differ in the way the five strings are
stored.
|
| field_lens | num_fields 1 byte unsigned integers | An array of num_fields integers representing the length of each field in the query. (num_fields is from the Post-Header). |
| fields | num_fields null-terminated strings | An array of num_fields null-terminated strings, each representing a field in the query. (The trailing zero is redundant, since the length are stored in the num_fields array.) The total length of all strings equals to the sum of all field_lens, plus num_fields bytes for all the trailing zeros. |
| table_name | null-terminated string of length table_len + 1 bytes | The 'table_name' from the query, as a null-terminated string. (The trailing zero is actually redundant since the table_len is known from Post-Header.) |
| db | null-terminated string of length db_len + 1 bytes | The 'db' from the query, as a null-terminated string. (The trailing zero is actually redundant since the db_len is known from Post-Header.) |
| fname | variable length string without trailing zero, extending to the end of the event (determined by the length field of the Common-Header) | The 'file_name' from the query. |
The fixed event data part buffer layout is as follows:
+--------------------------------------------------------------------------------+
| thread_id | load_exec_time | skip_lines | table_name_len | db_len | num_fields |
+--------------------------------------------------------------------------------+
Variable data part
+---------------------------------------------------------------------+
| sql_ex_data struct | len of col names to load | col_names | tb_name |
+-------------------------------------------------------------- ------+
+----------------+
|db_name | fname |
+----------------+
@param buf Contains the serialized event.
@param length Length of the serialized event.
@param description_event An FDE event, used to get the
following information
-binlog_version
-server_version
-post_header_len
-common_header_len
The content of this object
depends on the binlog-version currently in use.
*/
Load_event(const char* buf, unsigned int event_len,
const Format_description_event* description_event);
~Load_event()
{
}
size_t get_data_size()
{
return (table_name_len + db_len + 2 + fname_len
+ static_cast| Name | Format | Description |
|---|---|---|
| file_id | 32 bit integer | The ID of the temporary file created by the slave to which the first data block is copied |
+-------------------------------------------------------------------+
| name_len | name | is_null | type | charset_number | val_len | val |
+-------------------------------------------------------------------+
@param buf Contains the serialized event.
@param length Length of the serialized event.
@param description_event An FDE event, used to get the
following information
-binlog_version
-server_version
-post_header_len
-common_header_len
The content of this object
depends on the binlog-version currently in use.
*/
Create_file_event(const char* buf, unsigned int event_len,
const Format_description_event* description_event);
~Create_file_event()
{
bapi_free(const_cast| Name | Format | Description |
|---|---|---|
| file_id | 32 bit integer | The ID of the file to be deleted |
+---------+
| file_id |
+---------+
@param buf Contains the serialized event.
@param length Length of the serialized event.
@param description_event An FDE event, used to get the
following information
-binlog_version
-server_version
-post_header_len
-common_header_len
The content of this object
depends on the binlog-version currently in use.
*/
Delete_file_event(const char* buf, unsigned int event_len,
const Format_description_event* description_event);
~Delete_file_event() {}
#ifndef HAVE_MYSYS
//TODO(WL#7684): Implement the method print_event_info and print_long_info for
// all the events supported in MySQL Binlog
void print_event_info(std::ostream& info) {};
void print_long_info(std::ostream& info) {};
#endif
};
/**
@class Execute_load_event
Execute_load_event is created when the LOAD_DATA query succeeds on
the master. The slave should be notified to load the temporary file into
the table. For server versions > 5.0.3, the temporary files that stores
the parameters to LOAD DATA INFILE is not needed anymore, since they are
stored in this event. There is still a temp file containing all the data
to be loaded.
@section Execute_load_event_binary_format Binary Format
The variable data part is empty. The post header contains the following:
| Name | Format | Description |
|---|---|---|
| file_id | 32 bit integer | The ID of the file to load |
| Name | Format | Description |
|---|---|---|
| file_id | 32 bit integer | The ID of the file to append the block to |
+---------+
| file_id |
+---------+
The buffer layout for variabl data part is as follows:
+-------------------+
| block | block_len |
+-------------------+
@param buf Contains the serialized event.
@param length Length of the serialized event.
@param description_event An FDE event, used to get the
following information
-binlog_version
-server_version
-post_header_len
-common_header_len
The content of this object
depends on the binlog-version currently in use.
*/
Append_block_event(const char* buf, unsigned int event_len,
const Format_description_event *description_event);
~Append_block_event() {}
#ifndef HAVE_MYSYS
//TODO(WL#7684): Implement the method print_event_info and print_long_info for
// all the events supported in MySQL Binlog
void print_event_info(std::ostream& info) {};
void print_long_info(std::ostream& info) {};
#endif
};
/**
@class Begin_load_query_event
Event for the first block of file to be loaded, its only difference from
Append_block event is that this event creates or truncates existing file
before writing data.
@section Begin_load_query_event_binary_format Binary Format
The Post-Header and Body for this event type are empty; it only has
the Common-Header.
*/
class Begin_load_query_event: public virtual Append_block_event
{
protected:
Begin_load_query_event()
: Append_block_event(BEGIN_LOAD_QUERY_EVENT)
{}
public:
/**
The buffer layout for fixed data part is as follows:
+---------+
| file_id |
+---------+
The buffer layout for variabl data part is as follows:
+-------------------+
| block | block_len |
+-------------------+
@param buf Contains the serialized event.
@param length Length of the serialized event.
@param description_event An FDE event, used to get the
following information
-binlog_version
-server_version
-post_header_len
-common_header_len
The content of this object
depends on the binlog-version currently in use.
*/
Begin_load_query_event(const char* buf, unsigned int event_len,
const Format_description_event *description_event);
~Begin_load_query_event() {}
#ifndef HAVE_MYSYS
//TODO(WL#7684): Implement the method print_event_info and print_long_info for
// all the events supported in MySQL Binlog
void print_event_info(std::ostream& info) {};
void print_long_info(std::ostream& info) {};
#endif
};
} // end namespace binary_log
/**
@} (end of group Replication)
*/
#endif /* LOAD_DATA_EVENTS_INCLUDED */