1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
@addtogroup Replication
22
@brief Binary log event definitions. This includes generic code
23
common to all types of log events, as well as specific code for each
31
#if defined(USE_PRAGMA_INTERFACE) && !defined(MYSQL_CLIENT)
32
#pragma interface /* gcc class implementation */
35
#include <my_bitmap.h>
36
#include "rpl_constants.h"
38
#include "rpl_record.h"
39
#include "rpl_reporting.h"
43
Either assert or return an error.
45
In debug build, the condition will be checked, but in non-debug
46
builds, the error code given will be returned instead.
48
@param COND Condition to check
49
@param ERRNO Error number to return in non-debug builds
52
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
53
do { if (!(COND)) return ERRNO; } while (0)
55
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
59
#define LOG_READ_EOF -1
60
#define LOG_READ_BOGUS -2
61
#define LOG_READ_IO -3
62
#define LOG_READ_MEM -5
63
#define LOG_READ_TRUNC -6
64
#define LOG_READ_TOO_LARGE -7
66
#define LOG_EVENT_OFFSET 4
69
3 is MySQL 4.x; 4 is MySQL 5.0.0.
70
Compared to version 3, version 4 has:
71
- a different Start_log_event, which includes info about the binary log
72
(sizes of headers); this info is included for better compatibility if the
73
master's MySQL version is different from the slave's.
74
- all events have a unique ID (the triplet (server_id, timestamp at server
75
start, other) to be sure an event is not executed more than once in a
76
multimaster setup, example:
84
if a query is run on M1, it will arrive twice on S, so we need that S
85
remembers the last unique ID it has processed, to compare and know if the
86
event should be skipped or not. Example of ID: we already have the server id
88
timestamp_when_the_master_started (4 bytes), a counter (a sequence number
89
which increments every time we write an event to the binlog) (3 bytes).
90
Q: how do we handle when the counter is overflowed and restarts from 0 ?
92
- Query and Load (Create or Execute) events may have a more precise
93
timestamp (with microseconds), number of matched/affected/warnings rows
94
and fields of session variables: SQL_MODE,
95
FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and
96
charsets, the PASSWORD() version (old/new/...).
98
#define BINLOG_VERSION 4
101
We could have used SERVER_VERSION_LENGTH, but this introduces an
102
obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH
103
this would break the replication protocol
105
#define ST_SERVER_VER_LEN 50
108
These are flags and structs to handle all the LOAD DATA INFILE options (LINES
113
These are flags and structs to handle all the LOAD DATA INFILE options (LINES
115
DUMPFILE_FLAG is probably useless (DUMPFILE is a clause of SELECT, not of LOAD
118
#define DUMPFILE_FLAG 0x1
119
#define OPT_ENCLOSED_FLAG 0x2
120
#define REPLACE_FLAG 0x4
121
#define IGNORE_FLAG 0x8
123
#define FIELD_TERM_EMPTY 0x1
124
#define ENCLOSED_EMPTY 0x2
125
#define LINE_TERM_EMPTY 0x4
126
#define LINE_START_EMPTY 0x8
127
#define ESCAPED_EMPTY 0x10
129
/*****************************************************************************
133
****************************************************************************/
145
#define NUM_LOAD_DELIM_STRS 5
147
/*****************************************************************************
151
****************************************************************************/
154
sql_ex_info() {} /* Remove gcc warning */
155
const char* field_term;
156
const char* enclosed;
157
const char* line_term;
158
const char* line_start;
160
int cached_new_format;
161
uint8 field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
165
// store in new format even if old is possible
166
void force_new_format() { cached_new_format = 1;}
169
return (new_format() ?
170
field_term_len + enclosed_len + line_term_len +
171
line_start_len + escaped_len + 6 : 7);
173
bool write_data(IO_CACHE* file);
174
const char* init(const char* buf, const char* buf_end, bool use_new_format);
177
return ((cached_new_format != -1) ? cached_new_format :
178
(cached_new_format=(field_term_len > 1 ||
180
line_term_len > 1 || line_start_len > 1 ||
185
/*****************************************************************************
189
This log consists of events. Each event has a fixed-length header,
190
possibly followed by a variable length data body.
192
The data body consists of an optional fixed length segment (post-header)
193
and an optional variable length segment.
195
See the #defines below for the format specifics.
197
The events which really update data are Query_log_event,
198
Execute_load_query_log_event and old Load_log_event and
199
Execute_load_log_event events (Execute_load_query is used together with
200
Begin_load_query and Append_block events to replicate LOAD DATA INFILE.
201
Create_file/Append_block/Execute_load (which includes Load_log_event)
202
were used to replicate LOAD DATA before the 5.0.3).
204
****************************************************************************/
206
#define LOG_EVENT_HEADER_LEN 19 /* the fixed header length */
207
#define OLD_HEADER_LEN 13 /* the fixed header length in 3.23 */
209
Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
210
header (it will for sure when we have the unique event's ID), but at least
211
the first 19 bytes are the same in 4.x and 5.0. So when we have the unique
212
event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
213
LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
215
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
217
/* event-specific post-header sizes */
218
// where 3.23, 4.x and 5.0 agree
219
#define QUERY_HEADER_MINIMAL_LEN (4 + 4 + 1 + 2)
220
// where 5.0 differs: 2 for len of N-bytes vars.
221
#define QUERY_HEADER_LEN (QUERY_HEADER_MINIMAL_LEN + 2)
222
#define LOAD_HEADER_LEN (4 + 4 + 4 + 1 +1 + 4)
223
#define START_V3_HEADER_LEN (2 + ST_SERVER_VER_LEN + 4)
224
#define ROTATE_HEADER_LEN 8 // this is FROZEN (the Rotate post-header is frozen)
225
#define CREATE_FILE_HEADER_LEN 4
226
#define APPEND_BLOCK_HEADER_LEN 4
227
#define EXEC_LOAD_HEADER_LEN 4
228
#define DELETE_FILE_HEADER_LEN 4
229
#define FORMAT_DESCRIPTION_HEADER_LEN (START_V3_HEADER_LEN+1+LOG_EVENT_TYPES)
230
#define ROWS_HEADER_LEN 8
231
#define TABLE_MAP_HEADER_LEN 8
232
#define EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN (4 + 4 + 4 + 1)
233
#define EXECUTE_LOAD_QUERY_HEADER_LEN (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN)
234
#define INCIDENT_HEADER_LEN 2
235
#define HEARTBEAT_HEADER_LEN 0
237
Max number of possible extra bytes in a replication event compared to a
238
packet (i.e. a query) sent from client to master;
239
First, an auxiliary log_event status vars estimation:
241
#define MAX_SIZE_LOG_EVENT_STATUS (4 /* flags2 */ + \
243
1 + 1 + 255 /* catalog */ + \
246
MAX_TIME_ZONE_NAME_LENGTH)
247
#define MAX_LOG_EVENT_HEADER ( /* in order of Query_log_event::write */ \
248
LOG_EVENT_HEADER_LEN + /* write_header */ \
249
QUERY_HEADER_LEN + /* write_data */ \
250
EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN + /*write_post_header_for_derived */ \
251
MAX_SIZE_LOG_EVENT_STATUS + /* status */ \
255
Event header offsets;
256
these point to places inside the fixed header.
259
#define EVENT_TYPE_OFFSET 4
260
#define SERVER_ID_OFFSET 5
261
#define EVENT_LEN_OFFSET 9
262
#define LOG_POS_OFFSET 13
263
#define FLAGS_OFFSET 17
265
/* start event post-header (for v3 and v4) */
267
#define ST_BINLOG_VER_OFFSET 0
268
#define ST_SERVER_VER_OFFSET 2
269
#define ST_CREATED_OFFSET (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
270
#define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
272
/* slave event post-header (this event is never written) */
274
#define SL_MASTER_PORT_OFFSET 8
275
#define SL_MASTER_POS_OFFSET 0
276
#define SL_MASTER_HOST_OFFSET 10
278
/* query event post-header */
280
#define Q_THREAD_ID_OFFSET 0
281
#define Q_EXEC_TIME_OFFSET 4
282
#define Q_DB_LEN_OFFSET 8
283
#define Q_ERR_CODE_OFFSET 9
284
#define Q_STATUS_VARS_LEN_OFFSET 11
285
#define Q_DATA_OFFSET QUERY_HEADER_LEN
286
/* these are codes, not offsets; not more than 256 values (1 byte). */
287
#define Q_FLAGS2_CODE 0
288
#define Q_SQL_MODE_CODE 1
290
Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
291
5.0.x where 0<=x<=3. We have to keep it to be able to replicate these
294
#define Q_CATALOG_CODE 2
295
#define Q_AUTO_INCREMENT 3
296
#define Q_CHARSET_CODE 4
297
#define Q_TIME_ZONE_CODE 5
299
Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
300
5.0.x where x>=4. Saves one byte in every Query_log_event in binlog,
301
compared to Q_CATALOG_CODE. The reason we didn't simply re-use
302
Q_CATALOG_CODE is that then a 5.0.3 slave of this 5.0.x (x>=4) master would
303
crash (segfault etc) because it would expect a 0 when there is none.
305
#define Q_CATALOG_NZ_CODE 6
307
#define Q_LC_TIME_NAMES_CODE 7
309
#define Q_CHARSET_DATABASE_CODE 8
310
/* Intvar event post-header */
312
#define I_TYPE_OFFSET 0
313
#define I_VAL_OFFSET 1
315
/* Rand event post-header */
317
#define RAND_SEED1_OFFSET 0
318
#define RAND_SEED2_OFFSET 8
320
/* User_var event post-header */
322
#define UV_VAL_LEN_SIZE 4
323
#define UV_VAL_IS_NULL 1
324
#define UV_VAL_TYPE_SIZE 1
325
#define UV_NAME_LEN_SIZE 4
326
#define UV_CHARSET_NUMBER_SIZE 4
328
/* Load event post-header */
330
#define L_THREAD_ID_OFFSET 0
331
#define L_EXEC_TIME_OFFSET 4
332
#define L_SKIP_LINES_OFFSET 8
333
#define L_TBL_LEN_OFFSET 12
334
#define L_DB_LEN_OFFSET 13
335
#define L_NUM_FIELDS_OFFSET 14
336
#define L_SQL_EX_OFFSET 18
337
#define L_DATA_OFFSET LOAD_HEADER_LEN
339
/* Rotate event post-header */
341
#define R_POS_OFFSET 0
342
#define R_IDENT_OFFSET 8
344
/* CF to DF handle LOAD DATA INFILE */
346
/* CF = "Create File" */
347
#define CF_FILE_ID_OFFSET 0
348
#define CF_DATA_OFFSET CREATE_FILE_HEADER_LEN
350
/* AB = "Append Block" */
351
#define AB_FILE_ID_OFFSET 0
352
#define AB_DATA_OFFSET APPEND_BLOCK_HEADER_LEN
354
/* EL = "Execute Load" */
355
#define EL_FILE_ID_OFFSET 0
357
/* DF = "Delete File" */
358
#define DF_FILE_ID_OFFSET 0
360
/* TM = "Table Map" */
361
#define TM_MAPID_OFFSET 0
362
#define TM_FLAGS_OFFSET 6
365
#define RW_MAPID_OFFSET 0
366
#define RW_FLAGS_OFFSET 6
368
/* ELQ = "Execute Load Query" */
369
#define ELQ_FILE_ID_OFFSET QUERY_HEADER_LEN
370
#define ELQ_FN_POS_START_OFFSET ELQ_FILE_ID_OFFSET + 4
371
#define ELQ_FN_POS_END_OFFSET ELQ_FILE_ID_OFFSET + 8
372
#define ELQ_DUP_HANDLING_OFFSET ELQ_FILE_ID_OFFSET + 12
374
/* 4 bytes which all binlogs should begin with */
375
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
378
The 2 flags below were useless :
379
- the first one was never set
380
- the second one was set in all Rotate events on the master, but not used for
382
So they are now removed and their place may later be reused for other
383
flags. Then one must remember that Rotate events in 4.x have
384
LOG_EVENT_FORCED_ROTATE_F set, so one should not rely on the value of the
385
replacing flag when reading a Rotate event.
386
I keep the defines here just to remember what they were.
389
#define LOG_EVENT_TIME_F 0x1
390
#define LOG_EVENT_FORCED_ROTATE_F 0x2
394
This flag only makes sense for Format_description_log_event. It is set
395
when the event is written, and *reset* when a binlog file is
396
closed (yes, it's the only case when MySQL modifies already written
397
part of binlog). Thus it is a reliable indicator that binlog was
398
closed correctly. (Stop_log_event is not enough, there's always a
399
small chance that mysqld crashes in the middle of insert and end of
400
the binlog would look like a Stop_log_event).
402
This flag is used to detect a restart after a crash, and to provide
403
"unbreakable" binlog. The problem is that on a crash storage engines
404
rollback automatically, while binlog does not. To solve this we use this
405
flag and automatically append ROLLBACK to every non-closed binlog (append
406
virtually, on reading, file itself is not changed). If this flag is found,
407
mysqlbinlog simply prints "ROLLBACK" Replication master does not abort on
408
binlog corruption, but takes it as EOF, and replication slave forces a
409
rollback in this case.
411
Note, that old binlogs does not have this flag set, so we get a
412
a backward-compatible behaviour.
415
#define LOG_EVENT_BINLOG_IN_USE_F 0x1
418
@def LOG_EVENT_THREAD_SPECIFIC_F
420
If the query depends on the thread (for example: TEMPORARY TABLE).
421
Currently this is used by mysqlbinlog to know it must print
422
SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
423
for every query but this would be slow).
425
#define LOG_EVENT_THREAD_SPECIFIC_F 0x4
428
@def LOG_EVENT_SUPPRESS_USE_F
430
Suppress the generation of 'USE' statements before the actual
431
statement. This flag should be set for any events that does not need
432
the current database set to function correctly. Most notable cases
433
are 'CREATE DATABASE' and 'DROP DATABASE'.
435
This flags should only be used in exceptional circumstances, since
436
it introduce a significant change in behaviour regarding the
437
replication logic together with the flags --binlog-do-db and
440
#define LOG_EVENT_SUPPRESS_USE_F 0x8
443
The table map version internal to the log should be increased after
444
the event has been written to the binary log.
446
#define LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F 0x10
449
@def OPTIONS_WRITTEN_TO_BIN_LOG
451
OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must
452
be written to the binlog. OPTIONS_WRITTEN_TO_BIN_LOG could be
453
written into the Format_description_log_event, so that if later we
454
don't want to replicate a variable we did replicate, or the
455
contrary, it's doable. But it should not be too hard to decide once
456
for all of what we replicate and what we don't, among the fixed 32
457
bits of thd->options.
459
I (Guilhem) have read through every option's usage, and it looks
460
like OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only
461
ones which alter how the query modifies the table. It's good to
462
replicate OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the
463
slave may insert data slower than the master, in InnoDB.
464
OPTION_BIG_SELECTS is not needed (the slave thread runs with
465
max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
466
either, as the manual says (because a too big in-memory temp table
467
is automatically written to disk).
469
#define OPTIONS_WRITTEN_TO_BIN_LOG \
470
(OPTION_AUTO_IS_NULL | OPTION_NO_FOREIGN_KEY_CHECKS | \
471
OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NOT_AUTOCOMMIT)
473
/* Shouldn't be defined before */
474
#define EXPECTED_OPTIONS \
475
((ULL(1) << 14) | (ULL(1) << 26) | (ULL(1) << 27) | (ULL(1) << 19))
477
#if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
478
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
480
#undef EXPECTED_OPTIONS /* You shouldn't use this one */
485
Enumeration type for the different types of log events.
490
Every time you update this enum (when you add a type), you have to
491
fix Format_description_log_event::Format_description_log_event().
501
CREATE_FILE_EVENT= 8,
502
APPEND_BLOCK_EVENT= 9,
504
DELETE_FILE_EVENT= 11,
506
NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer
507
sql_ex, allowing multibyte TERMINATED BY etc; both types share the
508
same class (Load_log_event)
513
FORMAT_DESCRIPTION_EVENT= 15,
515
BEGIN_LOAD_QUERY_EVENT= 17,
516
EXECUTE_LOAD_QUERY_EVENT= 18,
518
TABLE_MAP_EVENT = 19,
521
These event numbers were used for 5.1.0 to 5.1.15 and are
524
PRE_GA_WRITE_ROWS_EVENT = 20,
525
PRE_GA_UPDATE_ROWS_EVENT = 21,
526
PRE_GA_DELETE_ROWS_EVENT = 22,
529
These event numbers are used from 5.1.16 and forward
531
WRITE_ROWS_EVENT = 23,
532
UPDATE_ROWS_EVENT = 24,
533
DELETE_ROWS_EVENT = 25,
536
Something out of the ordinary happened on the master
541
Heartbeat event to be send by master at its idle time
542
to ensure master's online status to slave
544
HEARTBEAT_LOG_EVENT= 27,
547
Add new events here - right above this comment!
548
Existing events (except ENUM_END_EVENT) should never change their numbers
551
ENUM_END_EVENT /* end marker */
555
The number of types we handle in Format_description_log_event (UNKNOWN_EVENT
556
is not to be handled, it does not exist in binlogs, it does not have a
559
#define LOG_EVENT_TYPES (ENUM_END_EVENT-1)
563
INVALID_INT_EVENT = 0, LAST_INSERT_ID_EVENT = 1, INSERT_ID_EVENT = 2
573
class Format_description_log_event;
574
class Relay_log_info;
577
enum enum_base64_output_mode {
578
BASE64_OUTPUT_NEVER= 0,
579
BASE64_OUTPUT_AUTO= 1,
580
BASE64_OUTPUT_ALWAYS= 2,
581
BASE64_OUTPUT_UNSPEC= 3,
582
/* insert new output modes here */
583
BASE64_OUTPUT_MODE_COUNT
587
A structure for mysqlbinlog to know how to print events
589
This structure is passed to the event's print() methods,
591
There are two types of settings stored here:
592
1. Last db, flags2, sql_mode etc comes from the last printed event.
593
They are stored so that only the necessary USE and SET commands
595
2. Other information on how to print the events, e.g. short_form,
596
hexdump_from. These are not dependent on the last event.
598
typedef struct st_print_event_info
601
Settings for database, sql_mode etc that comes from the last event
602
that was printed. We cache these so that we don't have to print
603
them if they are unchanged.
605
// TODO: have the last catalog here ??
606
char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is
609
bool sql_mode_inited;
610
ulong sql_mode; /* must be same as THD.variables.sql_mode */
611
ulong auto_increment_increment, auto_increment_offset;
613
char charset[6]; // 3 variables, each of them storable in 2 bytes
614
char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
615
uint lc_time_names_number;
616
uint charset_database_number;
618
bool thread_id_printed;
620
st_print_event_info();
622
~st_print_event_info() {
623
close_cached_file(&head_cache);
624
close_cached_file(&body_cache);
626
bool init_ok() /* tells if construction was successful */
627
{ return my_b_inited(&head_cache) && my_b_inited(&body_cache); }
630
/* Settings on how to print the events */
632
enum_base64_output_mode base64_output_mode;
634
This is set whenever a Format_description_event is printed.
635
Later, when an event is printed in base64, this flag is tested: if
636
no Format_description_event has been seen, it is unsafe to print
637
the base64 event, so an error message is generated.
639
bool printed_fd_event;
640
my_off_t hexdump_from;
641
uint8 common_header_len;
645
These two caches are used by the row-based replication events to
646
collect the header information and the main body of the events
647
making up a statement.
655
the struct aggregates two paramenters that identify an event
656
uniquely in scope of communication of a particular master and slave couple.
657
I.e there can not be 2 events from the same staying connected master which
658
have the same coordinates.
660
Such identifier is not yet unique generally as the event originating master
661
is resetable. Also the crashed master can be replaced with some other.
663
struct event_coordinates
665
char * file_name; // binlog file name (directories stripped)
666
my_off_t pos; // event's position in the binlog file
672
This is the abstract base class for binary log events.
674
@section Log_event_binary_format Binary Format
676
Any @c Log_event saved on disk consists of the following three
683
The Common-Header, documented in the table @ref Table_common_header
684
"below", always has the same form and length within one version of
685
MySQL. Each event type specifies a format and length of the
686
Post-Header. The length of the Common-Header is the same for all
687
events of the same type. The Body may be of different format and
688
length even for different events of the same type. The binary
689
formats of Post-Header and Body are documented separately in each
690
subclass. The binary format of Common-Header is as follows.
693
<caption>Common-Header</caption>
703
<td>4 byte unsigned integer</td>
704
<td>The time when the query started, in seconds since 1970.
710
<td>1 byte enumeration</td>
711
<td>See enum #Log_event_type.</td>
716
<td>4 byte unsigned integer</td>
717
<td>Server ID of the server that created the event.</td>
722
<td>4 byte unsigned integer</td>
723
<td>The total size of this event, in bytes. In other words, this
724
is the sum of the sizes of Common-Header, Post-Header, and Body.
729
<td>master_position</td>
730
<td>4 byte unsigned integer</td>
731
<td>The position of the next event in the master binary log, in
732
bytes from the beginning of the file. In a binlog that is not a
733
relay log, this is just the position of the next event, in bytes
734
from the beginning of the file. In a relay log, this is
735
the position of the next event in the master's binlog.
741
<td>2 byte bitfield</td>
742
<td>See Log_event::flags.</td>
746
Summing up the numbers above, we see that the total size of the
747
common header is 19 bytes.
749
@subsection Log_event_format_of_atomic_primitives Format of Atomic Primitives
751
- All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers,
752
are stored in little endian, i.e., the least significant byte first,
753
unless otherwise specified.
755
@anchor packed_integer
756
- Some events use a special format for efficient representation of
757
unsigned integers, called Packed Integer. A Packed Integer has the
758
capacity of storing up to 8-byte integers, while small integers
759
still can use 1, 3, or 4 bytes. The value of the first byte
760
determines how to read the number, according to the following table:
763
<caption>Format of Packed Integer</caption>
772
<td>The first byte is the number (in the range 0-250), and no more
778
<td>Two more bytes are used. The number is in the range
784
<td>Three more bytes are used. The number is in the range
785
0xffff-0xffffff.</td>
790
<td>Eight more bytes are used. The number is in the range
791
0xffffff-0xffffffffffffffff.</td>
796
- Strings are stored in various formats. The format of each string
797
is documented separately.
803
Enumeration of what kinds of skipping (and non-skipping) that can
804
occur when the slave executes an event.
809
enum enum_skip_reason {
816
Skip event by ignoring it.
818
This means that the slave skip counter will not be changed.
823
Skip event and decrease skip counter.
830
The following type definition is to be used whenever data is placed
831
and manipulated in a common buffer. Use this typedef for buffers
832
that contain data containing binary and character data.
834
typedef unsigned char Byte;
837
The offset in the log where this event originally appeared (it is
838
preserved in relay logs, making SHOW SLAVE STATUS able to print
839
coordinates of the event in the master's binlog). Note: when a
840
transaction is written by the master to its binlog (wrapped in
841
BEGIN/COMMIT) the log_pos of all the queries it contains is the
842
one of the BEGIN (this way, when one does SHOW SLAVE STATUS it
843
sees the offset of the BEGIN, which is logical as rollback may
844
occur), except the COMMIT query which has its real offset.
848
A temp buffer for read_log_event; it is later analysed according to the
849
event's type, and its content is distributed in the event-specific fields.
853
Timestamp on the master(for debugging and replication of
854
NOW()/TIMESTAMP). It is important for queries and LOAD DATA
855
INFILE. This is set at the event's creation time, except for Query
856
and Load (et al.) events where this is set at the query's
857
execution time, which guarantees good replication (otherwise, we
858
could have a query and its event with different timestamps).
861
/* The number of seconds the query took to run on the master. */
863
/* Number of bytes written by write() function */
867
The master's server id (is preserved in the relay log; used to
868
prevent from infinite loops in circular replication).
873
Some 16 flags. See the definitions above for LOG_EVENT_TIME_F,
874
LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
875
LOG_EVENT_SUPPRESS_USE_F for notes.
882
A storage to cache the global system variable's value.
883
Handling of a separate event will be governed its member.
885
ulong slave_exec_mode;
891
Log_event(THD* thd_arg, uint16 flags_arg, bool cache_stmt);
893
read_log_event() functions read an event from a binlog or relay
894
log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
895
master (reads master's binlog), the slave IO thread (reads the
896
event sent by binlog_dump), the slave SQL thread (reads the event
897
from the relay log). If mutex is 0, the read will proceed without
898
mutex. We need the description_event to be able to parse the
899
event (to know the post-header's size); in fact in read_log_event
900
we detect the event's type, then call the specific event's
901
constructor and pass description_event as an argument.
903
static Log_event* read_log_event(IO_CACHE* file,
904
pthread_mutex_t* log_lock,
905
const Format_description_log_event
907
static int read_log_event(IO_CACHE* file, String* packet,
908
pthread_mutex_t* log_lock);
910
init_show_field_list() prepares the column names and types for the
911
output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
914
static void init_show_field_list(List<Item>* field_list);
915
#ifdef HAVE_REPLICATION
916
int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
919
pack_info() is used by SHOW BINLOG EVENTS; as print() it prepares and sends
920
a string to display to the user, so it resembles print().
923
virtual void pack_info(Protocol *protocol);
925
#endif /* HAVE_REPLICATION */
926
virtual const char* get_db()
928
return thd ? thd->db : 0;
931
Log_event() : temp_buf(0) {}
932
/* avoid having to link mysqlbinlog against libpthread */
933
static Log_event* read_log_event(IO_CACHE* file,
934
const Format_description_log_event
936
/* print*() functions are used by mysqlbinlog */
937
virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
938
void print_timestamp(IO_CACHE* file, time_t *ts = 0);
939
void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
941
void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
945
static void *operator new(size_t size)
947
return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE));
950
static void operator delete(void *ptr, size_t size)
952
my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
955
/* Placement version of the above operators */
956
static void *operator new(size_t, void* ptr) { return ptr; }
957
static void operator delete(void*, void*) { }
960
bool write_header(IO_CACHE* file, ulong data_length);
961
virtual bool write(IO_CACHE* file)
963
return (write_header(file, get_data_size()) ||
964
write_data_header(file) ||
965
write_data_body(file));
967
virtual bool write_data_header(IO_CACHE* file)
969
virtual bool write_data_body(IO_CACHE* file __attribute__((unused)))
971
inline time_t get_time()
977
return thd->start_time;
978
if ((tmp_thd= current_thd))
979
return tmp_thd->start_time;
983
virtual Log_event_type get_type_code() = 0;
984
virtual bool is_valid() const = 0;
985
virtual bool is_artificial_event() { return 0; }
986
inline bool get_cache_stmt() const { return cache_stmt; }
987
Log_event(const char* buf, const Format_description_log_event
989
virtual ~Log_event() { free_temp_buf();}
990
void register_temp_buf(char* buf) { temp_buf = buf; }
995
my_free(temp_buf, MYF(0));
1000
Get event length for simple events. For complicated events the length
1001
is calculated during write()
1003
virtual int get_data_size() { return 0;}
1004
static Log_event* read_log_event(const char* buf, uint event_len,
1006
const Format_description_log_event
1007
*description_event);
1009
Returns the human readable name of the given event type.
1011
static const char* get_type_str(Log_event_type type);
1013
Returns the human readable name of this event's type.
1015
const char* get_type_str();
1017
/* Return start of query time or current time */
1019
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1023
Apply the event to the database.
1025
This function represents the public interface for applying an
1030
int apply_event(Relay_log_info const *rli)
1032
return do_apply_event(rli);
1037
Update the relay log position.
1039
This function represents the public interface for "stepping over"
1040
the event and will update the relay log information.
1044
int update_pos(Relay_log_info *rli)
1046
return do_update_pos(rli);
1050
Decide if the event shall be skipped, and the reason for skipping
1055
enum_skip_reason shall_skip(Relay_log_info *rli)
1057
return do_shall_skip(rli);
1063
Helper function to ignore an event w.r.t. the slave skip counter.
1065
This function can be used inside do_shall_skip() for functions
1066
that cannot end a group. If the slave skip counter is 1 when
1067
seeing such an event, the event shall be ignored, the counter
1068
left intact, and processing continue with the next event.
1072
enum_skip_reason do_shall_skip(Relay_log_info *rli) {
1073
return continue_group(rli);
1079
enum_skip_reason continue_group(Relay_log_info *rli);
1082
Primitive to apply an event to the database.
1084
This is where the change to the database is made.
1086
@note The primitive is protected instead of private, since there
1087
is a hierarchy of actions to be performed in some cases.
1089
@see Format_description_log_event::do_apply_event()
1091
@param rli Pointer to relay log info structure
1093
@retval 0 Event applied successfully
1094
@retval errno Error code if event application failed
1096
virtual int do_apply_event(Relay_log_info const *rli)
1098
return 0; /* Default implementation does nothing */
1103
Advance relay log coordinates.
1105
This function is called to advance the relay log coordinates to
1106
just after the event. It is essential that both the relay log
1107
coordinate and the group log position is updated correctly, since
1108
this function is used also for skipping events.
1110
Normally, each implementation of do_update_pos() shall:
1112
- Update the event position to refer to the position just after
1115
- Update the group log position to refer to the position just
1116
after the event <em>if the event is last in a group</em>
1118
@param rli Pointer to relay log info structure
1120
@retval 0 Coordinates changed successfully
1121
@retval errno Error code if advancing failed (usually just
1122
1). Observe that handler errors are returned by the
1123
do_apply_event() function, and not by this one.
1125
virtual int do_update_pos(Relay_log_info *rli);
1129
Decide if this event shall be skipped or not and the reason for
1132
The default implementation decide that the event shall be skipped
1135
- the server id of the event is the same as the server id of the
1136
server and <code>rli->replicate_same_server_id</code> is true,
1139
- if <code>rli->slave_skip_counter</code> is greater than zero.
1144
@retval Log_event::EVENT_SKIP_NOT
1145
The event shall not be skipped and should be applied.
1147
@retval Log_event::EVENT_SKIP_IGNORE
1148
The event shall be skipped by just ignoring it, i.e., the slave
1149
skip counter shall not be changed. This happends if, for example,
1150
the originating server id of the event is the same as the server
1153
@retval Log_event::EVENT_SKIP_COUNT
1154
The event shall be skipped because the slave skip counter was
1155
non-zero. The caller shall decrease the counter by one.
1157
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1163
One class for each type of event.
1164
Two constructors for each class:
1165
- one to create the event for logging (when the server acts as a master),
1166
called after an update to the database is done,
1167
which accepts parameters like the query, the database, the options for LOAD
1169
- one to create the event from a packet (when the server acts as a slave),
1170
called before reproducing the update, which accepts parameters (like a
1171
buffer). Used to read from the master, from the relay log, and in
1172
mysqlbinlog. This constructor must be format-tolerant.
1176
@class Query_log_event
1178
A @c Query_log_event is created for each query that modifies the
1179
database, unless the query is logged row-based.
1181
@section Query_log_event_binary_format Binary format
1183
See @ref Log_event_binary_format "Binary format for log events" for
1184
a general discussion and introduction to the binary format of binlog
1187
The Post-Header has five components:
1190
<caption>Post-Header for Query_log_event</caption>
1195
<th>Description</th>
1199
<td>slave_proxy_id</td>
1200
<td>4 byte unsigned integer</td>
1201
<td>An integer identifying the client thread that issued the
1202
query. The id is unique per server. (Note, however, that two
1203
threads on different servers may have the same slave_proxy_id.)
1204
This is used when a client thread creates a temporary table local
1205
to the client. The slave_proxy_id is used to distinguish
1206
temporary tables that belong to different clients.
1212
<td>4 byte unsigned integer</td>
1213
<td>The time from when the query started to when it was logged in
1214
the binlog, in seconds.</td>
1219
<td>1 byte integer</td>
1220
<td>The length of the name of the currently selected database.</td>
1225
<td>2 byte unsigned integer</td>
1226
<td>Error code generated by the master. If the master fails, the
1227
slave will fail with the same error code, except for the error
1228
codes ER_DB_CREATE_EXISTS == 1007 and ER_DB_DROP_EXISTS == 1008.
1233
<td>status_vars_len</td>
1234
<td>2 byte unsigned integer</td>
1235
<td>The length of the status_vars block of the Body, in bytes. See
1236
@ref query_log_event_status_vars "below".
1241
The Body has the following components:
1244
<caption>Body for Query_log_event</caption>
1249
<th>Description</th>
1253
<td>@anchor query_log_event_status_vars status_vars</td>
1254
<td>status_vars_len bytes</td>
1255
<td>Zero or more status variables. Each status variable consists
1256
of one byte identifying the variable stored, followed by the value
1257
of the variable. The possible variables are listed separately in
1258
the table @ref Table_query_log_event_status_vars "below". MySQL
1259
always writes events in the order defined below; however, it is
1260
capable of reading them in any order. </td>
1266
<td>The currently selected database, as a null-terminated string.
1268
(The trailing zero is redundant since the length is already known;
1269
it is db_len from Post-Header.)
1275
<td>variable length string without trailing zero, extending to the
1276
end of the event (determined by the length field of the
1279
<td>The SQL query.</td>
1283
The following table lists the status variables that may appear in
1284
the status_vars field.
1286
@anchor Table_query_log_event_status_vars
1288
<caption>Status variables for Query_log_event</caption>
1291
<th>Status variable</th>
1292
<th>1 byte identifier</th>
1294
<th>Description</th>
1299
<td>Q_FLAGS2_CODE == 0</td>
1300
<td>4 byte bitfield</td>
1301
<td>The flags in @c thd->options, binary AND-ed with @c
1302
OPTIONS_WRITTEN_TO_BIN_LOG. The @c thd->options bitfield contains
1303
options for "SELECT". @c OPTIONS_WRITTEN identifies those options
1304
that need to be written to the binlog (not all do). Specifically,
1305
@c OPTIONS_WRITTEN_TO_BIN_LOG equals (@c OPTION_AUTO_IS_NULL | @c
1306
OPTION_NO_FOREIGN_KEY_CHECKS | @c OPTION_RELAXED_UNIQUE_CHECKS |
1307
@c OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex.
1309
These flags correspond to the SQL variables SQL_AUTO_IS_NULL,
1310
FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and AUTOCOMMIT, documented in
1311
the "SET Syntax" section of the MySQL Manual.
1313
This field is always written to the binlog in version >= 5.0, and
1314
never written in version < 5.0.
1320
<td>Q_SQL_MODE_CODE == 1</td>
1321
<td>8 byte bitfield</td>
1322
<td>The @c sql_mode variable. See the section "SQL Modes" in the
1323
MySQL manual, and see mysql_priv.h for a list of the possible
1324
flags. Currently (2007-10-04), the following flags are available:
1326
MODE_REAL_AS_FLOAT==0x1
1327
MODE_PIPES_AS_CONCAT==0x2
1328
MODE_ANSI_QUOTES==0x4
1329
MODE_IGNORE_SPACE==0x8
1331
MODE_ONLY_FULL_GROUP_BY==0x20
1332
MODE_NO_UNSIGNED_SUBTRACTION==0x40
1333
MODE_NO_DIR_IN_CREATE==0x80
1334
MODE_POSTGRESQL==0x100
1339
MODE_NO_KEY_OPTIONS==0x2000
1340
MODE_NO_TABLE_OPTIONS==0x4000
1341
MODE_NO_FIELD_OPTIONS==0x8000
1342
MODE_MYSQL323==0x10000
1343
MODE_MYSQL323==0x20000
1344
MODE_MYSQL40==0x40000
1346
MODE_NO_AUTO_VALUE_ON_ZERO==0x100000
1347
MODE_NO_BACKSLASH_ESCAPES==0x200000
1348
MODE_STRICT_TRANS_TABLES==0x400000
1349
MODE_STRICT_ALL_TABLES==0x800000
1350
MODE_NO_ZERO_IN_DATE==0x1000000
1351
MODE_NO_ZERO_DATE==0x2000000
1352
MODE_INVALID_DATES==0x4000000
1353
MODE_ERROR_FOR_DIVISION_BY_ZERO==0x8000000
1354
MODE_TRADITIONAL==0x10000000
1355
MODE_NO_AUTO_CREATE_USER==0x20000000
1356
MODE_HIGH_NOT_PRECEDENCE==0x40000000
1357
MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000
1359
All these flags are replicated from the server. However, all
1360
flags except @c MODE_NO_DIR_IN_CREATE are honored by the slave;
1361
the slave always preserves its old value of @c
1362
MODE_NO_DIR_IN_CREATE. For a rationale, see comment in
1363
@c Query_log_event::do_apply_event in @c log_event.cc.
1365
This field is always written to the binlog.
1371
<td>Q_CATALOG_NZ_CODE == 6</td>
1372
<td>Variable-length string: the length in bytes (1 byte) followed
1373
by the characters (at most 255 bytes)
1375
<td>Stores the client's current catalog. Every database belongs
1376
to a catalog, the same way that every table belongs to a
1377
database. Currently, there is only one catalog, "std".
1379
This field is written if the length of the catalog is > 0;
1380
otherwise it is not written.
1385
<td>auto_increment</td>
1386
<td>Q_AUTO_INCREMENT == 3</td>
1387
<td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
1389
<td>The two variables auto_increment_increment and
1390
auto_increment_offset, in that order. For more information, see
1391
"System variables" in the MySQL manual.
1393
This field is written if auto_increment > 1. Otherwise, it is not
1400
<td>Q_CHARSET_CODE == 4</td>
1401
<td>three 2 byte unsigned integers, totally 2+2+2=6 bytes</td>
1402
<td>The three variables character_set_client,
1403
collation_connection, and collation_server, in that order.
1404
character_set_client is a code identifying the character set and
1405
collation used by the client to encode the query.
1406
collation_connection identifies the character set and collation
1407
that the master converts the query to when it receives it; this is
1408
useful when comparing literal strings. collation_server is the
1409
default character set and collation used when a new database is
1412
See also "Connection Character Sets and Collations" in the MySQL
1415
All three variables are codes identifying a (character set,
1416
collation) pair. To see which codes map to which pairs, run the
1417
query "SELECT id, character_set_name, collation_name FROM
1420
Cf. Q_CHARSET_DATABASE_CODE below.
1422
This field is always written.
1428
<td>Q_TIME_ZONE_CODE == 5</td>
1429
<td>Variable-length string: the length in bytes (1 byte) followed
1430
by the characters (at most 255 bytes).
1431
<td>The time_zone of the master.
1433
See also "System Variables" and "MySQL Server Time Zone Support"
1434
in the MySQL manual.
1436
This field is written if the length of the time zone string is >
1437
0; otherwise, it is not written.
1442
<td>lc_time_names_number</td>
1443
<td>Q_LC_TIME_NAMES_CODE == 7</td>
1444
<td>2 byte integer</td>
1445
<td>A code identifying a table of month and day names. The
1446
mapping from codes to languages is defined in @c sql_locale.cc.
1448
This field is written if it is not 0, i.e., if the locale is not
1454
<td>charset_database_number</td>
1455
<td>Q_CHARSET_DATABASE_CODE == 8</td>
1456
<td>2 byte integer</td>
1458
<td>The value of the collation_database system variable (in the
1459
source code stored in @c thd->variables.collation_database), which
1460
holds the code for a (character set, collation) pair as described
1461
above (see Q_CHARSET_CODE).
1463
collation_database was used in old versions (???WHEN). Its value
1464
was loaded when issuing a "use db" query and could be changed by
1465
issuing a "SET collation_database=xxx" query. It used to affect
1466
the "LOAD DATA INFILE" and "CREATE TABLE" commands.
1468
In newer versions, "CREATE TABLE" has been changed to take the
1469
character set from the database of the created table, rather than
1470
the character set of the current database. This makes a
1471
difference when creating a table in another database than the
1472
current one. "LOAD DATA INFILE" has not yet changed to do this,
1473
but there are plans to eventually do it, and to make
1474
collation_database read-only.
1476
This field is written if it is not 0.
1481
@subsection Query_log_event_notes_on_previous_versions Notes on Previous Versions
1483
* Status vars were introduced in version 5.0. To read earlier
1484
versions correctly, check the length of the Post-Header.
1486
* The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x,
1487
where 0<=x<=3. It was identical to Q_CATALOG_CODE, except that the
1488
string had a trailing '\0'. The '\0' was removed in 5.0.4 since it
1489
was redundant (the string length is stored before the string). The
1490
Q_CATALOG_CODE will never be written by a new master, but can still
1491
be understood by a new slave.
1493
* See Q_CHARSET_DATABASE_CODE in the table above.
1496
class Query_log_event: public Log_event
1499
Log_event::Byte* data_buf;
1502
const char* catalog;
1505
If we already know the length of the query string
1506
we pass it with q_len, so we would not have to call strlen()
1507
otherwise, set it to 0, in which case, we compute it with strlen()
1514
For events created by Query_log_event::do_apply_event (and
1515
Load_log_event::do_apply_event()) we need the *original* thread
1516
id, to be able to log the event with the original (=master's)
1517
thread id (fix for BUG#1686).
1519
ulong slave_proxy_id;
1522
Binlog format 3 and 4 start to differ (as far as class members are
1523
concerned) from here.
1526
uint catalog_len; // <= 255 char; 0 means uninited
1529
We want to be able to store a variable number of N-bit status vars:
1530
(generally N=32; but N=64 for SQL_MODE) a user may want to log the number
1531
of affected rows (for debugging) while another does not want to lose 4
1533
The storage on disk is the following:
1534
status_vars_len is part of the post-header,
1535
status_vars are in the variable-length part, after the post-header, before
1537
status_vars on disk is a sequence of pairs (code, value) where 'code' means
1538
'sql_mode', 'affected' etc. Sometimes 'value' must be a short string, so
1539
its first byte is its length. For now the order of status vars is:
1540
flags2 - sql_mode - catalog - autoinc - charset
1541
We should add the same thing to Load_log_event, but in fact
1542
LOAD DATA INFILE is going to be logged with a new type of event (logging of
1543
the plain text query), so Load_log_event would be frozen, so no need. The
1544
new way of logging LOAD DATA INFILE would use a derived class of
1545
Query_log_event, so automatically benefit from the work already done for
1546
status variables in Query_log_event.
1548
uint16 status_vars_len;
1551
'flags2' is a second set of flags (on top of those in Log_event), for
1552
session variables. These are thd->options which is & against a mask
1553
(OPTIONS_WRITTEN_TO_BIN_LOG).
1554
flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
1555
master, we don't know flags2, so use the slave server's global options) and
1556
flags2==0 (5.0 master, we know this has a meaning of flags all down which
1557
must influence the query).
1560
bool sql_mode_inited;
1561
bool charset_inited;
1564
/* In connections sql_mode is 32 bits now but will be 64 bits soon */
1566
ulong auto_increment_increment, auto_increment_offset;
1568
uint time_zone_len; /* 0 means uninited */
1569
const char *time_zone_str;
1570
uint lc_time_names_number; /* 0 means en_US */
1571
uint charset_database_number;
1573
#ifndef MYSQL_CLIENT
1575
Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
1576
bool using_trans, bool suppress_use,
1577
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1578
const char* get_db() { return db; }
1579
#ifdef HAVE_REPLICATION
1580
void pack_info(Protocol* protocol);
1581
#endif /* HAVE_REPLICATION */
1583
void print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info);
1584
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1588
Query_log_event(const char* buf, uint event_len,
1589
const Format_description_log_event *description_event,
1590
Log_event_type event_type);
1594
my_free((uchar*) data_buf, MYF(0));
1596
Log_event_type get_type_code() { return QUERY_EVENT; }
1597
#ifndef MYSQL_CLIENT
1598
bool write(IO_CACHE* file);
1599
virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; }
1601
bool is_valid() const { return query != 0; }
1604
Returns number of bytes additionaly written to post header by derived
1605
events (so far it is only Execute_load_query event).
1607
virtual ulong get_post_header_size_for_derived() { return 0; }
1608
/* Writes derived event-specific part of post header. */
1610
public: /* !!! Public in this patch to allow old usage */
1611
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1612
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1613
virtual int do_apply_event(Relay_log_info const *rli);
1614
virtual int do_update_pos(Relay_log_info *rli);
1616
int do_apply_event(Relay_log_info const *rli,
1617
const char *query_arg,
1619
#endif /* HAVE_REPLICATION */
1623
#ifdef HAVE_REPLICATION
1626
@class Slave_log_event
1628
Note that this class is currently not used at all; no code writes a
1629
@c Slave_log_event (though some code in @c repl_failsafe.cc reads @c
1630
Slave_log_event). So it's not a problem if this code is not
1633
@section Slave_log_event_binary_format Binary Format
1635
This event type has no Post-Header. The Body has the following
1639
<caption>Body for Slave_log_event</caption>
1644
<th>Description</th>
1649
<td>8 byte integer</td>
1655
<td>master_port</td>
1656
<td>2 byte integer</td>
1661
<td>master_host</td>
1662
<td>null-terminated string</td>
1668
<td>null-terminated string</td>
1673
class Slave_log_event: public Log_event
1677
void init_from_mem_pool(int data_size);
1679
my_off_t master_pos;
1682
int master_host_len;
1686
#ifndef MYSQL_CLIENT
1687
Slave_log_event(THD* thd_arg, Relay_log_info* rli);
1688
void pack_info(Protocol* protocol);
1690
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1693
Slave_log_event(const char* buf, uint event_len);
1695
int get_data_size();
1696
bool is_valid() const { return master_host != 0; }
1697
Log_event_type get_type_code() { return SLAVE_EVENT; }
1698
#ifndef MYSQL_CLIENT
1699
bool write(IO_CACHE* file);
1703
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1704
virtual int do_apply_event(Relay_log_info const* rli);
1708
#endif /* HAVE_REPLICATION */
1712
@class Load_log_event
1714
This log event corresponds to a "LOAD DATA INFILE" SQL query on the
1719
(2) LOAD DATA [LOCAL] INFILE 'file_name'
1720
(3) [REPLACE | IGNORE]
1721
(4) INTO TABLE 'table_name'
1723
(6) [TERMINATED BY 'field_term']
1724
(7) [[OPTIONALLY] ENCLOSED BY 'enclosed']
1725
(8) [ESCAPED BY 'escaped']
1728
(11) [TERMINATED BY 'line_term']
1729
(12) [LINES STARTING BY 'line_start']
1731
(14) [IGNORE skip_lines LINES]
1732
(15) (field_1, field_2, ..., field_n)@endverbatim
1734
@section Load_log_event_binary_format Binary Format
1736
The Post-Header consists of the following six components.
1739
<caption>Post-Header for Load_log_event</caption>
1744
<th>Description</th>
1748
<td>slave_proxy_id</td>
1749
<td>4 byte unsigned integer</td>
1750
<td>An integer identifying the client thread that issued the
1751
query. The id is unique per server. (Note, however, that two
1752
threads on different servers may have the same slave_proxy_id.)
1753
This is used when a client thread creates a temporary table local
1754
to the client. The slave_proxy_id is used to distinguish
1755
temporary tables that belong to different clients.
1761
<td>4 byte unsigned integer</td>
1762
<td>The time from when the query started to when it was logged in
1763
the binlog, in seconds.</td>
1768
<td>4 byte unsigned integer</td>
1769
<td>The number on line (14) above, if present, or 0 if line (14)
1775
<td>table_name_len</td>
1776
<td>1 byte unsigned integer</td>
1777
<td>The length of 'table_name' on line (4) above.</td>
1782
<td>1 byte unsigned integer</td>
1783
<td>The length of 'db' on line (1) above.</td>
1788
<td>4 byte unsigned integer</td>
1789
<td>The number n of fields on line (15) above.</td>
1793
The Body contains the following components.
1796
<caption>Body of Load_log_event</caption>
1801
<th>Description</th>
1806
<td>variable length</td>
1808
<td>Describes the part of the query on lines (3) and
1809
(5)–(13) above. More precisely, it stores the five strings
1810
(on lines) field_term (6), enclosed (7), escaped (8), line_term
1811
(11), and line_start (12); as well as a bitfield indicating the
1812
presence of the keywords REPLACE (3), IGNORE (3), and OPTIONALLY
1815
The data is stored in one of two formats, called "old" and "new".
1816
The type field of Common-Header determines which of these two
1817
formats is used: type LOAD_EVENT means that the old format is
1818
used, and type NEW_LOAD_EVENT means that the new format is used.
1819
When MySQL writes a Load_log_event, it uses the new format if at
1820
least one of the five strings is two or more bytes long.
1821
Otherwise (i.e., if all strings are 0 or 1 bytes long), the old
1824
The new and old format differ in the way the five strings are
1828
<li> In the new format, the strings are stored in the order
1829
field_term, enclosed, escaped, line_term, line_start. Each string
1830
consists of a length (1 byte), followed by a sequence of
1831
characters (0-255 bytes). Finally, a boolean combination of the
1832
following flags is stored in 1 byte: REPLACE_FLAG==0x4,
1833
IGNORE_FLAG==0x8, and OPT_ENCLOSED_FLAG==0x2. If a flag is set,
1834
it indicates the presence of the corresponding keyword in the SQL
1837
<li> In the old format, we know that each string has length 0 or
1838
1. Therefore, only the first byte of each string is stored. The
1839
order of the strings is the same as in the new format. These five
1840
bytes are followed by the same 1 byte bitfield as in the new
1841
format. Finally, a 1 byte bitfield called empty_flags is stored.
1842
The low 5 bits of empty_flags indicate which of the five strings
1843
have length 0. For each of the following flags that is set, the
1844
corresponding string has length 0; for the flags that are not set,
1845
the string has length 1: FIELD_TERM_EMPTY==0x1,
1846
ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4, LINE_START_EMPTY==0x8,
1847
ESCAPED_EMPTY==0x10.
1850
Thus, the size of the new format is 6 bytes + the sum of the sizes
1851
of the five strings. The size of the old format is always 7
1858
<td>num_fields 1 byte unsigned integers</td>
1859
<td>An array of num_fields integers representing the length of
1860
each field in the query. (num_fields is from the Post-Header).
1866
<td>num_fields null-terminated strings</td>
1867
<td>An array of num_fields null-terminated strings, each
1868
representing a field in the query. (The trailing zero is
1869
redundant, since the length are stored in the num_fields array.)
1870
The total length of all strings equals to the sum of all
1871
field_lens, plus num_fields bytes for all the trailing zeros.
1877
<td>null-terminated string of length table_len+1 bytes</td>
1878
<td>The 'table_name' from the query, as a null-terminated string.
1879
(The trailing zero is actually redundant since the table_len is
1880
known from Post-Header.)
1886
<td>null-terminated string of length db_len+1 bytes</td>
1887
<td>The 'db' from the query, as a null-terminated string.
1888
(The trailing zero is actually redundant since the db_len is known
1895
<td>variable length string without trailing zero, extending to the
1896
end of the event (determined by the length field of the
1899
<td>The 'file_name' from the query.
1905
@subsection Load_log_event_notes_on_previous_versions Notes on Previous Versions
1907
This event type is understood by current versions, but only
1908
generated by MySQL 3.23 and earlier.
1910
class Load_log_event: public Log_event
1913
uint get_query_buffer_length();
1914
void print_query(bool need_db, char *buf, char **end,
1915
char **fn_start, char **fn_end);
1917
int copy_log_event(const char *buf, ulong event_len,
1919
const Format_description_log_event* description_event);
1923
ulong slave_proxy_id;
1924
uint32 table_name_len;
1926
No need to have a catalog, as these events can only come from 4.x.
1927
TODO: this may become false if Dmitri pushes his new LOAD DATA INFILE in
1928
5.0 only (not in 4.x).
1934
const uchar* field_lens;
1935
uint32 field_block_len;
1937
const char* table_name;
1944
/* fname doesn't point to memory inside Log_event::temp_buf */
1945
void set_fname_outside_temp_buf(const char *afname, uint alen)
1951
/* fname doesn't point to memory inside Log_event::temp_buf */
1952
int check_fname_outside_temp_buf()
1957
#ifndef MYSQL_CLIENT
1958
String field_lens_buf;
1961
Load_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
1962
const char* table_name_arg,
1963
List<Item>& fields_arg, enum enum_duplicates handle_dup, bool ignore,
1965
void set_fields(const char* db, List<Item> &fields_arg,
1966
Name_resolution_context *context);
1967
const char* get_db() { return db; }
1968
#ifdef HAVE_REPLICATION
1969
void pack_info(Protocol* protocol);
1970
#endif /* HAVE_REPLICATION */
1972
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1973
void print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented);
1977
Note that for all the events related to LOAD DATA (Load_log_event,
1978
Create_file/Append/Exec/Delete, we pass description_event; however as
1979
logging of LOAD DATA is going to be changed in 4.1 or 5.0, this is only used
1980
for the common_header_len (post_header_len will not be changed).
1982
Load_log_event(const char* buf, uint event_len,
1983
const Format_description_log_event* description_event);
1986
Log_event_type get_type_code()
1988
return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT;
1990
#ifndef MYSQL_CLIENT
1991
bool write_data_header(IO_CACHE* file);
1992
bool write_data_body(IO_CACHE* file);
1994
bool is_valid() const { return table_name != 0; }
1997
return (table_name_len + db_len + 2 + fname_len
1999
+ sql_ex.data_size() + field_block_len + num_fields);
2002
public: /* !!! Public in this patch to allow old usage */
2003
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2004
virtual int do_apply_event(Relay_log_info const* rli)
2006
return do_apply_event(thd->slave_net,rli,0);
2009
int do_apply_event(NET *net, Relay_log_info const *rli,
2010
bool use_rli_only_for_errors);
2014
extern char server_version[SERVER_VERSION_LENGTH];
2017
@class Start_log_event_v3
2019
Start_log_event_v3 is the Start_log_event of binlog format 3 (MySQL 3.23 and
2022
Format_description_log_event derives from Start_log_event_v3; it is
2023
the Start_log_event of binlog format 4 (MySQL 5.0), that is, the
2024
event that describes the other events' Common-Header/Post-Header
2025
lengths. This event is sent by MySQL 5.0 whenever it starts sending
2026
a new binlog if the requested position is >4 (otherwise if ==4 the
2027
event will be sent naturally).
2029
@section Start_log_event_v3_binary_format Binary Format
2031
class Start_log_event_v3: public Log_event
2035
If this event is at the start of the first binary log since server
2036
startup 'created' should be the timestamp when the event (and the
2037
binary log) was created. In the other case (i.e. this event is at
2038
the start of a binary log created by FLUSH LOGS or automatic
2039
rotation), 'created' should be 0. This "trick" is used by MySQL
2040
>=4.0.14 slaves to know whether they must drop stale temporary
2041
tables and whether they should abort unfinished transaction.
2043
Note that when 'created'!=0, it is always equal to the event's
2044
timestamp; indeed Start_log_event is written only in log.cc where
2045
the first constructor below is called, in which 'created' is set
2046
to 'when'. So in fact 'created' is a useless variable. When it is
2047
0 we can read the actual value from timestamp ('when') and when it
2048
is non-zero we can read the same value from timestamp
2049
('when'). Conclusion:
2050
- we use timestamp to print when the binlog was created.
2051
- we use 'created' only to know if this is a first binlog or not.
2052
In 3.23.57 we did not pay attention to this identity, so mysqlbinlog in
2053
3.23.57 does not print 'created the_date' if created was zero. This is now
2057
uint16 binlog_version;
2058
char server_version[ST_SERVER_VER_LEN];
2060
artifical_event is 1 in the case where this is a generated event that
2061
should not case any cleanup actions. We handle this in the log by
2062
setting log_event == 0 (for now).
2064
bool artificial_event;
2066
We set this to 1 if we don't want to have the created time in the log,
2067
which is the case when we rollover to a new log.
2069
bool dont_set_created;
2071
#ifndef MYSQL_CLIENT
2072
Start_log_event_v3();
2073
#ifdef HAVE_REPLICATION
2074
void pack_info(Protocol* protocol);
2075
#endif /* HAVE_REPLICATION */
2077
Start_log_event_v3() {}
2078
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2081
Start_log_event_v3(const char* buf,
2082
const Format_description_log_event* description_event);
2083
~Start_log_event_v3() {}
2084
Log_event_type get_type_code() { return START_EVENT_V3;}
2085
#ifndef MYSQL_CLIENT
2086
bool write(IO_CACHE* file);
2088
bool is_valid() const { return 1; }
2091
return START_V3_HEADER_LEN; //no variable-sized part
2093
virtual bool is_artificial_event() { return artificial_event; }
2096
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2097
virtual int do_apply_event(Relay_log_info const *rli);
2098
virtual enum_skip_reason do_shall_skip(Relay_log_info*)
2101
Events from ourself should be skipped, but they should not
2102
decrease the slave skip counter.
2104
if (this->server_id == ::server_id)
2105
return Log_event::EVENT_SKIP_IGNORE;
2107
return Log_event::EVENT_SKIP_NOT;
2114
@class Format_description_log_event
2116
For binlog version 4.
2117
This event is saved by threads which read it, as they need it for future
2118
use (to decode the ordinary events).
2120
@section Format_description_log_event_binary_format Binary Format
2123
class Format_description_log_event: public Start_log_event_v3
2127
The size of the fixed header which _all_ events have
2128
(for binlogs written by this version, this is equal to
2129
LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
2130
(those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
2132
uint8 common_header_len;
2133
uint8 number_of_event_types;
2134
/* The list of post-headers' lengthes */
2135
uint8 *post_header_len;
2136
uchar server_version_split[3];
2137
const uint8 *event_type_permutation;
2139
Format_description_log_event(uint8 binlog_ver, const char* server_ver=0);
2140
Format_description_log_event(const char* buf, uint event_len,
2141
const Format_description_log_event
2142
*description_event);
2143
~Format_description_log_event()
2145
my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
2147
Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
2148
#ifndef MYSQL_CLIENT
2149
bool write(IO_CACHE* file);
2151
bool is_valid() const
2153
return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN :
2154
LOG_EVENT_MINIMAL_HEADER_LEN)) &&
2155
(post_header_len != NULL));
2160
The vector of post-header lengths is considered as part of the
2161
post-header, because in a given version it never changes (contrary to the
2162
query in a Query_log_event).
2164
return FORMAT_DESCRIPTION_HEADER_LEN;
2167
void calc_server_version_split();
2170
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2171
virtual int do_apply_event(Relay_log_info const *rli);
2172
virtual int do_update_pos(Relay_log_info *rli);
2173
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2179
@class Intvar_log_event
2181
An Intvar_log_event will be created just before a Query_log_event,
2182
if the query uses one of the variables LAST_INSERT_ID or INSERT_ID.
2183
Each Intvar_log_event holds the value of one of these variables.
2185
@section Intvar_log_event_binary_format Binary Format
2187
The Post-Header has two components:
2190
<caption>Post-Header for Intvar_log_event</caption>
2195
<th>Description</th>
2200
<td>1 byte enumeration</td>
2201
<td>One byte identifying the type of variable stored. Currently,
2202
two identifiers are supported: LAST_INSERT_ID_EVENT==1 and
2209
<td>8 byte unsigned integer</td>
2210
<td>The value of the variable.</td>
2215
class Intvar_log_event: public Log_event
2221
#ifndef MYSQL_CLIENT
2222
Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
2223
:Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
2225
#ifdef HAVE_REPLICATION
2226
void pack_info(Protocol* protocol);
2227
#endif /* HAVE_REPLICATION */
2229
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2232
Intvar_log_event(const char* buf,
2233
const Format_description_log_event *description_event);
2234
~Intvar_log_event() {}
2235
Log_event_type get_type_code() { return INTVAR_EVENT;}
2236
const char* get_var_type_name();
2237
int get_data_size() { return 9; /* sizeof(type) + sizeof(val) */;}
2238
#ifndef MYSQL_CLIENT
2239
bool write(IO_CACHE* file);
2241
bool is_valid() const { return 1; }
2244
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2245
virtual int do_apply_event(Relay_log_info const *rli);
2246
virtual int do_update_pos(Relay_log_info *rli);
2247
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2253
@class Rand_log_event
2255
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
2256
4.1.1 does not need it (it's repeatable again) so this event needn't be
2257
written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
2258
waste, it does not cause bugs).
2260
The state of the random number generation consists of 128 bits,
2261
which are stored internally as two 64-bit numbers.
2263
@section Rand_log_event_binary_format Binary Format
2264
This event type has no Post-Header. The Body of this event type has
2268
<caption>Post-Header for Intvar_log_event</caption>
2273
<th>Description</th>
2278
<td>8 byte unsigned integer</td>
2279
<td>64 bit random seed1.</td>
2284
<td>8 byte unsigned integer</td>
2285
<td>64 bit random seed2.</td>
2290
class Rand_log_event: public Log_event
2296
#ifndef MYSQL_CLIENT
2297
Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
2298
:Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2300
#ifdef HAVE_REPLICATION
2301
void pack_info(Protocol* protocol);
2302
#endif /* HAVE_REPLICATION */
2304
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2307
Rand_log_event(const char* buf,
2308
const Format_description_log_event *description_event);
2309
~Rand_log_event() {}
2310
Log_event_type get_type_code() { return RAND_EVENT;}
2311
int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ }
2312
#ifndef MYSQL_CLIENT
2313
bool write(IO_CACHE* file);
2315
bool is_valid() const { return 1; }
2318
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2319
virtual int do_apply_event(Relay_log_info const *rli);
2320
virtual int do_update_pos(Relay_log_info *rli);
2321
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2326
@class Xid_log_event
2328
Logs xid of the transaction-to-be-committed in the 2pc protocol.
2329
Has no meaning in replication, slaves ignore it.
2331
@section Xid_log_event_binary_format Binary Format
2334
typedef ulonglong my_xid; // this line is the same as in handler.h
2337
class Xid_log_event: public Log_event
2342
#ifndef MYSQL_CLIENT
2343
Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
2344
#ifdef HAVE_REPLICATION
2345
void pack_info(Protocol* protocol);
2346
#endif /* HAVE_REPLICATION */
2348
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2351
Xid_log_event(const char* buf,
2352
const Format_description_log_event *description_event);
2354
Log_event_type get_type_code() { return XID_EVENT;}
2355
int get_data_size() { return sizeof(xid); }
2356
#ifndef MYSQL_CLIENT
2357
bool write(IO_CACHE* file);
2359
bool is_valid() const { return 1; }
2362
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2363
virtual int do_apply_event(Relay_log_info const *rli);
2364
enum_skip_reason do_shall_skip(Relay_log_info *rli);
2369
@class User_var_log_event
2371
Every time a query uses the value of a user variable, a User_var_log_event is
2372
written before the Query_log_event, to set the user variable.
2374
@section User_var_log_event_binary_format Binary Format
2377
class User_var_log_event: public Log_event
2385
uint charset_number;
2387
#ifndef MYSQL_CLIENT
2388
User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
2389
char *val_arg, ulong val_len_arg, Item_result type_arg,
2390
uint charset_number_arg)
2391
:Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
2392
val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
2394
void pack_info(Protocol* protocol);
2396
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2399
User_var_log_event(const char* buf,
2400
const Format_description_log_event *description_event);
2401
~User_var_log_event() {}
2402
Log_event_type get_type_code() { return USER_VAR_EVENT;}
2403
#ifndef MYSQL_CLIENT
2404
bool write(IO_CACHE* file);
2406
bool is_valid() const { return 1; }
2409
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2410
virtual int do_apply_event(Relay_log_info const *rli);
2411
virtual int do_update_pos(Relay_log_info *rli);
2412
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2418
@class Stop_log_event
2420
@section Stop_log_event_binary_format Binary Format
2422
The Post-Header and Body for this event type are empty; it only has
2425
class Stop_log_event: public Log_event
2428
#ifndef MYSQL_CLIENT
2429
Stop_log_event() :Log_event()
2432
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2435
Stop_log_event(const char* buf,
2436
const Format_description_log_event *description_event):
2437
Log_event(buf, description_event)
2439
~Stop_log_event() {}
2440
Log_event_type get_type_code() { return STOP_EVENT;}
2441
bool is_valid() const { return 1; }
2444
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2445
virtual int do_update_pos(Relay_log_info *rli);
2446
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
2449
Events from ourself should be skipped, but they should not
2450
decrease the slave skip counter.
2452
if (this->server_id == ::server_id)
2453
return Log_event::EVENT_SKIP_IGNORE;
2455
return Log_event::EVENT_SKIP_NOT;
2461
@class Rotate_log_event
2463
This will be deprecated when we move to using sequence ids.
2465
@section Rotate_log_event_binary_format Binary Format
2467
The Post-Header has one component:
2470
<caption>Post-Header for Rotate_log_event</caption>
2475
<th>Description</th>
2480
<td>8 byte integer</td>
2481
<td>The position within the binlog to rotate to.</td>
2486
The Body has one component:
2489
<caption>Body for Rotate_log_event</caption>
2494
<th>Description</th>
2499
<td>variable length string without trailing zero, extending to the
2500
end of the event (determined by the length field of the
2503
<td>Name of the binlog to rotate to.</td>
2509
class Rotate_log_event: public Log_event
2513
DUP_NAME= 2 // if constructor should dup the string argument
2515
const char* new_log_ident;
2519
#ifndef MYSQL_CLIENT
2520
Rotate_log_event(const char* new_log_ident_arg,
2522
ulonglong pos_arg, uint flags);
2523
#ifdef HAVE_REPLICATION
2524
void pack_info(Protocol* protocol);
2525
#endif /* HAVE_REPLICATION */
2527
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2530
Rotate_log_event(const char* buf, uint event_len,
2531
const Format_description_log_event* description_event);
2534
if (flags & DUP_NAME)
2535
my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
2537
Log_event_type get_type_code() { return ROTATE_EVENT;}
2538
int get_data_size() { return ident_len + ROTATE_HEADER_LEN;}
2539
bool is_valid() const { return new_log_ident != 0; }
2540
#ifndef MYSQL_CLIENT
2541
bool write(IO_CACHE* file);
2545
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2546
virtual int do_update_pos(Relay_log_info *rli);
2547
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2552
/* the classes below are for the new LOAD DATA INFILE logging */
2555
@class Create_file_log_event
2557
@section Create_file_log_event_binary_format Binary Format
2560
class Create_file_log_event: public Load_log_event
2564
Pretend we are Load event, so we can write out just
2565
our Load part - used on the slave when writing event out to
2566
SQL_LOAD-*.info file
2571
const char *event_buf;
2574
bool inited_from_old;
2576
#ifndef MYSQL_CLIENT
2577
Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
2578
const char* table_name_arg,
2579
List<Item>& fields_arg,
2580
enum enum_duplicates handle_dup, bool ignore,
2581
uchar* block_arg, uint block_len_arg,
2583
#ifdef HAVE_REPLICATION
2584
void pack_info(Protocol* protocol);
2585
#endif /* HAVE_REPLICATION */
2587
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2588
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2592
Create_file_log_event(const char* buf, uint event_len,
2593
const Format_description_log_event* description_event);
2594
~Create_file_log_event()
2596
my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
2599
Log_event_type get_type_code()
2601
return fake_base ? Load_log_event::get_type_code() : CREATE_FILE_EVENT;
2605
return (fake_base ? Load_log_event::get_data_size() :
2606
Load_log_event::get_data_size() +
2609
bool is_valid() const { return inited_from_old || block != 0; }
2610
#ifndef MYSQL_CLIENT
2611
bool write_data_header(IO_CACHE* file);
2612
bool write_data_body(IO_CACHE* file);
2614
Cut out Create_file extentions and
2615
write it as Load event - used on the slave
2617
bool write_base(IO_CACHE* file);
2621
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2622
virtual int do_apply_event(Relay_log_info const *rli);
2628
@class Append_block_log_event
2630
@section Append_block_log_event_binary_format Binary Format
2633
class Append_block_log_event: public Log_event
2640
'db' is filled when the event is created in mysql_load() (the
2641
event needs to have a 'db' member to be well filtered by
2642
binlog-*-db rules). 'db' is not written to the binlog (it's not
2643
used by Append_block_log_event::write()), so it can't be read in
2644
the Append_block_log_event(const char* buf, int event_len)
2645
constructor. In other words, 'db' is used only for filtering by
2646
binlog-*-db rules. Create_file_log_event is different: it's 'db'
2647
(which is inherited from Load_log_event) is written to the binlog
2652
#ifndef MYSQL_CLIENT
2653
Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
2654
uint block_len_arg, bool using_trans);
2655
#ifdef HAVE_REPLICATION
2656
void pack_info(Protocol* protocol);
2657
virtual int get_create_or_append() const;
2658
#endif /* HAVE_REPLICATION */
2660
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2663
Append_block_log_event(const char* buf, uint event_len,
2664
const Format_description_log_event
2665
*description_event);
2666
~Append_block_log_event() {}
2667
Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
2668
int get_data_size() { return block_len + APPEND_BLOCK_HEADER_LEN ;}
2669
bool is_valid() const { return block != 0; }
2670
#ifndef MYSQL_CLIENT
2671
bool write(IO_CACHE* file);
2672
const char* get_db() { return db; }
2676
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2677
virtual int do_apply_event(Relay_log_info const *rli);
2683
@class Delete_file_log_event
2685
@section Delete_file_log_event_binary_format Binary Format
2688
class Delete_file_log_event: public Log_event
2692
const char* db; /* see comment in Append_block_log_event */
2694
#ifndef MYSQL_CLIENT
2695
Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
2696
#ifdef HAVE_REPLICATION
2697
void pack_info(Protocol* protocol);
2698
#endif /* HAVE_REPLICATION */
2700
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2701
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2705
Delete_file_log_event(const char* buf, uint event_len,
2706
const Format_description_log_event* description_event);
2707
~Delete_file_log_event() {}
2708
Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
2709
int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
2710
bool is_valid() const { return file_id != 0; }
2711
#ifndef MYSQL_CLIENT
2712
bool write(IO_CACHE* file);
2713
const char* get_db() { return db; }
2717
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2718
virtual int do_apply_event(Relay_log_info const *rli);
2724
@class Execute_load_log_event
2726
@section Delete_file_log_event_binary_format Binary Format
2729
class Execute_load_log_event: public Log_event
2733
const char* db; /* see comment in Append_block_log_event */
2735
#ifndef MYSQL_CLIENT
2736
Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
2737
#ifdef HAVE_REPLICATION
2738
void pack_info(Protocol* protocol);
2739
#endif /* HAVE_REPLICATION */
2741
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2744
Execute_load_log_event(const char* buf, uint event_len,
2745
const Format_description_log_event
2746
*description_event);
2747
~Execute_load_log_event() {}
2748
Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
2749
int get_data_size() { return EXEC_LOAD_HEADER_LEN ;}
2750
bool is_valid() const { return file_id != 0; }
2751
#ifndef MYSQL_CLIENT
2752
bool write(IO_CACHE* file);
2753
const char* get_db() { return db; }
2757
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2758
virtual int do_apply_event(Relay_log_info const *rli);
2764
@class Begin_load_query_log_event
2766
Event for the first block of file to be loaded, its only difference from
2767
Append_block event is that this event creates or truncates existing file
2768
before writing data.
2770
@section Begin_load_query_log_event_binary_format Binary Format
2772
class Begin_load_query_log_event: public Append_block_log_event
2775
#ifndef MYSQL_CLIENT
2776
Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
2777
uchar* block_arg, uint block_len_arg,
2779
#ifdef HAVE_REPLICATION
2780
Begin_load_query_log_event(THD* thd);
2781
int get_create_or_append() const;
2782
#endif /* HAVE_REPLICATION */
2784
Begin_load_query_log_event(const char* buf, uint event_len,
2785
const Format_description_log_event
2786
*description_event);
2787
~Begin_load_query_log_event() {}
2788
Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
2790
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2791
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2797
Elements of this enum describe how LOAD DATA handles duplicates.
2799
enum enum_load_dup_handling { LOAD_DUP_ERROR= 0, LOAD_DUP_IGNORE,
2803
@class Execute_load_query_log_event
2805
Event responsible for LOAD DATA execution, it similar to Query_log_event
2806
but before executing the query it substitutes original filename in LOAD DATA
2807
query with name of temporary file.
2809
@section Execute_load_query_log_event_binary_format Binary Format
2811
class Execute_load_query_log_event: public Query_log_event
2814
uint file_id; // file_id of temporary file
2815
uint fn_pos_start; // pointer to the part of the query that should
2817
uint fn_pos_end; // pointer to the end of this part of query
2819
We have to store type of duplicate handling explicitly, because
2820
for LOAD DATA it also depends on LOCAL option. And this part
2821
of query will be rewritten during replication so this information
2824
enum_load_dup_handling dup_handling;
2826
#ifndef MYSQL_CLIENT
2827
Execute_load_query_log_event(THD* thd, const char* query_arg,
2828
ulong query_length, uint fn_pos_start_arg,
2829
uint fn_pos_end_arg,
2830
enum_load_dup_handling dup_handling_arg,
2831
bool using_trans, bool suppress_use,
2833
killed_err_arg= THD::KILLED_NO_VALUE);
2834
#ifdef HAVE_REPLICATION
2835
void pack_info(Protocol* protocol);
2836
#endif /* HAVE_REPLICATION */
2838
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2839
/* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2840
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2841
const char *local_fname);
2843
Execute_load_query_log_event(const char* buf, uint event_len,
2844
const Format_description_log_event
2845
*description_event);
2846
~Execute_load_query_log_event() {}
2848
Log_event_type get_type_code() { return EXECUTE_LOAD_QUERY_EVENT; }
2849
bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
2851
ulong get_post_header_size_for_derived();
2852
#ifndef MYSQL_CLIENT
2853
bool write_post_header_for_derived(IO_CACHE* file);
2857
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2858
virtual int do_apply_event(Relay_log_info const *rli);
2865
@class Unknown_log_event
2867
@section Unknown_log_event_binary_format Binary Format
2869
class Unknown_log_event: public Log_event
2873
Even if this is an unknown event, we still pass description_event to
2874
Log_event's ctor, this way we can extract maximum information from the
2875
event's header (the unique ID for example).
2877
Unknown_log_event(const char* buf,
2878
const Format_description_log_event *description_event):
2879
Log_event(buf, description_event)
2881
~Unknown_log_event() {}
2882
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2883
Log_event_type get_type_code() { return UNKNOWN_EVENT;}
2884
bool is_valid() const { return 1; }
2887
char *str_to_hex(char *to, const char *from, uint len);
2890
@class Table_map_log_event
2892
In row-based mode, every row operation event is preceded by a
2893
Table_map_log_event which maps a table definition to a number. The
2894
table definition consists of database name, table name, and column
2897
@section Table_map_log_event_binary_format Binary Format
2899
The Post-Header has the following components:
2902
<caption>Post-Header for Table_map_log_event</caption>
2907
<th>Description</th>
2912
<td>6 bytes unsigned integer</td>
2913
<td>The number that identifies the table.</td>
2918
<td>2 byte bitfield</td>
2919
<td>Reserved for future use; currently always 0.</td>
2924
The Body has the following components:
2927
<caption>Body for Table_map_log_event</caption>
2932
<th>Description</th>
2936
<td>database_name</td>
2937
<td>one byte string length, followed by null-terminated string</td>
2938
<td>The name of the database in which the table resides. The name
2939
is represented as a one byte unsigned integer representing the
2940
number of bytes in the name, followed by length bytes containing
2941
the database name, followed by a terminating 0 byte. (Note the
2942
redundancy in the representation of the length.) </td>
2947
<td>one byte string length, followed by null-terminated string</td>
2948
<td>The name of the table, encoded the same way as the database
2953
<td>column_count</td>
2954
<td>@ref packed_integer "Packed Integer"</td>
2955
<td>The number of columns in the table, represented as a packed
2956
variable-length integer.</td>
2960
<td>column_type</td>
2961
<td>List of column_count 1 byte enumeration values</td>
2962
<td>The type of each column in the table, listed from left to
2963
right. Each byte is mapped to a column type according to the
2964
enumeration type enum_field_types defined in mysql_com.h. The
2965
mapping of types to numbers is listed in the table @ref
2966
Table_table_map_log_event_column_types "below" (along with
2967
description of the associated metadata field). </td>
2971
<td>metadata_length</td>
2972
<td>@ref packed_integer "Packed Integer"</td>
2973
<td>The length of the following metadata block</td>
2978
<td>list of metadata for each column</td>
2979
<td>For each column from left to right, a chunk of data who's
2980
length and semantics depends on the type of the column. The
2981
length and semantics for the metadata for each column are listed
2982
in the table @ref Table_table_map_log_event_column_types
2988
<td>column_count bits, rounded up to nearest byte</td>
2989
<td>For each column, a bit indicating whether data in the column
2990
can be NULL or not. The number of bytes needed for this is
2991
int((column_count+7)/8). The flag for the first column from the
2992
left is in the least-significant bit of the first byte, the second
2993
is in the second least significant bit of the first byte, the
2994
ninth is in the least significant bit of the second byte, and so
3000
The table below lists all column types, along with the numerical
3001
identifier for it and the size and interpretation of meta-data used
3002
to describe the type.
3004
@anchor Table_table_map_log_event_column_types
3006
<caption>Table_map_log_event column types: numerical identifier and
3011
<th>Size of metadata in bytes</th>
3012
<th>Description of metadata</th>
3016
<td>MYSQL_TYPE_DECIMAL</td><td>0</td>
3018
<td>No column metadata.</td>
3022
<td>MYSQL_TYPE_TINY</td><td>1</td>
3024
<td>No column metadata.</td>
3028
<td>MYSQL_TYPE_SHORT</td><td>2</td>
3030
<td>No column metadata.</td>
3034
<td>MYSQL_TYPE_LONG</td><td>3</td>
3036
<td>No column metadata.</td>
3040
<td>MYSQL_TYPE_FLOAT</td><td>4</td>
3042
<td>1 byte unsigned integer, representing the "pack_length", which
3043
is equal to sizeof(float) on the server from which the event
3048
<td>MYSQL_TYPE_DOUBLE</td><td>5</td>
3050
<td>1 byte unsigned integer, representing the "pack_length", which
3051
is equal to sizeof(double) on the server from which the event
3056
<td>MYSQL_TYPE_NULL</td><td>6</td>
3058
<td>No column metadata.</td>
3062
<td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
3064
<td>No column metadata.</td>
3068
<td>MYSQL_TYPE_LONGLONG</td><td>8</td>
3070
<td>No column metadata.</td>
3074
<td>MYSQL_TYPE_INT24</td><td>9</td>
3076
<td>No column metadata.</td>
3080
<td>MYSQL_TYPE_DATE</td><td>10</td>
3082
<td>No column metadata.</td>
3086
<td>MYSQL_TYPE_TIME</td><td>11</td>
3088
<td>No column metadata.</td>
3092
<td>MYSQL_TYPE_DATETIME</td><td>12</td>
3094
<td>No column metadata.</td>
3098
<td>MYSQL_TYPE_YEAR</td><td>13</td>
3100
<td>No column metadata.</td>
3104
<td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
3106
<td><i>This enumeration value is only used internally and cannot
3107
exist in a binlog.</i></td>
3111
<td>MYSQL_TYPE_VARCHAR</td><td>15</td>
3113
<td>2 byte unsigned integer representing the maximum length of
3118
<td>MYSQL_TYPE_BIT</td><td>16</td>
3120
<td>A 1 byte unsigned int representing the length in bits of the
3121
bitfield (0 to 64), followed by a 1 byte unsigned int
3122
representing the number of bytes occupied by the bitfield. The
3123
number of bytes is either int((length+7)/8) or int(length/8).</td>
3127
<td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
3129
<td>A 1 byte unsigned int representing the precision, followed
3130
by a 1 byte unsigned int representing the number of decimals.</td>
3134
<td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
3136
<td><i>This enumeration value is only used internally and cannot
3137
exist in a binlog.</i></td>
3141
<td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
3143
<td><i>This enumeration value is only used internally and cannot
3144
exist in a binlog.</i></td>
3148
<td>MYSQL_TYPE_TINY_BLOB</td><td>249</td>
3150
<td><i>This enumeration value is only used internally and cannot
3151
exist in a binlog.</i></td>
3155
<td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td><td><i>250</i></td>
3157
<td><i>This enumeration value is only used internally and cannot
3158
exist in a binlog.</i></td>
3162
<td><i>MYSQL_TYPE_LONG_BLOB</i></td><td><i>251</i></td>
3164
<td><i>This enumeration value is only used internally and cannot
3165
exist in a binlog.</i></td>
3169
<td>MYSQL_TYPE_BLOB</td><td>252</td>
3171
<td>The pack length, i.e., the number of bytes needed to represent
3172
the length of the blob: 1, 2, 3, or 4.</td>
3176
<td>MYSQL_TYPE_VAR_STRING</td><td>253</td>
3178
<td>This is used to store both strings and enumeration values.
3179
The first byte is a enumeration value storing the <i>real
3180
type</i>, which may be either MYSQL_TYPE_VAR_STRING or
3181
MYSQL_TYPE_ENUM. The second byte is a 1 byte unsigned integer
3182
representing the field size, i.e., the number of bytes needed to
3183
store the length of the string.</td>
3187
<td>MYSQL_TYPE_STRING</td><td>254</td>
3189
<td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
3190
The second byte is the field size, i.e., the number of bytes in
3191
the representation of size of the string: 3 or 4.</td>
3195
<td>MYSQL_TYPE_GEOMETRY</td><td>255</td>
3197
<td>The pack length, i.e., the number of bytes needed to represent
3198
the length of the geometry: 1, 2, 3, or 4.</td>
3203
class Table_map_log_event : public Log_event
3209
TYPE_CODE = TABLE_MAP_EVENT
3213
Enumeration of the errors that can be returned.
3217
ERR_OPEN_FAILURE = -1, /**< Failure to open table */
3218
ERR_OK = 0, /**< No error */
3219
ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
3220
ERR_OUT_OF_MEM = 2, /**< Out of memory */
3221
ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
3222
ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
3228
Nothing here right now, but the flags support is there in
3229
preparation for changes that are coming. Need to add a
3230
constant to make it compile under HP-UX: aCC does not like
3236
typedef uint16 flag_set;
3238
/* Special constants representing sets of flags */
3244
void set_flags(flag_set flag) { m_flags |= flag; }
3245
void clear_flags(flag_set flag) { m_flags &= ~flag; }
3246
flag_set get_flags(flag_set flag) const { return m_flags & flag; }
3248
#ifndef MYSQL_CLIENT
3249
Table_map_log_event(THD *thd, TABLE *tbl, ulong tid,
3250
bool is_transactional, uint16 flags);
3252
#ifdef HAVE_REPLICATION
3253
Table_map_log_event(const char *buf, uint event_len,
3254
const Format_description_log_event *description_event);
3257
~Table_map_log_event();
3259
virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; }
3260
virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
3262
virtual int get_data_size() { return m_data_size; }
3263
#ifndef MYSQL_CLIENT
3264
virtual int save_field_metadata();
3265
virtual bool write_data_header(IO_CACHE *file);
3266
virtual bool write_data_body(IO_CACHE *file);
3267
virtual const char *get_db() { return m_dbnam; }
3270
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3271
virtual void pack_info(Protocol *protocol);
3275
virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3280
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3281
virtual int do_apply_event(Relay_log_info const *rli);
3282
virtual int do_update_pos(Relay_log_info *rli);
3283
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3286
#ifndef MYSQL_CLIENT
3289
char const *m_dbnam;
3291
char const *m_tblnam;
3302
uchar *m_field_metadata; // buffer for field metadata
3304
The size of field metadata buffer set by calling save_field_metadata()
3306
ulong m_field_metadata_size;
3308
uchar *m_meta_memory;
3313
@class Rows_log_event
3315
Common base class for all row-containing log events.
3319
Encode the common parts of all events containing rows, which are:
3320
- Write data header and data body to an IO_CACHE.
3321
- Provide an interface for adding an individual row to the event.
3323
@section Rows_log_event_binary_format Binary Format
3327
class Rows_log_event : public Log_event
3331
Enumeration of the errors that can be returned.
3335
ERR_OPEN_FAILURE = -1, /**< Failure to open table */
3336
ERR_OK = 0, /**< No error */
3337
ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
3338
ERR_OUT_OF_MEM = 2, /**< Out of memory */
3339
ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
3340
ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
3344
These definitions allow you to combine the flags into an
3345
appropriate flag set using the normal bitwise operators. The
3346
implicit conversion from an enum-constant to an integer is
3347
accepted by the compiler, which is then used to set the real set
3352
/* Last event of a statement */
3353
STMT_END_F = (1U << 0),
3355
/* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in thd->options */
3356
NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
3358
/* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
3359
RELAXED_UNIQUE_CHECKS_F = (1U << 2),
3362
Indicates that rows in this event are complete, that is contain
3363
values for all columns of the table.
3365
COMPLETE_ROWS_F = (1U << 3)
3368
typedef uint16 flag_set;
3370
/* Special constants representing sets of flags */
3376
virtual ~Rows_log_event();
3378
void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
3379
void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
3380
flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
3382
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3383
virtual void pack_info(Protocol *protocol);
3387
/* not for direct call, each derived has its own ::print() */
3388
virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0;
3391
#ifndef MYSQL_CLIENT
3392
int add_row_data(uchar *data, size_t length)
3394
return do_add_row_data(data,length);
3398
/* Member functions to implement superclass interface */
3399
virtual int get_data_size();
3401
MY_BITMAP const *get_cols() const { return &m_cols; }
3402
size_t get_width() const { return m_width; }
3403
ulong get_table_id() const { return m_table_id; }
3405
#ifndef MYSQL_CLIENT
3406
virtual bool write_data_header(IO_CACHE *file);
3407
virtual bool write_data_body(IO_CACHE *file);
3408
virtual const char *get_db() { return m_table->s->db.str; }
3411
Check that malloc() succeeded in allocating memory for the rows
3412
buffer and the COLS vector. Checking that an Update_rows_log_event
3413
is valid is done in the Update_rows_log_event::is_valid()
3416
virtual bool is_valid() const
3418
return m_rows_buf && m_cols.bitmap;
3421
uint m_row_count; /* The number of rows added to the event */
3425
The constructors are protected since you're supposed to inherit
3426
this class, not create instances of this class.
3428
#ifndef MYSQL_CLIENT
3429
Rows_log_event(THD*, TABLE*, ulong table_id,
3430
MY_BITMAP const *cols, bool is_transactional);
3432
Rows_log_event(const char *row_data, uint event_len,
3433
Log_event_type event_type,
3434
const Format_description_log_event *description_event);
3437
void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
3440
#ifndef MYSQL_CLIENT
3441
virtual int do_add_row_data(uchar *data, size_t length);
3444
#ifndef MYSQL_CLIENT
3445
TABLE *m_table; /* The table the rows belong to */
3447
ulong m_table_id; /* Table ID */
3448
MY_BITMAP m_cols; /* Bitmap denoting columns available */
3449
ulong m_width; /* The width of the columns bitmap */
3451
Bitmap for columns available in the after image, if present. These
3452
fields are only available for Update_rows events. Observe that the
3453
width of both the before image COLS vector and the after image
3454
COLS vector is the same: the number of columns of the table on the
3457
MY_BITMAP m_cols_ai;
3459
ulong m_master_reclength; /* Length of record on master side */
3461
/* Bit buffers in the same memory as the class */
3462
uint32 m_bitbuf[128/(sizeof(uint32)*8)];
3463
uint32 m_bitbuf_ai[128/(sizeof(uint32)*8)];
3465
uchar *m_rows_buf; /* The rows in packed format */
3466
uchar *m_rows_cur; /* One-after the end of the data */
3467
uchar *m_rows_end; /* One-after the end of the allocated space */
3469
flag_set m_flags; /* Flags for row-level events */
3471
/* helper functions */
3473
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3474
const uchar *m_curr_row; /* Start of the row being processed */
3475
const uchar *m_curr_row_end; /* One-after the end of the current row */
3476
uchar *m_key; /* Buffer to keep key value during searches */
3478
int find_row(const Relay_log_info *const);
3479
int write_row(const Relay_log_info *const, const bool);
3481
// Unpack the current row into m_table->record[0]
3482
int unpack_current_row(const Relay_log_info *const rli,
3483
MY_BITMAP const *cols)
3485
DBUG_ASSERT(m_table);
3486
ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
3487
int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
3488
&m_curr_row_end, &m_master_reclength);
3489
if (m_curr_row_end > m_rows_end)
3490
my_error(ER_SLAVE_CORRUPT_EVENT, MYF(0));
3491
ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
3498
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3499
virtual int do_apply_event(Relay_log_info const *rli);
3500
virtual int do_update_pos(Relay_log_info *rli);
3501
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3504
Primitive to prepare for a sequence of row executions.
3508
Before doing a sequence of do_prepare_row() and do_exec_row()
3509
calls, this member function should be called to prepare for the
3510
entire sequence. Typically, this member function will allocate
3511
space for any buffers that are needed for the two member
3512
functions mentioned above.
3516
The member function will return 0 if all went OK, or a non-zero
3517
error code otherwise.
3520
int do_before_row_operations(const Slave_reporting_capability *const log) = 0;
3523
Primitive to clean up after a sequence of row executions.
3527
After doing a sequence of do_prepare_row() and do_exec_row(),
3528
this member function should be called to clean up and release
3529
any allocated buffers.
3531
The error argument, if non-zero, indicates an error which happened during
3532
row processing before this function was called. In this case, even if
3533
function is successful, it should return the error code given in the argument.
3536
int do_after_row_operations(const Slave_reporting_capability *const log,
3540
Primitive to do the actual execution necessary for a row.
3543
The member function will do the actual execution needed to handle a row.
3544
The row is located at m_curr_row. When the function returns,
3545
m_curr_row_end should point at the next row (one byte after the end
3546
of the current row).
3549
0 if execution succeeded, 1 if execution failed.
3552
virtual int do_exec_row(const Relay_log_info *const rli) = 0;
3553
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3555
friend class Old_rows_log_event;
3559
@class Write_rows_log_event
3561
Log row insertions and updates. The event contain several
3562
insert/update rows for a table. Note that each event contains only
3565
@section Write_rows_log_event_binary_format Binary Format
3567
class Write_rows_log_event : public Rows_log_event
3572
/* Support interface to THD::binlog_prepare_pending_rows_event */
3573
TYPE_CODE = WRITE_ROWS_EVENT
3576
#if !defined(MYSQL_CLIENT)
3577
Write_rows_log_event(THD*, TABLE*, ulong table_id,
3578
bool is_transactional);
3580
#ifdef HAVE_REPLICATION
3581
Write_rows_log_event(const char *buf, uint event_len,
3582
const Format_description_log_event *description_event);
3584
#if !defined(MYSQL_CLIENT)
3585
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3586
bool is_transactional,
3587
const uchar *before_record
3588
__attribute__((unused)),
3589
const uchar *after_record)
3591
return thd->binlog_write_row(table, is_transactional, after_record);
3596
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3599
void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3602
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3603
virtual int do_before_row_operations(const Slave_reporting_capability *const);
3604
virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3605
virtual int do_exec_row(const Relay_log_info *const);
3611
@class Update_rows_log_event
3613
Log row updates with a before image. The event contain several
3614
update rows for a table. Note that each event contains only rows for
3617
Also note that the row data consists of pairs of row data: one row
3618
for the old data and one row for the new data.
3620
@section Update_rows_log_event_binary_format Binary Format
3622
class Update_rows_log_event : public Rows_log_event
3627
/* Support interface to THD::binlog_prepare_pending_rows_event */
3628
TYPE_CODE = UPDATE_ROWS_EVENT
3631
#ifndef MYSQL_CLIENT
3632
Update_rows_log_event(THD*, TABLE*, ulong table_id,
3633
bool is_transactional);
3635
void init(MY_BITMAP const *cols);
3638
virtual ~Update_rows_log_event();
3640
#ifdef HAVE_REPLICATION
3641
Update_rows_log_event(const char *buf, uint event_len,
3642
const Format_description_log_event *description_event);
3645
#if !defined(MYSQL_CLIENT)
3646
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3647
bool is_transactional,
3648
const uchar *before_record,
3649
const uchar *after_record)
3651
return thd->binlog_update_row(table, is_transactional,
3652
before_record, after_record);
3656
virtual bool is_valid() const
3658
return Rows_log_event::is_valid() && m_cols_ai.bitmap;
3662
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3665
void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3668
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3669
virtual int do_before_row_operations(const Slave_reporting_capability *const);
3670
virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3671
virtual int do_exec_row(const Relay_log_info *const);
3672
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3676
@class Delete_rows_log_event
3678
Log row deletions. The event contain several delete rows for a
3679
table. Note that each event contains only rows for one table.
3683
- Act as a container for rows that has been deleted on the master
3684
and should be deleted on the slave.
3689
Create the event and add rows to the event.
3691
Extract the rows from the event.
3693
@section Delete_rows_log_event_binary_format Binary Format
3695
class Delete_rows_log_event : public Rows_log_event
3700
/* Support interface to THD::binlog_prepare_pending_rows_event */
3701
TYPE_CODE = DELETE_ROWS_EVENT
3704
#ifndef MYSQL_CLIENT
3705
Delete_rows_log_event(THD*, TABLE*, ulong,
3706
bool is_transactional);
3708
#ifdef HAVE_REPLICATION
3709
Delete_rows_log_event(const char *buf, uint event_len,
3710
const Format_description_log_event *description_event);
3712
#if !defined(MYSQL_CLIENT)
3713
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3714
bool is_transactional,
3715
const uchar *before_record,
3716
const uchar *after_record
3717
__attribute__((unused)))
3719
return thd->binlog_delete_row(table, is_transactional, before_record);
3724
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3727
void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3730
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3731
virtual int do_before_row_operations(const Slave_reporting_capability *const);
3732
virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3733
virtual int do_exec_row(const Relay_log_info *const);
3739
@class Incident_log_event
3741
Class representing an incident, an occurance out of the ordinary,
3742
that happened on the master.
3744
The event is used to inform the slave that something out of the
3745
ordinary happened on the master that might cause the database to be
3746
in an inconsistent state.
3748
<table id="IncidentFormat">
3749
<caption>Incident event format</caption>
3753
<th>Description</th>
3757
<td align="right">2</td>
3758
<td>Incident number as an unsigned integer</td>
3762
<td align="right">1</td>
3763
<td>Message length as an unsigned integer</td>
3767
<td align="right">MSGLEN</td>
3768
<td>The message, if present. Not null terminated.</td>
3772
@section Delete_rows_log_event_binary_format Binary Format
3774
class Incident_log_event : public Log_event {
3776
#ifndef MYSQL_CLIENT
3777
Incident_log_event(THD *thd_arg, Incident incident)
3778
: Log_event(thd_arg, 0, FALSE), m_incident(incident)
3780
DBUG_ENTER("Incident_log_event::Incident_log_event");
3781
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3782
m_message.str= NULL; /* Just as a precaution */
3783
m_message.length= 0;
3787
Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
3788
: Log_event(thd_arg, 0, FALSE), m_incident(incident)
3790
DBUG_ENTER("Incident_log_event::Incident_log_event");
3791
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3797
#ifndef MYSQL_CLIENT
3798
void pack_info(Protocol*);
3801
Incident_log_event(const char *buf, uint event_len,
3802
const Format_description_log_event *descr_event);
3804
virtual ~Incident_log_event();
3807
virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3810
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3811
virtual int do_apply_event(Relay_log_info const *rli);
3814
virtual bool write_data_header(IO_CACHE *file);
3815
virtual bool write_data_body(IO_CACHE *file);
3817
virtual Log_event_type get_type_code() { return INCIDENT_EVENT; }
3819
virtual bool is_valid() const { return 1; }
3820
virtual int get_data_size() {
3821
return INCIDENT_HEADER_LEN + 1 + m_message.length;
3825
const char *description() const;
3827
Incident m_incident;
3828
LEX_STRING m_message;
3831
static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3835
my_b_copy_to_file(cache, file) ||
3836
reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);
3839
#ifndef MYSQL_CLIENT
3840
/*****************************************************************************
3842
Heartbeat Log Event class
3844
Replication event to ensure to slave that master is alive.
3845
The event is originated by master's dump thread and sent straight to
3846
slave without being logged. Slave itself does not store it in relay log
3847
but rather uses a data for immediate checks and throws away the event.
3849
Two members of the class log_ident and Log_event::log_pos comprise
3850
@see the event_coordinates instance. The coordinates that a heartbeat
3851
instance carries correspond to the last event master has sent from
3854
****************************************************************************/
3855
class Heartbeat_log_event: public Log_event
3858
Heartbeat_log_event(const char* buf, uint event_len,
3859
const Format_description_log_event* description_event);
3860
Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
3861
bool is_valid() const
3863
return (log_ident != NULL &&
3864
log_pos >= BIN_LOG_HEADER_SIZE);
3866
const char * get_log_ident() { return log_ident; }
3867
uint get_ident_len() { return ident_len; }
3870
const char* log_ident;
3876
@} (end of group Replication)
3879
#endif /* _log_event_h */