~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
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.
11
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 */
15
16
/**
17
  @addtogroup Replication
18
  @{
19
20
  @file
21
  
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
24
  type of log event.
25
*/
26
27
28
#ifndef _log_event_h
29
#define _log_event_h
30
31
#if defined(USE_PRAGMA_INTERFACE) && !defined(MYSQL_CLIENT)
32
#pragma interface			/* gcc class implementation */
33
#endif
34
35
#include <my_bitmap.h>
36
#include "rpl_constants.h"
37
#ifndef MYSQL_CLIENT
38
#include "rpl_record.h"
39
#include "rpl_reporting.h"
53.2.4 by Monty Taylor
Changes so that client/ builds cleanly with no warnings.
40
#else
41
#include "my_decimal.h"
1 by brian
clean slate
42
#endif
43
44
/**
45
   Either assert or return an error.
46
47
   In debug build, the condition will be checked, but in non-debug
48
   builds, the error code given will be returned instead.
49
50
   @param COND   Condition to check
51
   @param ERRNO  Error number to return in non-debug builds
52
*/
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
53
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
54
  assert(COND)
1 by brian
clean slate
55
56
#define LOG_READ_EOF    -1
57
#define LOG_READ_BOGUS  -2
58
#define LOG_READ_IO     -3
59
#define LOG_READ_MEM    -5
60
#define LOG_READ_TRUNC  -6
61
#define LOG_READ_TOO_LARGE -7
62
63
#define LOG_EVENT_OFFSET 4
64
65
/*
66
   3 is MySQL 4.x; 4 is MySQL 5.0.0.
67
   Compared to version 3, version 4 has:
68
   - a different Start_log_event, which includes info about the binary log
69
   (sizes of headers); this info is included for better compatibility if the
70
   master's MySQL version is different from the slave's.
71
   - all events have a unique ID (the triplet (server_id, timestamp at server
72
   start, other) to be sure an event is not executed more than once in a
73
   multimaster setup, example:
74
                M1
75
              /   \
76
             v     v
77
             M2    M3
78
             \     /
79
              v   v
80
                S
81
   if a query is run on M1, it will arrive twice on S, so we need that S
82
   remembers the last unique ID it has processed, to compare and know if the
83
   event should be skipped or not. Example of ID: we already have the server id
84
   (4 bytes), plus:
85
   timestamp_when_the_master_started (4 bytes), a counter (a sequence number
86
   which increments every time we write an event to the binlog) (3 bytes).
87
   Q: how do we handle when the counter is overflowed and restarts from 0 ?
88
89
   - Query and Load (Create or Execute) events may have a more precise
90
     timestamp (with microseconds), number of matched/affected/warnings rows
91
   and fields of session variables: SQL_MODE,
92
   FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and
93
   charsets, the PASSWORD() version (old/new/...).
94
*/
95
#define BINLOG_VERSION    4
96
97
/*
98
 We could have used SERVER_VERSION_LENGTH, but this introduces an
99
 obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH
100
 this would break the replication protocol
101
*/
102
#define ST_SERVER_VER_LEN 50
103
104
/*
105
  These are flags and structs to handle all the LOAD DATA INFILE options (LINES
106
  TERMINATED etc).
107
*/
108
109
/*
110
  These are flags and structs to handle all the LOAD DATA INFILE options (LINES
111
  TERMINATED etc).
112
  DUMPFILE_FLAG is probably useless (DUMPFILE is a clause of SELECT, not of LOAD
113
  DATA).
114
*/
115
#define DUMPFILE_FLAG		0x1
116
#define OPT_ENCLOSED_FLAG	0x2
117
#define REPLACE_FLAG		0x4
118
#define IGNORE_FLAG		0x8
119
120
#define FIELD_TERM_EMPTY	0x1
121
#define ENCLOSED_EMPTY		0x2
122
#define LINE_TERM_EMPTY		0x4
123
#define LINE_START_EMPTY	0x8
124
#define ESCAPED_EMPTY		0x10
125
126
/*****************************************************************************
127
128
  old_sql_ex struct
129
130
 ****************************************************************************/
131
struct old_sql_ex
132
{
133
  char field_term;
134
  char enclosed;
135
  char line_term;
136
  char line_start;
137
  char escaped;
138
  char opt_flags;
139
  char empty_flags;
140
};
141
142
#define NUM_LOAD_DELIM_STRS 5
143
144
/*****************************************************************************
145
146
  sql_ex_info struct
147
148
 ****************************************************************************/
149
struct sql_ex_info
150
{
151
  sql_ex_info() {}                            /* Remove gcc warning */
152
  const char* field_term;
153
  const char* enclosed;
154
  const char* line_term;
155
  const char* line_start;
156
  const char* escaped;
157
  int cached_new_format;
206 by Brian Aker
Removed final uint dead types.
158
  uint8_t field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len;
1 by brian
clean slate
159
  char opt_flags;
160
  char empty_flags;
161
162
  // store in new format even if old is possible
163
  void force_new_format() { cached_new_format = 1;}
164
  int data_size()
165
  {
166
    return (new_format() ?
167
	    field_term_len + enclosed_len + line_term_len +
168
	    line_start_len + escaped_len + 6 : 7);
169
  }
170
  bool write_data(IO_CACHE* file);
171
  const char* init(const char* buf, const char* buf_end, bool use_new_format);
172
  bool new_format()
173
  {
174
    return ((cached_new_format != -1) ? cached_new_format :
175
	    (cached_new_format=(field_term_len > 1 ||
176
				enclosed_len > 1 ||
177
				line_term_len > 1 || line_start_len > 1 ||
178
				escaped_len > 1)));
179
  }
180
};
181
182
/*****************************************************************************
183
184
  MySQL Binary Log
185
186
  This log consists of events.  Each event has a fixed-length header,
187
  possibly followed by a variable length data body.
188
189
  The data body consists of an optional fixed length segment (post-header)
190
  and  an optional variable length segment.
191
192
  See the #defines below for the format specifics.
193
194
  The events which really update data are Query_log_event,
195
  Execute_load_query_log_event and old Load_log_event and
196
  Execute_load_log_event events (Execute_load_query is used together with
197
  Begin_load_query and Append_block events to replicate LOAD DATA INFILE.
198
  Create_file/Append_block/Execute_load (which includes Load_log_event)
199
  were used to replicate LOAD DATA before the 5.0.3).
200
201
 ****************************************************************************/
202
203
#define LOG_EVENT_HEADER_LEN 19     /* the fixed header length */
204
#define OLD_HEADER_LEN       13     /* the fixed header length in 3.23 */
205
/*
206
   Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
207
   header (it will for sure when we have the unique event's ID), but at least
208
   the first 19 bytes are the same in 4.x and 5.0. So when we have the unique
209
   event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
210
   LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
211
*/
212
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
213
214
/* event-specific post-header sizes */
215
// where 3.23, 4.x and 5.0 agree
216
#define QUERY_HEADER_MINIMAL_LEN     (4 + 4 + 1 + 2)
217
// where 5.0 differs: 2 for len of N-bytes vars.
218
#define QUERY_HEADER_LEN     (QUERY_HEADER_MINIMAL_LEN + 2)
219
#define LOAD_HEADER_LEN      (4 + 4 + 4 + 1 +1 + 4)
220
#define START_V3_HEADER_LEN     (2 + ST_SERVER_VER_LEN + 4)
221
#define ROTATE_HEADER_LEN    8 // this is FROZEN (the Rotate post-header is frozen)
222
#define CREATE_FILE_HEADER_LEN 4
223
#define APPEND_BLOCK_HEADER_LEN 4
224
#define EXEC_LOAD_HEADER_LEN   4
225
#define DELETE_FILE_HEADER_LEN 4
226
#define FORMAT_DESCRIPTION_HEADER_LEN (START_V3_HEADER_LEN+1+LOG_EVENT_TYPES)
227
#define ROWS_HEADER_LEN        8
228
#define TABLE_MAP_HEADER_LEN   8
229
#define EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN (4 + 4 + 4 + 1)
230
#define EXECUTE_LOAD_QUERY_HEADER_LEN  (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN)
231
#define INCIDENT_HEADER_LEN    2
232
#define HEARTBEAT_HEADER_LEN   0
233
/* 
234
  Max number of possible extra bytes in a replication event compared to a
235
  packet (i.e. a query) sent from client to master;
236
  First, an auxiliary log_event status vars estimation:
237
*/
238
#define MAX_SIZE_LOG_EVENT_STATUS (4 /* flags2 */   + \
239
                                   8 /* sql mode */ + \
240
                                   1 + 1 + 255 /* catalog */ + \
241
                                   4 /* autoinc */ + \
242
                                   6 /* charset */ + \
243
                                   MAX_TIME_ZONE_NAME_LENGTH)
244
#define MAX_LOG_EVENT_HEADER   ( /* in order of Query_log_event::write */ \
245
  LOG_EVENT_HEADER_LEN + /* write_header */ \
246
  QUERY_HEADER_LEN     + /* write_data */   \
247
  EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN + /*write_post_header_for_derived */ \
248
  MAX_SIZE_LOG_EVENT_STATUS + /* status */ \
249
  NAME_LEN + 1)
250
251
/* 
252
   Event header offsets; 
253
   these point to places inside the fixed header.
254
*/
255
256
#define EVENT_TYPE_OFFSET    4
257
#define SERVER_ID_OFFSET     5
258
#define EVENT_LEN_OFFSET     9
259
#define LOG_POS_OFFSET       13
260
#define FLAGS_OFFSET         17
261
262
/* start event post-header (for v3 and v4) */
263
264
#define ST_BINLOG_VER_OFFSET  0
265
#define ST_SERVER_VER_OFFSET  2
266
#define ST_CREATED_OFFSET     (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
267
#define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
268
269
/* slave event post-header (this event is never written) */
270
271
#define SL_MASTER_PORT_OFFSET   8
272
#define SL_MASTER_POS_OFFSET    0
273
#define SL_MASTER_HOST_OFFSET   10
274
275
/* query event post-header */
276
277
#define Q_THREAD_ID_OFFSET	0
278
#define Q_EXEC_TIME_OFFSET	4
279
#define Q_DB_LEN_OFFSET		8
280
#define Q_ERR_CODE_OFFSET	9
281
#define Q_STATUS_VARS_LEN_OFFSET 11
282
#define Q_DATA_OFFSET		QUERY_HEADER_LEN
283
/* these are codes, not offsets; not more than 256 values (1 byte). */
284
#define Q_FLAGS2_CODE           0
285
#define Q_SQL_MODE_CODE         1
286
/*
287
  Q_CATALOG_CODE is catalog with end zero stored; it is used only by MySQL
288
  5.0.x where 0<=x<=3. We have to keep it to be able to replicate these
289
  old masters.
290
*/
291
#define Q_CATALOG_CODE          2
292
#define Q_AUTO_INCREMENT	3
293
#define Q_CHARSET_CODE          4
294
#define Q_TIME_ZONE_CODE        5
295
/*
296
  Q_CATALOG_NZ_CODE is catalog withOUT end zero stored; it is used by MySQL
297
  5.0.x where x>=4. Saves one byte in every Query_log_event in binlog,
298
  compared to Q_CATALOG_CODE. The reason we didn't simply re-use
299
  Q_CATALOG_CODE is that then a 5.0.3 slave of this 5.0.x (x>=4) master would
300
  crash (segfault etc) because it would expect a 0 when there is none.
301
*/
302
#define Q_CATALOG_NZ_CODE       6
303
304
#define Q_LC_TIME_NAMES_CODE    7
305
306
#define Q_CHARSET_DATABASE_CODE 8
307
/* Intvar event post-header */
308
309
#define I_TYPE_OFFSET        0
310
#define I_VAL_OFFSET         1
311
312
/* Rand event post-header */
313
314
#define RAND_SEED1_OFFSET 0
315
#define RAND_SEED2_OFFSET 8
316
317
/* User_var event post-header */
318
319
#define UV_VAL_LEN_SIZE        4
320
#define UV_VAL_IS_NULL         1
321
#define UV_VAL_TYPE_SIZE       1
322
#define UV_NAME_LEN_SIZE       4
323
#define UV_CHARSET_NUMBER_SIZE 4
324
325
/* Load event post-header */
326
327
#define L_THREAD_ID_OFFSET   0
328
#define L_EXEC_TIME_OFFSET   4
329
#define L_SKIP_LINES_OFFSET  8
330
#define L_TBL_LEN_OFFSET     12
331
#define L_DB_LEN_OFFSET      13
332
#define L_NUM_FIELDS_OFFSET  14
333
#define L_SQL_EX_OFFSET      18
334
#define L_DATA_OFFSET        LOAD_HEADER_LEN
335
336
/* Rotate event post-header */
337
338
#define R_POS_OFFSET       0
339
#define R_IDENT_OFFSET     8
340
341
/* CF to DF handle LOAD DATA INFILE */
342
343
/* CF = "Create File" */
344
#define CF_FILE_ID_OFFSET  0
345
#define CF_DATA_OFFSET     CREATE_FILE_HEADER_LEN
346
347
/* AB = "Append Block" */
348
#define AB_FILE_ID_OFFSET  0
349
#define AB_DATA_OFFSET     APPEND_BLOCK_HEADER_LEN
350
351
/* EL = "Execute Load" */
352
#define EL_FILE_ID_OFFSET  0
353
354
/* DF = "Delete File" */
355
#define DF_FILE_ID_OFFSET  0
356
357
/* TM = "Table Map" */
358
#define TM_MAPID_OFFSET    0
359
#define TM_FLAGS_OFFSET    6
360
361
/* RW = "RoWs" */
362
#define RW_MAPID_OFFSET    0
363
#define RW_FLAGS_OFFSET    6
364
365
/* ELQ = "Execute Load Query" */
366
#define ELQ_FILE_ID_OFFSET QUERY_HEADER_LEN
367
#define ELQ_FN_POS_START_OFFSET ELQ_FILE_ID_OFFSET + 4
368
#define ELQ_FN_POS_END_OFFSET ELQ_FILE_ID_OFFSET + 8
369
#define ELQ_DUP_HANDLING_OFFSET ELQ_FILE_ID_OFFSET + 12
370
371
/* 4 bytes which all binlogs should begin with */
372
#define BINLOG_MAGIC        "\xfe\x62\x69\x6e"
373
374
/*
375
   This flag only makes sense for Format_description_log_event. It is set
376
   when the event is written, and *reset* when a binlog file is
377
   closed (yes, it's the only case when MySQL modifies already written
378
   part of binlog).  Thus it is a reliable indicator that binlog was
379
   closed correctly.  (Stop_log_event is not enough, there's always a
380
   small chance that mysqld crashes in the middle of insert and end of
381
   the binlog would look like a Stop_log_event).
382
383
   This flag is used to detect a restart after a crash, and to provide
384
   "unbreakable" binlog. The problem is that on a crash storage engines
385
   rollback automatically, while binlog does not.  To solve this we use this
386
   flag and automatically append ROLLBACK to every non-closed binlog (append
387
   virtually, on reading, file itself is not changed). If this flag is found,
388
   mysqlbinlog simply prints "ROLLBACK" Replication master does not abort on
389
   binlog corruption, but takes it as EOF, and replication slave forces a
390
   rollback in this case.
391
392
   Note, that old binlogs does not have this flag set, so we get a
393
   a backward-compatible behaviour.
394
*/
395
396
#define LOG_EVENT_BINLOG_IN_USE_F       0x1
397
398
/**
399
  @def LOG_EVENT_THREAD_SPECIFIC_F
400
401
  If the query depends on the thread (for example: TEMPORARY TABLE).
402
  Currently this is used by mysqlbinlog to know it must print
403
  SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
404
  for every query but this would be slow).
405
*/
406
#define LOG_EVENT_THREAD_SPECIFIC_F 0x4
407
408
/**
409
  @def LOG_EVENT_SUPPRESS_USE_F
410
411
  Suppress the generation of 'USE' statements before the actual
412
  statement. This flag should be set for any events that does not need
413
  the current database set to function correctly. Most notable cases
414
  are 'CREATE DATABASE' and 'DROP DATABASE'.
415
416
  This flags should only be used in exceptional circumstances, since
417
  it introduce a significant change in behaviour regarding the
418
  replication logic together with the flags --binlog-do-db and
419
  --replicated-do-db.
420
 */
421
#define LOG_EVENT_SUPPRESS_USE_F    0x8
422
423
/*
424
  The table map version internal to the log should be increased after
425
  the event has been written to the binary log.
426
 */
427
#define LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F 0x10
428
429
/**
430
  @def OPTIONS_WRITTEN_TO_BIN_LOG
431
432
  OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must
433
  be written to the binlog. OPTIONS_WRITTEN_TO_BIN_LOG could be
434
  written into the Format_description_log_event, so that if later we
435
  don't want to replicate a variable we did replicate, or the
436
  contrary, it's doable. But it should not be too hard to decide once
437
  for all of what we replicate and what we don't, among the fixed 32
438
  bits of thd->options.
439
440
  I (Guilhem) have read through every option's usage, and it looks
441
  like OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only
442
  ones which alter how the query modifies the table. It's good to
443
  replicate OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the
444
  slave may insert data slower than the master, in InnoDB.
445
  OPTION_BIG_SELECTS is not needed (the slave thread runs with
446
  max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
447
  either, as the manual says (because a too big in-memory temp table
448
  is automatically written to disk).
449
*/
450
#define OPTIONS_WRITTEN_TO_BIN_LOG \
451
  (OPTION_AUTO_IS_NULL | OPTION_NO_FOREIGN_KEY_CHECKS |  \
452
   OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NOT_AUTOCOMMIT)
453
454
/* Shouldn't be defined before */
455
#define EXPECTED_OPTIONS \
80.1.1 by Brian Aker
LL() cleanup
456
  ((1ULL << 14) | (1ULL << 26) | (1ULL << 27) | (1ULL << 19))
1 by brian
clean slate
457
458
#if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
459
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
460
#endif
461
#undef EXPECTED_OPTIONS         /* You shouldn't use this one */
462
463
/**
464
  @enum Log_event_type
465
466
  Enumeration type for the different types of log events.
467
*/
468
enum Log_event_type
469
{
470
  /*
471
    Every time you update this enum (when you add a type), you have to
472
    fix Format_description_log_event::Format_description_log_event().
473
  */
474
  UNKNOWN_EVENT= 0,
475
  START_EVENT_V3= 1,
476
  QUERY_EVENT= 2,
477
  STOP_EVENT= 3,
478
  ROTATE_EVENT= 4,
479
  INTVAR_EVENT= 5,
480
  LOAD_EVENT= 6,
481
  SLAVE_EVENT= 7,
482
  CREATE_FILE_EVENT= 8,
483
  APPEND_BLOCK_EVENT= 9,
484
  EXEC_LOAD_EVENT= 10,
485
  DELETE_FILE_EVENT= 11,
486
  /*
487
    NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer
488
    sql_ex, allowing multibyte TERMINATED BY etc; both types share the
489
    same class (Load_log_event)
490
  */
491
  NEW_LOAD_EVENT= 12,
492
  RAND_EVENT= 13,
493
  USER_VAR_EVENT= 14,
494
  FORMAT_DESCRIPTION_EVENT= 15,
495
  XID_EVENT= 16,
496
  BEGIN_LOAD_QUERY_EVENT= 17,
497
  EXECUTE_LOAD_QUERY_EVENT= 18,
498
499
  TABLE_MAP_EVENT = 19,
500
501
  /*
502
    These event numbers were used for 5.1.0 to 5.1.15 and are
503
    therefore obsolete.
504
   */
505
  PRE_GA_WRITE_ROWS_EVENT = 20,
506
  PRE_GA_UPDATE_ROWS_EVENT = 21,
507
  PRE_GA_DELETE_ROWS_EVENT = 22,
508
509
  /*
510
    These event numbers are used from 5.1.16 and forward
511
   */
512
  WRITE_ROWS_EVENT = 23,
513
  UPDATE_ROWS_EVENT = 24,
514
  DELETE_ROWS_EVENT = 25,
515
516
  /*
517
    Something out of the ordinary happened on the master
518
   */
519
  INCIDENT_EVENT= 26,
520
521
  /*
522
    Heartbeat event to be send by master at its idle time 
523
    to ensure master's online status to slave 
524
  */
525
  HEARTBEAT_LOG_EVENT= 27,
526
  
527
  /*
528
    Add new events here - right above this comment!
529
    Existing events (except ENUM_END_EVENT) should never change their numbers
530
  */
531
532
  ENUM_END_EVENT /* end marker */
533
};
534
535
/*
536
   The number of types we handle in Format_description_log_event (UNKNOWN_EVENT
537
   is not to be handled, it does not exist in binlogs, it does not have a
538
   format).
539
*/
540
#define LOG_EVENT_TYPES (ENUM_END_EVENT-1)
541
542
enum Int_event_type
543
{
544
  INVALID_INT_EVENT = 0, LAST_INSERT_ID_EVENT = 1, INSERT_ID_EVENT = 2
545
};
546
547
548
#ifndef MYSQL_CLIENT
549
class String;
550
class MYSQL_BIN_LOG;
551
class THD;
552
#endif
553
554
class Format_description_log_event;
555
class Relay_log_info;
556
557
#ifdef MYSQL_CLIENT
558
enum enum_base64_output_mode {
559
  BASE64_OUTPUT_NEVER= 0,
560
  BASE64_OUTPUT_AUTO= 1,
561
  BASE64_OUTPUT_ALWAYS= 2,
562
  BASE64_OUTPUT_UNSPEC= 3,
563
  /* insert new output modes here */
564
  BASE64_OUTPUT_MODE_COUNT
565
};
566
567
/*
568
  A structure for mysqlbinlog to know how to print events
569
570
  This structure is passed to the event's print() methods,
571
572
  There are two types of settings stored here:
573
  1. Last db, flags2, sql_mode etc comes from the last printed event.
574
     They are stored so that only the necessary USE and SET commands
575
     are printed.
576
  2. Other information on how to print the events, e.g. short_form,
577
     hexdump_from.  These are not dependent on the last event.
578
*/
579
typedef struct st_print_event_info
580
{
581
  /*
582
    Settings for database, sql_mode etc that comes from the last event
583
    that was printed.  We cache these so that we don't have to print
584
    them if they are unchanged.
585
  */
586
  // TODO: have the last catalog here ??
587
  char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is
588
  bool flags2_inited;
205 by Brian Aker
uint32 -> uin32_t
589
  uint32_t flags2;
1 by brian
clean slate
590
  bool sql_mode_inited;
591
  ulong sql_mode;		/* must be same as THD.variables.sql_mode */
592
  ulong auto_increment_increment, auto_increment_offset;
593
  bool charset_inited;
594
  char charset[6]; // 3 variables, each of them storable in 2 bytes
595
  char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
596
  uint lc_time_names_number;
597
  uint charset_database_number;
598
  uint thread_id;
599
  bool thread_id_printed;
600
601
  st_print_event_info();
602
603
  ~st_print_event_info() {
604
    close_cached_file(&head_cache);
605
    close_cached_file(&body_cache);
606
  }
607
  bool init_ok() /* tells if construction was successful */
608
    { return my_b_inited(&head_cache) && my_b_inited(&body_cache); }
609
610
611
  /* Settings on how to print the events */
612
  bool short_form;
613
  enum_base64_output_mode base64_output_mode;
614
  /*
615
    This is set whenever a Format_description_event is printed.
616
    Later, when an event is printed in base64, this flag is tested: if
617
    no Format_description_event has been seen, it is unsafe to print
618
    the base64 event, so an error message is generated.
619
  */
620
  bool printed_fd_event;
621
  my_off_t hexdump_from;
206 by Brian Aker
Removed final uint dead types.
622
  uint8_t common_header_len;
1 by brian
clean slate
623
  char delimiter[16];
624
625
  /*
626
     These two caches are used by the row-based replication events to
627
     collect the header information and the main body of the events
628
     making up a statement.
629
   */
630
  IO_CACHE head_cache;
631
  IO_CACHE body_cache;
632
} PRINT_EVENT_INFO;
633
#endif
634
635
/**
636
  the struct aggregates two paramenters that identify an event
637
  uniquely in scope of communication of a particular master and slave couple.
638
  I.e there can not be 2 events from the same staying connected master which
639
  have the same coordinates.
640
  @note
641
  Such identifier is not yet unique generally as the event originating master
642
  is resetable. Also the crashed master can be replaced with some other.
643
*/
644
struct event_coordinates
645
{
646
  char * file_name; // binlog file name (directories stripped)
647
  my_off_t  pos;       // event's position in the binlog file
648
};
649
650
/**
651
  @class Log_event
652
653
  This is the abstract base class for binary log events.
654
  
655
  @section Log_event_binary_format Binary Format
656
657
  Any @c Log_event saved on disk consists of the following three
658
  components.
659
660
  - Common-Header
661
  - Post-Header
662
  - Body
663
664
  The Common-Header, documented in the table @ref Table_common_header
665
  "below", always has the same form and length within one version of
666
  MySQL.  Each event type specifies a format and length of the
667
  Post-Header.  The length of the Common-Header is the same for all
668
  events of the same type.  The Body may be of different format and
669
  length even for different events of the same type.  The binary
670
  formats of Post-Header and Body are documented separately in each
671
  subclass.  The binary format of Common-Header is as follows.
672
673
  <table>
674
  <caption>Common-Header</caption>
675
676
  <tr>
677
    <th>Name</th>
678
    <th>Format</th>
679
    <th>Description</th>
680
  </tr>
681
682
  <tr>
683
    <td>timestamp</td>
684
    <td>4 byte unsigned integer</td>
685
    <td>The time when the query started, in seconds since 1970.
686
    </td>
687
  </tr>
688
689
  <tr>
690
    <td>type</td>
691
    <td>1 byte enumeration</td>
692
    <td>See enum #Log_event_type.</td>
693
  </tr>
694
695
  <tr>
696
    <td>server_id</td>
697
    <td>4 byte unsigned integer</td>
698
    <td>Server ID of the server that created the event.</td>
699
  </tr>
700
701
  <tr>
702
    <td>total_size</td>
703
    <td>4 byte unsigned integer</td>
704
    <td>The total size of this event, in bytes.  In other words, this
705
    is the sum of the sizes of Common-Header, Post-Header, and Body.
706
    </td>
707
  </tr>
708
709
  <tr>
710
    <td>master_position</td>
711
    <td>4 byte unsigned integer</td>
712
    <td>The position of the next event in the master binary log, in
713
    bytes from the beginning of the file.  In a binlog that is not a
714
    relay log, this is just the position of the next event, in bytes
715
    from the beginning of the file.  In a relay log, this is
716
    the position of the next event in the master's binlog.
717
    </td>
718
  </tr>
719
720
  <tr>
721
    <td>flags</td>
722
    <td>2 byte bitfield</td>
723
    <td>See Log_event::flags.</td>
724
  </tr>
725
  </table>
726
727
  Summing up the numbers above, we see that the total size of the
728
  common header is 19 bytes.
729
730
  @subsection Log_event_format_of_atomic_primitives Format of Atomic Primitives
731
732
  - All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers,
733
  are stored in little endian, i.e., the least significant byte first,
734
  unless otherwise specified.
735
736
  @anchor packed_integer
737
  - Some events use a special format for efficient representation of
738
  unsigned integers, called Packed Integer.  A Packed Integer has the
739
  capacity of storing up to 8-byte integers, while small integers
740
  still can use 1, 3, or 4 bytes.  The value of the first byte
741
  determines how to read the number, according to the following table:
742
743
  <table>
744
  <caption>Format of Packed Integer</caption>
745
746
  <tr>
747
    <th>First byte</th>
748
    <th>Format</th>
749
  </tr>
750
751
  <tr>
752
    <td>0-250</td>
753
    <td>The first byte is the number (in the range 0-250), and no more
754
    bytes are used.</td>
755
  </tr>
756
757
  <tr>
758
    <td>252</td>
759
    <td>Two more bytes are used.  The number is in the range
760
    251-0xffff.</td>
761
  </tr>
762
763
  <tr>
764
    <td>253</td>
765
    <td>Three more bytes are used.  The number is in the range
766
    0xffff-0xffffff.</td>
767
  </tr>
768
769
  <tr>
770
    <td>254</td>
771
    <td>Eight more bytes are used.  The number is in the range
772
    0xffffff-0xffffffffffffffff.</td>
773
  </tr>
774
775
  </table>
776
777
  - Strings are stored in various formats.  The format of each string
778
  is documented separately.
779
*/
780
class Log_event
781
{
782
public:
783
  /**
784
     Enumeration of what kinds of skipping (and non-skipping) that can
785
     occur when the slave executes an event.
786
787
     @see shall_skip
788
     @see do_shall_skip
789
   */
790
  enum enum_skip_reason {
791
    /**
792
       Don't skip event.
793
    */
794
    EVENT_SKIP_NOT,
795
796
    /**
797
       Skip event by ignoring it.
798
799
       This means that the slave skip counter will not be changed.
800
    */
801
    EVENT_SKIP_IGNORE,
802
803
    /**
804
       Skip event and decrease skip counter.
805
    */
806
    EVENT_SKIP_COUNT
807
  };
808
809
810
  /*
811
    The following type definition is to be used whenever data is placed 
812
    and manipulated in a common buffer. Use this typedef for buffers
813
    that contain data containing binary and character data.
814
  */
815
  typedef unsigned char Byte;
816
817
  /*
818
    The offset in the log where this event originally appeared (it is
819
    preserved in relay logs, making SHOW SLAVE STATUS able to print
820
    coordinates of the event in the master's binlog). Note: when a
821
    transaction is written by the master to its binlog (wrapped in
822
    BEGIN/COMMIT) the log_pos of all the queries it contains is the
823
    one of the BEGIN (this way, when one does SHOW SLAVE STATUS it
824
    sees the offset of the BEGIN, which is logical as rollback may
825
    occur), except the COMMIT query which has its real offset.
826
  */
827
  my_off_t log_pos;
828
  /*
829
     A temp buffer for read_log_event; it is later analysed according to the
830
     event's type, and its content is distributed in the event-specific fields.
831
  */
832
  char *temp_buf;
833
  /*
834
    Timestamp on the master(for debugging and replication of
835
    NOW()/TIMESTAMP).  It is important for queries and LOAD DATA
836
    INFILE. This is set at the event's creation time, except for Query
837
    and Load (et al.) events where this is set at the query's
838
    execution time, which guarantees good replication (otherwise, we
839
    could have a query and its event with different timestamps).
840
  */
841
  time_t when;
842
  /* The number of seconds the query took to run on the master. */
843
  ulong exec_time;
844
  /* Number of bytes written by write() function */
845
  ulong data_written;
846
847
  /*
848
    The master's server id (is preserved in the relay log; used to
849
    prevent from infinite loops in circular replication).
850
  */
205 by Brian Aker
uint32 -> uin32_t
851
  uint32_t server_id;
1 by brian
clean slate
852
853
  /**
854
    Some 16 flags. See the definitions above for LOG_EVENT_TIME_F,
855
    LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
856
    LOG_EVENT_SUPPRESS_USE_F for notes.
857
  */
206 by Brian Aker
Removed final uint dead types.
858
  uint16_t flags;
1 by brian
clean slate
859
860
  bool cache_stmt;
861
862
  /**
863
    A storage to cache the global system variable's value.
864
    Handling of a separate event will be governed its member.
865
  */
866
  ulong slave_exec_mode;
867
868
#ifndef MYSQL_CLIENT
869
  THD* thd;
870
871
  Log_event();
206 by Brian Aker
Removed final uint dead types.
872
  Log_event(THD* thd_arg, uint16_t flags_arg, bool cache_stmt);
1 by brian
clean slate
873
  /*
874
    read_log_event() functions read an event from a binlog or relay
875
    log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
876
    master (reads master's binlog), the slave IO thread (reads the
877
    event sent by binlog_dump), the slave SQL thread (reads the event
878
    from the relay log).  If mutex is 0, the read will proceed without
879
    mutex.  We need the description_event to be able to parse the
880
    event (to know the post-header's size); in fact in read_log_event
881
    we detect the event's type, then call the specific event's
882
    constructor and pass description_event as an argument.
883
  */
884
  static Log_event* read_log_event(IO_CACHE* file,
885
				   pthread_mutex_t* log_lock,
886
                                   const Format_description_log_event
887
                                   *description_event);
888
  static int read_log_event(IO_CACHE* file, String* packet,
889
			    pthread_mutex_t* log_lock);
890
  /*
891
    init_show_field_list() prepares the column names and types for the
892
    output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
893
    EVENTS.
894
  */
895
  static void init_show_field_list(List<Item>* field_list);
896
#ifdef HAVE_REPLICATION
897
  int net_send(Protocol *protocol, const char* log_name, my_off_t pos);
898
899
  /*
900
    pack_info() is used by SHOW BINLOG EVENTS; as print() it prepares and sends
901
    a string to display to the user, so it resembles print().
902
  */
903
904
  virtual void pack_info(Protocol *protocol);
905
906
#endif /* HAVE_REPLICATION */
907
  virtual const char* get_db()
908
  {
909
    return thd ? thd->db : 0;
910
  }
911
#else
912
  Log_event() : temp_buf(0) {}
913
    /* avoid having to link mysqlbinlog against libpthread */
914
  static Log_event* read_log_event(IO_CACHE* file,
915
                                   const Format_description_log_event
916
                                   *description_event);
917
  /* print*() functions are used by mysqlbinlog */
918
  virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
919
  void print_timestamp(IO_CACHE* file, time_t *ts = 0);
920
  void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
921
                    bool is_more);
922
  void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
923
                    bool is_more);
924
#endif
925
926
  static void *operator new(size_t size)
927
  {
928
    return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE));
929
  }
930
53.2.4 by Monty Taylor
Changes so that client/ builds cleanly with no warnings.
931
  static void operator delete(void *ptr,
932
                              size_t size __attribute__((__unused__)))
1 by brian
clean slate
933
  {
934
    my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
935
  }
936
937
  /* Placement version of the above operators */
938
  static void *operator new(size_t, void* ptr) { return ptr; }
939
  static void operator delete(void*, void*) { }
940
941
#ifndef MYSQL_CLIENT
942
  bool write_header(IO_CACHE* file, ulong data_length);
943
  virtual bool write(IO_CACHE* file)
944
  {
945
    return (write_header(file, get_data_size()) ||
946
            write_data_header(file) ||
947
            write_data_body(file));
948
  }
77.1.7 by Monty Taylor
Heap builds clean.
949
  virtual bool write_data_header(IO_CACHE* file __attribute__((__unused__)))
1 by brian
clean slate
950
  { return 0; }
951
  virtual bool write_data_body(IO_CACHE* file __attribute__((unused)))
952
  { return 0; }
953
  inline time_t get_time()
954
  {
955
    THD *tmp_thd;
956
    if (when)
957
      return when;
958
    if (thd)
959
      return thd->start_time;
960
    if ((tmp_thd= current_thd))
961
      return tmp_thd->start_time;
962
    return my_time(0);
963
  }
964
#endif
965
  virtual Log_event_type get_type_code() = 0;
966
  virtual bool is_valid() const = 0;
967
  virtual bool is_artificial_event() { return 0; }
968
  inline bool get_cache_stmt() const { return cache_stmt; }
969
  Log_event(const char* buf, const Format_description_log_event
970
            *description_event);
971
  virtual ~Log_event() { free_temp_buf();}
972
  void register_temp_buf(char* buf) { temp_buf = buf; }
973
  void free_temp_buf()
974
  {
975
    if (temp_buf)
976
    {
977
      my_free(temp_buf, MYF(0));
978
      temp_buf = 0;
979
    }
980
  }
981
  /*
982
    Get event length for simple events. For complicated events the length
983
    is calculated during write()
984
  */
985
  virtual int get_data_size() { return 0;}
986
  static Log_event* read_log_event(const char* buf, uint event_len,
987
				   const char **error,
988
                                   const Format_description_log_event
989
                                   *description_event);
990
  /**
991
    Returns the human readable name of the given event type.
992
  */
993
  static const char* get_type_str(Log_event_type type);
994
  /**
995
    Returns the human readable name of this event's type.
996
  */
997
  const char* get_type_str();
998
999
  /* Return start of query time or current time */
1000
1001
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1002
public:
1003
1004
  /**
1005
     Apply the event to the database.
1006
1007
     This function represents the public interface for applying an
1008
     event.
1009
1010
     @see do_apply_event
1011
   */
1012
  int apply_event(Relay_log_info const *rli)
1013
  {
1014
    return do_apply_event(rli);
1015
  }
1016
1017
1018
  /**
1019
     Update the relay log position.
1020
1021
     This function represents the public interface for "stepping over"
1022
     the event and will update the relay log information.
1023
1024
     @see do_update_pos
1025
   */
1026
  int update_pos(Relay_log_info *rli)
1027
  {
1028
    return do_update_pos(rli);
1029
  }
1030
1031
  /**
1032
     Decide if the event shall be skipped, and the reason for skipping
1033
     it.
1034
1035
     @see do_shall_skip
1036
   */
1037
  enum_skip_reason shall_skip(Relay_log_info *rli)
1038
  {
1039
    return do_shall_skip(rli);
1040
  }
1041
1042
protected:
1043
1044
  /**
1045
     Helper function to ignore an event w.r.t. the slave skip counter.
1046
1047
     This function can be used inside do_shall_skip() for functions
1048
     that cannot end a group. If the slave skip counter is 1 when
1049
     seeing such an event, the event shall be ignored, the counter
1050
     left intact, and processing continue with the next event.
1051
1052
     A typical usage is:
1053
     @code
1054
     enum_skip_reason do_shall_skip(Relay_log_info *rli) {
1055
       return continue_group(rli);
1056
     }
1057
     @endcode
1058
1059
     @return Skip reason
1060
   */
1061
  enum_skip_reason continue_group(Relay_log_info *rli);
1062
1063
  /**
1064
    Primitive to apply an event to the database.
1065
1066
    This is where the change to the database is made.
1067
1068
    @note The primitive is protected instead of private, since there
1069
    is a hierarchy of actions to be performed in some cases.
1070
1071
    @see Format_description_log_event::do_apply_event()
1072
1073
    @param rli Pointer to relay log info structure
1074
1075
    @retval 0     Event applied successfully
1076
    @retval errno Error code if event application failed
1077
  */
77.1.7 by Monty Taylor
Heap builds clean.
1078
  virtual int do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
1 by brian
clean slate
1079
  {
1080
    return 0;                /* Default implementation does nothing */
1081
  }
1082
1083
1084
  /**
1085
     Advance relay log coordinates.
1086
1087
     This function is called to advance the relay log coordinates to
1088
     just after the event.  It is essential that both the relay log
1089
     coordinate and the group log position is updated correctly, since
1090
     this function is used also for skipping events.
1091
1092
     Normally, each implementation of do_update_pos() shall:
1093
1094
     - Update the event position to refer to the position just after
1095
       the event.
1096
1097
     - Update the group log position to refer to the position just
1098
       after the event <em>if the event is last in a group</em>
1099
1100
     @param rli Pointer to relay log info structure
1101
1102
     @retval 0     Coordinates changed successfully
1103
     @retval errno Error code if advancing failed (usually just
1104
                   1). Observe that handler errors are returned by the
1105
                   do_apply_event() function, and not by this one.
1106
   */
1107
  virtual int do_update_pos(Relay_log_info *rli);
1108
1109
1110
  /**
1111
     Decide if this event shall be skipped or not and the reason for
1112
     skipping it.
1113
1114
     The default implementation decide that the event shall be skipped
1115
     if either:
1116
1117
     - the server id of the event is the same as the server id of the
1118
       server and <code>rli->replicate_same_server_id</code> is true,
1119
       or
1120
1121
     - if <code>rli->slave_skip_counter</code> is greater than zero.
1122
1123
     @see do_apply_event
1124
     @see do_update_pos
1125
1126
     @retval Log_event::EVENT_SKIP_NOT
1127
     The event shall not be skipped and should be applied.
1128
1129
     @retval Log_event::EVENT_SKIP_IGNORE
1130
     The event shall be skipped by just ignoring it, i.e., the slave
1131
     skip counter shall not be changed. This happends if, for example,
1132
     the originating server id of the event is the same as the server
1133
     id of the slave.
1134
1135
     @retval Log_event::EVENT_SKIP_COUNT
1136
     The event shall be skipped because the slave skip counter was
1137
     non-zero. The caller shall decrease the counter by one.
1138
   */
1139
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1140
#endif
1141
};
1142
1143
1144
/*
1145
   One class for each type of event.
1146
   Two constructors for each class:
1147
   - one to create the event for logging (when the server acts as a master),
1148
   called after an update to the database is done,
1149
   which accepts parameters like the query, the database, the options for LOAD
1150
   DATA INFILE...
1151
   - one to create the event from a packet (when the server acts as a slave),
1152
   called before reproducing the update, which accepts parameters (like a
1153
   buffer). Used to read from the master, from the relay log, and in
1154
   mysqlbinlog. This constructor must be format-tolerant.
1155
*/
1156
1157
/**
1158
  @class Query_log_event
1159
   
1160
  A @c Query_log_event is created for each query that modifies the
1161
  database, unless the query is logged row-based.
1162
1163
  @section Query_log_event_binary_format Binary format
1164
1165
  See @ref Log_event_binary_format "Binary format for log events" for
1166
  a general discussion and introduction to the binary format of binlog
1167
  events.
1168
1169
  The Post-Header has five components:
1170
1171
  <table>
1172
  <caption>Post-Header for Query_log_event</caption>
1173
1174
  <tr>
1175
    <th>Name</th>
1176
    <th>Format</th>
1177
    <th>Description</th>
1178
  </tr>
1179
1180
  <tr>
1181
    <td>slave_proxy_id</td>
1182
    <td>4 byte unsigned integer</td>
1183
    <td>An integer identifying the client thread that issued the
1184
    query.  The id is unique per server.  (Note, however, that two
1185
    threads on different servers may have the same slave_proxy_id.)
1186
    This is used when a client thread creates a temporary table local
1187
    to the client.  The slave_proxy_id is used to distinguish
1188
    temporary tables that belong to different clients.
1189
    </td>
1190
  </tr>
1191
1192
  <tr>
1193
    <td>exec_time</td>
1194
    <td>4 byte unsigned integer</td>
1195
    <td>The time from when the query started to when it was logged in
1196
    the binlog, in seconds.</td>
1197
  </tr>
1198
1199
  <tr>
1200
    <td>db_len</td>
1201
    <td>1 byte integer</td>
1202
    <td>The length of the name of the currently selected database.</td>
1203
  </tr>
1204
1205
  <tr>
1206
    <td>error_code</td>
1207
    <td>2 byte unsigned integer</td>
1208
    <td>Error code generated by the master.  If the master fails, the
1209
    slave will fail with the same error code, except for the error
1210
    codes ER_DB_CREATE_EXISTS == 1007 and ER_DB_DROP_EXISTS == 1008.
1211
    </td>
1212
  </tr>
1213
1214
  <tr>
1215
    <td>status_vars_len</td>
1216
    <td>2 byte unsigned integer</td>
1217
    <td>The length of the status_vars block of the Body, in bytes. See
1218
    @ref query_log_event_status_vars "below".
1219
    </td>
1220
  </tr>
1221
  </table>
1222
1223
  The Body has the following components:
1224
1225
  <table>
1226
  <caption>Body for Query_log_event</caption>
1227
1228
  <tr>
1229
    <th>Name</th>
1230
    <th>Format</th>
1231
    <th>Description</th>
1232
  </tr>
1233
1234
  <tr>
1235
    <td>@anchor query_log_event_status_vars status_vars</td>
1236
    <td>status_vars_len bytes</td>
1237
    <td>Zero or more status variables.  Each status variable consists
1238
    of one byte identifying the variable stored, followed by the value
1239
    of the variable.  The possible variables are listed separately in
1240
    the table @ref Table_query_log_event_status_vars "below".  MySQL
1241
    always writes events in the order defined below; however, it is
1242
    capable of reading them in any order.  </td>
1243
  </tr>
1244
1245
  <tr>
1246
    <td>db</td>
1247
    <td>db_len+1</td>
1248
    <td>The currently selected database, as a null-terminated string.
1249
1250
    (The trailing zero is redundant since the length is already known;
1251
    it is db_len from Post-Header.)
1252
    </td>
1253
  </tr>
1254
1255
  <tr>
1256
    <td>query</td>
1257
    <td>variable length string without trailing zero, extending to the
1258
    end of the event (determined by the length field of the
1259
    Common-Header)
1260
    </td>
1261
    <td>The SQL query.</td>
1262
  </tr>
1263
  </table>
1264
1265
  The following table lists the status variables that may appear in
1266
  the status_vars field.
1267
1268
  @anchor Table_query_log_event_status_vars
1269
  <table>
1270
  <caption>Status variables for Query_log_event</caption>
1271
1272
  <tr>
1273
    <th>Status variable</th>
1274
    <th>1 byte identifier</th>
1275
    <th>Format</th>
1276
    <th>Description</th>
1277
  </tr>
1278
1279
  <tr>
1280
    <td>flags2</td>
1281
    <td>Q_FLAGS2_CODE == 0</td>
1282
    <td>4 byte bitfield</td>
1283
    <td>The flags in @c thd->options, binary AND-ed with @c
1284
    OPTIONS_WRITTEN_TO_BIN_LOG.  The @c thd->options bitfield contains
1285
    options for "SELECT".  @c OPTIONS_WRITTEN identifies those options
1286
    that need to be written to the binlog (not all do).  Specifically,
1287
    @c OPTIONS_WRITTEN_TO_BIN_LOG equals (@c OPTION_AUTO_IS_NULL | @c
1288
    OPTION_NO_FOREIGN_KEY_CHECKS | @c OPTION_RELAXED_UNIQUE_CHECKS |
1289
    @c OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex.
1290
1291
    These flags correspond to the SQL variables SQL_AUTO_IS_NULL,
1292
    FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and AUTOCOMMIT, documented in
1293
    the "SET Syntax" section of the MySQL Manual.
1294
1295
    This field is always written to the binlog in version >= 5.0, and
1296
    never written in version < 5.0.
1297
    </td>
1298
  </tr>
1299
1300
  <tr>
1301
    <td>sql_mode</td>
1302
    <td>Q_SQL_MODE_CODE == 1</td>
1303
    <td>8 byte bitfield</td>
1304
    <td>The @c sql_mode variable.  See the section "SQL Modes" in the
1305
    MySQL manual, and see mysql_priv.h for a list of the possible
1306
    flags. Currently (2007-10-04), the following flags are available:
1307
    <pre>
1308
    MODE_REAL_AS_FLOAT==0x1
1309
    MODE_PIPES_AS_CONCAT==0x2
1310
    MODE_ANSI_QUOTES==0x4
1311
    MODE_IGNORE_SPACE==0x8
1312
    MODE_NOT_USED==0x10
1313
    MODE_ONLY_FULL_GROUP_BY==0x20
1314
    MODE_NO_UNSIGNED_SUBTRACTION==0x40
1315
    MODE_NO_DIR_IN_CREATE==0x80
1316
    MODE_POSTGRESQL==0x100
1317
    MODE_ORACLE==0x200
1318
    MODE_MSSQL==0x400
1319
    MODE_DB2==0x800
1320
    MODE_MAXDB==0x1000
1321
    MODE_NO_KEY_OPTIONS==0x2000
1322
    MODE_NO_TABLE_OPTIONS==0x4000
1323
    MODE_NO_FIELD_OPTIONS==0x8000
1324
    MODE_MYSQL323==0x10000
1325
    MODE_MYSQL323==0x20000
1326
    MODE_MYSQL40==0x40000
1327
    MODE_ANSI==0x80000
1328
    MODE_NO_AUTO_VALUE_ON_ZERO==0x100000
1329
    MODE_NO_BACKSLASH_ESCAPES==0x200000
1330
    MODE_STRICT_TRANS_TABLES==0x400000
1331
    MODE_STRICT_ALL_TABLES==0x800000
1332
    MODE_NO_ZERO_IN_DATE==0x1000000
1333
    MODE_NO_ZERO_DATE==0x2000000
1334
    MODE_INVALID_DATES==0x4000000
1335
    MODE_ERROR_FOR_DIVISION_BY_ZERO==0x8000000
1336
    MODE_TRADITIONAL==0x10000000
1337
    MODE_NO_AUTO_CREATE_USER==0x20000000
1338
    MODE_HIGH_NOT_PRECEDENCE==0x40000000
1339
    MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000
1340
    </pre>
1341
    All these flags are replicated from the server.  However, all
1342
    flags except @c MODE_NO_DIR_IN_CREATE are honored by the slave;
1343
    the slave always preserves its old value of @c
1344
    MODE_NO_DIR_IN_CREATE.  For a rationale, see comment in
1345
    @c Query_log_event::do_apply_event in @c log_event.cc.
1346
1347
    This field is always written to the binlog.
1348
    </td>
1349
  </tr>
1350
1351
  <tr>
1352
    <td>catalog</td>
1353
    <td>Q_CATALOG_NZ_CODE == 6</td>
1354
    <td>Variable-length string: the length in bytes (1 byte) followed
1355
    by the characters (at most 255 bytes)
1356
    </td>
1357
    <td>Stores the client's current catalog.  Every database belongs
1358
    to a catalog, the same way that every table belongs to a
1359
    database.  Currently, there is only one catalog, "std".
1360
1361
    This field is written if the length of the catalog is > 0;
1362
    otherwise it is not written.
1363
    </td>
1364
  </tr>
1365
1366
  <tr>
1367
    <td>auto_increment</td>
1368
    <td>Q_AUTO_INCREMENT == 3</td>
1369
    <td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
1370
1371
    <td>The two variables auto_increment_increment and
1372
    auto_increment_offset, in that order.  For more information, see
1373
    "System variables" in the MySQL manual.
1374
1375
    This field is written if auto_increment > 1.  Otherwise, it is not
1376
    written.
1377
    </td>
1378
  </tr>
1379
1380
  <tr>
1381
    <td>charset</td>
1382
    <td>Q_CHARSET_CODE == 4</td>
1383
    <td>three 2 byte unsigned integers, totally 2+2+2=6 bytes</td>
1384
    <td>The three variables character_set_client,
1385
    collation_connection, and collation_server, in that order.
1386
    character_set_client is a code identifying the character set and
1387
    collation used by the client to encode the query.
1388
    collation_connection identifies the character set and collation
1389
    that the master converts the query to when it receives it; this is
1390
    useful when comparing literal strings.  collation_server is the
1391
    default character set and collation used when a new database is
1392
    created.
1393
1394
    See also "Connection Character Sets and Collations" in the MySQL
1395
    5.1 manual.
1396
1397
    All three variables are codes identifying a (character set,
1398
    collation) pair.  To see which codes map to which pairs, run the
1399
    query "SELECT id, character_set_name, collation_name FROM
1400
    COLLATIONS".
1401
1402
    Cf. Q_CHARSET_DATABASE_CODE below.
1403
1404
    This field is always written.
1405
    </td>
1406
  </tr>
1407
1408
  <tr>
1409
    <td>time_zone</td>
1410
    <td>Q_TIME_ZONE_CODE == 5</td>
1411
    <td>Variable-length string: the length in bytes (1 byte) followed
1412
    by the characters (at most 255 bytes).
1413
    <td>The time_zone of the master.
1414
1415
    See also "System Variables" and "MySQL Server Time Zone Support"
1416
    in the MySQL manual.
1417
1418
    This field is written if the length of the time zone string is >
1419
    0; otherwise, it is not written.
1420
    </td>
1421
  </tr>
1422
1423
  <tr>
1424
    <td>lc_time_names_number</td>
1425
    <td>Q_LC_TIME_NAMES_CODE == 7</td>
1426
    <td>2 byte integer</td>
1427
    <td>A code identifying a table of month and day names.  The
1428
    mapping from codes to languages is defined in @c sql_locale.cc.
1429
1430
    This field is written if it is not 0, i.e., if the locale is not
1431
    en_US.
1432
    </td>
1433
  </tr>
1434
1435
  <tr>
1436
    <td>charset_database_number</td>
1437
    <td>Q_CHARSET_DATABASE_CODE == 8</td>
1438
    <td>2 byte integer</td>
1439
1440
    <td>The value of the collation_database system variable (in the
1441
    source code stored in @c thd->variables.collation_database), which
1442
    holds the code for a (character set, collation) pair as described
1443
    above (see Q_CHARSET_CODE).
1444
1445
    collation_database was used in old versions (???WHEN).  Its value
1446
    was loaded when issuing a "use db" query and could be changed by
1447
    issuing a "SET collation_database=xxx" query.  It used to affect
1448
    the "LOAD DATA INFILE" and "CREATE TABLE" commands.
1449
1450
    In newer versions, "CREATE TABLE" has been changed to take the
1451
    character set from the database of the created table, rather than
1452
    the character set of the current database.  This makes a
1453
    difference when creating a table in another database than the
1454
    current one.  "LOAD DATA INFILE" has not yet changed to do this,
1455
    but there are plans to eventually do it, and to make
1456
    collation_database read-only.
1457
1458
    This field is written if it is not 0.
1459
    </td>
1460
  </tr>
1461
  </table>
1462
1463
  @subsection Query_log_event_notes_on_previous_versions Notes on Previous Versions
1464
1465
  * Status vars were introduced in version 5.0.  To read earlier
1466
  versions correctly, check the length of the Post-Header.
1467
1468
  * The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x,
1469
  where 0<=x<=3.  It was identical to Q_CATALOG_CODE, except that the
1470
  string had a trailing '\0'.  The '\0' was removed in 5.0.4 since it
1471
  was redundant (the string length is stored before the string).  The
1472
  Q_CATALOG_CODE will never be written by a new master, but can still
1473
  be understood by a new slave.
1474
1475
  * See Q_CHARSET_DATABASE_CODE in the table above.
1476
1477
*/
1478
class Query_log_event: public Log_event
1479
{
1480
protected:
1481
  Log_event::Byte* data_buf;
1482
public:
1483
  const char* query;
1484
  const char* catalog;
1485
  const char* db;
1486
  /*
1487
    If we already know the length of the query string
1488
    we pass it with q_len, so we would not have to call strlen()
1489
    otherwise, set it to 0, in which case, we compute it with strlen()
1490
  */
205 by Brian Aker
uint32 -> uin32_t
1491
  uint32_t q_len;
1492
  uint32_t db_len;
206 by Brian Aker
Removed final uint dead types.
1493
  uint16_t error_code;
1 by brian
clean slate
1494
  ulong thread_id;
1495
  /*
1496
    For events created by Query_log_event::do_apply_event (and
1497
    Load_log_event::do_apply_event()) we need the *original* thread
1498
    id, to be able to log the event with the original (=master's)
1499
    thread id (fix for BUG#1686).
1500
  */
1501
  ulong slave_proxy_id;
1502
1503
  /*
1504
    Binlog format 3 and 4 start to differ (as far as class members are
1505
    concerned) from here.
1506
  */
1507
1508
  uint catalog_len;			// <= 255 char; 0 means uninited
1509
1510
  /*
1511
    We want to be able to store a variable number of N-bit status vars:
1512
    (generally N=32; but N=64 for SQL_MODE) a user may want to log the number
1513
    of affected rows (for debugging) while another does not want to lose 4
1514
    bytes in this.
1515
    The storage on disk is the following:
1516
    status_vars_len is part of the post-header,
1517
    status_vars are in the variable-length part, after the post-header, before
1518
    the db & query.
1519
    status_vars on disk is a sequence of pairs (code, value) where 'code' means
1520
    'sql_mode', 'affected' etc. Sometimes 'value' must be a short string, so
1521
    its first byte is its length. For now the order of status vars is:
1522
    flags2 - sql_mode - catalog - autoinc - charset
1523
    We should add the same thing to Load_log_event, but in fact
1524
    LOAD DATA INFILE is going to be logged with a new type of event (logging of
1525
    the plain text query), so Load_log_event would be frozen, so no need. The
1526
    new way of logging LOAD DATA INFILE would use a derived class of
1527
    Query_log_event, so automatically benefit from the work already done for
1528
    status variables in Query_log_event.
1529
 */
206 by Brian Aker
Removed final uint dead types.
1530
  uint16_t status_vars_len;
1 by brian
clean slate
1531
1532
  /*
1533
    'flags2' is a second set of flags (on top of those in Log_event), for
1534
    session variables. These are thd->options which is & against a mask
1535
    (OPTIONS_WRITTEN_TO_BIN_LOG).
1536
    flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
1537
    master, we don't know flags2, so use the slave server's global options) and
1538
    flags2==0 (5.0 master, we know this has a meaning of flags all down which
1539
    must influence the query).
1540
  */
1541
  bool flags2_inited;
1542
  bool sql_mode_inited;
1543
  bool charset_inited;
1544
205 by Brian Aker
uint32 -> uin32_t
1545
  uint32_t flags2;
1 by brian
clean slate
1546
  /* In connections sql_mode is 32 bits now but will be 64 bits soon */
1547
  ulong sql_mode;
1548
  ulong auto_increment_increment, auto_increment_offset;
1549
  char charset[6];
1550
  uint time_zone_len; /* 0 means uninited */
1551
  const char *time_zone_str;
1552
  uint lc_time_names_number; /* 0 means en_US */
1553
  uint charset_database_number;
1554
1555
#ifndef MYSQL_CLIENT
1556
1557
  Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
1558
                  bool using_trans, bool suppress_use,
1559
                  THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1560
  const char* get_db() { return db; }
1561
#ifdef HAVE_REPLICATION
1562
  void pack_info(Protocol* protocol);
1563
#endif /* HAVE_REPLICATION */
1564
#else
1565
  void print_query_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info);
1566
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1567
#endif
1568
1569
  Query_log_event();
1570
  Query_log_event(const char* buf, uint event_len,
1571
                  const Format_description_log_event *description_event,
1572
                  Log_event_type event_type);
1573
  ~Query_log_event()
1574
  {
1575
    if (data_buf)
1576
      my_free((uchar*) data_buf, MYF(0));
1577
  }
1578
  Log_event_type get_type_code() { return QUERY_EVENT; }
1579
#ifndef MYSQL_CLIENT
1580
  bool write(IO_CACHE* file);
77.1.7 by Monty Taylor
Heap builds clean.
1581
  virtual bool write_post_header_for_derived(IO_CACHE* file __attribute__((__unused__)))
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1582
  { return false; }
1 by brian
clean slate
1583
#endif
1584
  bool is_valid() const { return query != 0; }
1585
1586
  /*
1587
    Returns number of bytes additionaly written to post header by derived
1588
    events (so far it is only Execute_load_query event).
1589
  */
1590
  virtual ulong get_post_header_size_for_derived() { return 0; }
1591
  /* Writes derived event-specific part of post header. */
1592
1593
public:        /* !!! Public in this patch to allow old usage */
1594
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1595
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
1596
  virtual int do_apply_event(Relay_log_info const *rli);
1597
  virtual int do_update_pos(Relay_log_info *rli);
1598
1599
  int do_apply_event(Relay_log_info const *rli,
1600
                       const char *query_arg,
205 by Brian Aker
uint32 -> uin32_t
1601
                       uint32_t q_len_arg);
1 by brian
clean slate
1602
#endif /* HAVE_REPLICATION */
1603
};
1604
1605
1606
#ifdef HAVE_REPLICATION
1607
1608
/**
1609
  @class Slave_log_event
1610
1611
  Note that this class is currently not used at all; no code writes a
1612
  @c Slave_log_event (though some code in @c repl_failsafe.cc reads @c
1613
  Slave_log_event).  So it's not a problem if this code is not
1614
  maintained.
1615
1616
  @section Slave_log_event_binary_format Binary Format
1617
1618
  This event type has no Post-Header. The Body has the following
1619
  four components.
1620
1621
  <table>
1622
  <caption>Body for Slave_log_event</caption>
1623
1624
  <tr>
1625
    <th>Name</th>
1626
    <th>Format</th>
1627
    <th>Description</th>
1628
  </tr>
1629
1630
  <tr>
1631
    <td>master_pos</td>
1632
    <td>8 byte integer</td>
1633
    <td>???TODO
1634
    </td>
1635
  </tr>
1636
1637
  <tr>
1638
    <td>master_port</td>
1639
    <td>2 byte integer</td>
1640
    <td>???TODO</td>
1641
  </tr>
1642
1643
  <tr>
1644
    <td>master_host</td>
1645
    <td>null-terminated string</td>
1646
    <td>???TODO</td>
1647
  </tr>
1648
1649
  <tr>
1650
    <td>master_log</td>
1651
    <td>null-terminated string</td>
1652
    <td>???TODO</td>
1653
  </tr>
1654
  </table>
1655
*/
1656
class Slave_log_event: public Log_event
1657
{
1658
protected:
1659
  char* mem_pool;
1660
  void init_from_mem_pool(int data_size);
1661
public:
1662
  my_off_t master_pos;
1663
  char* master_host;
1664
  char* master_log;
1665
  int master_host_len;
1666
  int master_log_len;
206 by Brian Aker
Removed final uint dead types.
1667
  uint16_t master_port;
1 by brian
clean slate
1668
1669
#ifndef MYSQL_CLIENT
1670
  Slave_log_event(THD* thd_arg, Relay_log_info* rli);
1671
  void pack_info(Protocol* protocol);
1672
#else
1673
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1674
#endif
1675
1676
  Slave_log_event(const char* buf, uint event_len);
1677
  ~Slave_log_event();
1678
  int get_data_size();
1679
  bool is_valid() const { return master_host != 0; }
1680
  Log_event_type get_type_code() { return SLAVE_EVENT; }
1681
#ifndef MYSQL_CLIENT
1682
  bool write(IO_CACHE* file);
1683
#endif
1684
1685
private:
1686
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1687
  virtual int do_apply_event(Relay_log_info const* rli);
1688
#endif
1689
};
1690
1691
#endif /* HAVE_REPLICATION */
1692
1693
1694
/**
1695
  @class Load_log_event
1696
1697
  This log event corresponds to a "LOAD DATA INFILE" SQL query on the
1698
  following form:
1699
1700
  @verbatim
1701
   (1)    USE db;
1702
   (2)    LOAD DATA [LOCAL] INFILE 'file_name'
1703
   (3)    [REPLACE | IGNORE]
1704
   (4)    INTO TABLE 'table_name'
1705
   (5)    [FIELDS
1706
   (6)      [TERMINATED BY 'field_term']
1707
   (7)      [[OPTIONALLY] ENCLOSED BY 'enclosed']
1708
   (8)      [ESCAPED BY 'escaped']
1709
   (9)    ]
1710
  (10)    [LINES
1711
  (11)      [TERMINATED BY 'line_term']
1712
  (12)      [LINES STARTING BY 'line_start']
1713
  (13)    ]
1714
  (14)    [IGNORE skip_lines LINES]
1715
  (15)    (field_1, field_2, ..., field_n)@endverbatim
1716
1717
  @section Load_log_event_binary_format Binary Format
1718
1719
  The Post-Header consists of the following six components.
1720
1721
  <table>
1722
  <caption>Post-Header for Load_log_event</caption>
1723
1724
  <tr>
1725
    <th>Name</th>
1726
    <th>Format</th>
1727
    <th>Description</th>
1728
  </tr>
1729
1730
  <tr>
1731
    <td>slave_proxy_id</td>
1732
    <td>4 byte unsigned integer</td>
1733
    <td>An integer identifying the client thread that issued the
1734
    query.  The id is unique per server.  (Note, however, that two
1735
    threads on different servers may have the same slave_proxy_id.)
1736
    This is used when a client thread creates a temporary table local
1737
    to the client.  The slave_proxy_id is used to distinguish
1738
    temporary tables that belong to different clients.
1739
    </td>
1740
  </tr>
1741
1742
  <tr>
1743
    <td>exec_time</td>
1744
    <td>4 byte unsigned integer</td>
1745
    <td>The time from when the query started to when it was logged in
1746
    the binlog, in seconds.</td>
1747
  </tr>
1748
1749
  <tr>
1750
    <td>skip_lines</td>
1751
    <td>4 byte unsigned integer</td>
1752
    <td>The number on line (14) above, if present, or 0 if line (14)
1753
    is left out.
1754
    </td>
1755
  </tr>
1756
1757
  <tr>
1758
    <td>table_name_len</td>
1759
    <td>1 byte unsigned integer</td>
1760
    <td>The length of 'table_name' on line (4) above.</td>
1761
  </tr>
1762
1763
  <tr>
1764
    <td>db_len</td>
1765
    <td>1 byte unsigned integer</td>
1766
    <td>The length of 'db' on line (1) above.</td>
1767
  </tr>
1768
1769
  <tr>
1770
    <td>num_fields</td>
1771
    <td>4 byte unsigned integer</td>
1772
    <td>The number n of fields on line (15) above.</td>
1773
  </tr>
1774
  </table>    
1775
1776
  The Body contains the following components.
1777
1778
  <table>
1779
  <caption>Body of Load_log_event</caption>
1780
1781
  <tr>
1782
    <th>Name</th>
1783
    <th>Format</th>
1784
    <th>Description</th>
1785
  </tr>
1786
1787
  <tr>
1788
    <td>sql_ex</td>
1789
    <td>variable length</td>
1790
1791
    <td>Describes the part of the query on lines (3) and
1792
    (5)&ndash;(13) above.  More precisely, it stores the five strings
1793
    (on lines) field_term (6), enclosed (7), escaped (8), line_term
1794
    (11), and line_start (12); as well as a bitfield indicating the
1795
    presence of the keywords REPLACE (3), IGNORE (3), and OPTIONALLY
1796
    (7).
1797
1798
    The data is stored in one of two formats, called "old" and "new".
1799
    The type field of Common-Header determines which of these two
1800
    formats is used: type LOAD_EVENT means that the old format is
1801
    used, and type NEW_LOAD_EVENT means that the new format is used.
1802
    When MySQL writes a Load_log_event, it uses the new format if at
1803
    least one of the five strings is two or more bytes long.
1804
    Otherwise (i.e., if all strings are 0 or 1 bytes long), the old
1805
    format is used.
1806
1807
    The new and old format differ in the way the five strings are
1808
    stored.
1809
1810
    <ul>
1811
    <li> In the new format, the strings are stored in the order
1812
    field_term, enclosed, escaped, line_term, line_start. Each string
1813
    consists of a length (1 byte), followed by a sequence of
1814
    characters (0-255 bytes).  Finally, a boolean combination of the
1815
    following flags is stored in 1 byte: REPLACE_FLAG==0x4,
1816
    IGNORE_FLAG==0x8, and OPT_ENCLOSED_FLAG==0x2.  If a flag is set,
1817
    it indicates the presence of the corresponding keyword in the SQL
1818
    query.
1819
1820
    <li> In the old format, we know that each string has length 0 or
1821
    1.  Therefore, only the first byte of each string is stored.  The
1822
    order of the strings is the same as in the new format.  These five
1823
    bytes are followed by the same 1 byte bitfield as in the new
1824
    format.  Finally, a 1 byte bitfield called empty_flags is stored.
1825
    The low 5 bits of empty_flags indicate which of the five strings
1826
    have length 0.  For each of the following flags that is set, the
1827
    corresponding string has length 0; for the flags that are not set,
1828
    the string has length 1: FIELD_TERM_EMPTY==0x1,
1829
    ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4, LINE_START_EMPTY==0x8,
1830
    ESCAPED_EMPTY==0x10.
1831
    </ul>
1832
1833
    Thus, the size of the new format is 6 bytes + the sum of the sizes
1834
    of the five strings.  The size of the old format is always 7
1835
    bytes.
1836
    </td>
1837
  </tr>
1838
1839
  <tr>
1840
    <td>field_lens</td>
1841
    <td>num_fields 1 byte unsigned integers</td>
1842
    <td>An array of num_fields integers representing the length of
1843
    each field in the query.  (num_fields is from the Post-Header).
1844
    </td>
1845
  </tr>
1846
1847
  <tr>
1848
    <td>fields</td>
1849
    <td>num_fields null-terminated strings</td>
1850
    <td>An array of num_fields null-terminated strings, each
1851
    representing a field in the query.  (The trailing zero is
1852
    redundant, since the length are stored in the num_fields array.)
1853
    The total length of all strings equals to the sum of all
1854
    field_lens, plus num_fields bytes for all the trailing zeros.
1855
    </td>
1856
  </tr>
1857
1858
  <tr>
1859
    <td>table_name</td>
1860
    <td>null-terminated string of length table_len+1 bytes</td>
1861
    <td>The 'table_name' from the query, as a null-terminated string.
1862
    (The trailing zero is actually redundant since the table_len is
1863
    known from Post-Header.)
1864
    </td>
1865
  </tr>
1866
1867
  <tr>
1868
    <td>db</td>
1869
    <td>null-terminated string of length db_len+1 bytes</td>
1870
    <td>The 'db' from the query, as a null-terminated string.
1871
    (The trailing zero is actually redundant since the db_len is known
1872
    from Post-Header.)
1873
    </td>
1874
  </tr>
1875
1876
  <tr>
1877
    <td>file_name</td>
1878
    <td>variable length string without trailing zero, extending to the
1879
    end of the event (determined by the length field of the
1880
    Common-Header)
1881
    </td>
1882
    <td>The 'file_name' from the query.
1883
    </td>
1884
  </tr>
1885
1886
  </table>
1887
1888
  @subsection Load_log_event_notes_on_previous_versions Notes on Previous Versions
1889
1890
  This event type is understood by current versions, but only
1891
  generated by MySQL 3.23 and earlier.
1892
*/
1893
class Load_log_event: public Log_event
1894
{
1895
private:
1896
  uint get_query_buffer_length();
1897
  void print_query(bool need_db, char *buf, char **end,
1898
                   char **fn_start, char **fn_end);
1899
protected:
1900
  int copy_log_event(const char *buf, ulong event_len,
1901
                     int body_offset,
1902
                     const Format_description_log_event* description_event);
1903
1904
public:
1905
  ulong thread_id;
1906
  ulong slave_proxy_id;
205 by Brian Aker
uint32 -> uin32_t
1907
  uint32_t table_name_len;
1 by brian
clean slate
1908
  /*
1909
    No need to have a catalog, as these events can only come from 4.x.
1910
    TODO: this may become false if Dmitri pushes his new LOAD DATA INFILE in
1911
    5.0 only (not in 4.x).
1912
  */
205 by Brian Aker
uint32 -> uin32_t
1913
  uint32_t db_len;
1914
  uint32_t fname_len;
1915
  uint32_t num_fields;
1 by brian
clean slate
1916
  const char* fields;
1917
  const uchar* field_lens;
205 by Brian Aker
uint32 -> uin32_t
1918
  uint32_t field_block_len;
1 by brian
clean slate
1919
1920
  const char* table_name;
1921
  const char* db;
1922
  const char* fname;
205 by Brian Aker
uint32 -> uin32_t
1923
  uint32_t skip_lines;
1 by brian
clean slate
1924
  sql_ex_info sql_ex;
1925
  bool local_fname;
1926
1927
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1928
  void set_fname_outside_temp_buf(const char *afname, uint alen)
1929
  {
1930
    fname= afname;
1931
    fname_len= alen;
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1932
    local_fname= true;
1 by brian
clean slate
1933
  }
1934
  /* fname doesn't point to memory inside Log_event::temp_buf  */
1935
  int  check_fname_outside_temp_buf()
1936
  {
1937
    return local_fname;
1938
  }
1939
1940
#ifndef MYSQL_CLIENT
1941
  String field_lens_buf;
1942
  String fields_buf;
1943
1944
  Load_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
1945
		 const char* table_name_arg,
1946
		 List<Item>& fields_arg, enum enum_duplicates handle_dup, bool ignore,
1947
		 bool using_trans);
1948
  void set_fields(const char* db, List<Item> &fields_arg,
1949
                  Name_resolution_context *context);
1950
  const char* get_db() { return db; }
1951
#ifdef HAVE_REPLICATION
1952
  void pack_info(Protocol* protocol);
1953
#endif /* HAVE_REPLICATION */
1954
#else
1955
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1956
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info, bool commented);
1957
#endif
1958
1959
  /*
1960
    Note that for all the events related to LOAD DATA (Load_log_event,
1961
    Create_file/Append/Exec/Delete, we pass description_event; however as
1962
    logging of LOAD DATA is going to be changed in 4.1 or 5.0, this is only used
1963
    for the common_header_len (post_header_len will not be changed).
1964
  */
1965
  Load_log_event(const char* buf, uint event_len,
1966
                 const Format_description_log_event* description_event);
1967
  ~Load_log_event()
1968
  {}
1969
  Log_event_type get_type_code()
1970
  {
1971
    return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT;
1972
  }
1973
#ifndef MYSQL_CLIENT
1974
  bool write_data_header(IO_CACHE* file);
1975
  bool write_data_body(IO_CACHE* file);
1976
#endif
1977
  bool is_valid() const { return table_name != 0; }
1978
  int get_data_size()
1979
  {
1980
    return (table_name_len + db_len + 2 + fname_len
1981
	    + LOAD_HEADER_LEN
1982
	    + sql_ex.data_size() + field_block_len + num_fields);
1983
  }
1984
1985
public:        /* !!! Public in this patch to allow old usage */
1986
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1987
  virtual int do_apply_event(Relay_log_info const* rli)
1988
  {
1989
    return do_apply_event(thd->slave_net,rli,0);
1990
  }
1991
1992
  int do_apply_event(NET *net, Relay_log_info const *rli,
1993
                     bool use_rli_only_for_errors);
1994
#endif
1995
};
1996
1997
extern char server_version[SERVER_VERSION_LENGTH];
1998
1999
/**
2000
  @class Start_log_event_v3
2001
2002
  Start_log_event_v3 is the Start_log_event of binlog format 3 (MySQL 3.23 and
2003
  4.x).
2004
2005
  Format_description_log_event derives from Start_log_event_v3; it is
2006
  the Start_log_event of binlog format 4 (MySQL 5.0), that is, the
2007
  event that describes the other events' Common-Header/Post-Header
2008
  lengths. This event is sent by MySQL 5.0 whenever it starts sending
2009
  a new binlog if the requested position is >4 (otherwise if ==4 the
2010
  event will be sent naturally).
2011
2012
  @section Start_log_event_v3_binary_format Binary Format
2013
*/
2014
class Start_log_event_v3: public Log_event
2015
{
2016
public:
2017
  /*
2018
    If this event is at the start of the first binary log since server
2019
    startup 'created' should be the timestamp when the event (and the
2020
    binary log) was created.  In the other case (i.e. this event is at
2021
    the start of a binary log created by FLUSH LOGS or automatic
2022
    rotation), 'created' should be 0.  This "trick" is used by MySQL
2023
    >=4.0.14 slaves to know whether they must drop stale temporary
2024
    tables and whether they should abort unfinished transaction.
2025
2026
    Note that when 'created'!=0, it is always equal to the event's
2027
    timestamp; indeed Start_log_event is written only in log.cc where
2028
    the first constructor below is called, in which 'created' is set
2029
    to 'when'.  So in fact 'created' is a useless variable. When it is
2030
    0 we can read the actual value from timestamp ('when') and when it
2031
    is non-zero we can read the same value from timestamp
2032
    ('when'). Conclusion:
2033
     - we use timestamp to print when the binlog was created.
2034
     - we use 'created' only to know if this is a first binlog or not.
2035
     In 3.23.57 we did not pay attention to this identity, so mysqlbinlog in
2036
     3.23.57 does not print 'created the_date' if created was zero. This is now
2037
     fixed.
2038
  */
2039
  time_t created;
206 by Brian Aker
Removed final uint dead types.
2040
  uint16_t binlog_version;
1 by brian
clean slate
2041
  char server_version[ST_SERVER_VER_LEN];
2042
  /*
2043
    artifical_event is 1 in the case where this is a generated event that
2044
    should not case any cleanup actions. We handle this in the log by
2045
    setting log_event == 0 (for now).
2046
  */
2047
  bool artificial_event;
2048
  /*
2049
    We set this to 1 if we don't want to have the created time in the log,
2050
    which is the case when we rollover to a new log.
2051
  */
2052
  bool dont_set_created;
2053
2054
#ifndef MYSQL_CLIENT
2055
  Start_log_event_v3();
2056
#ifdef HAVE_REPLICATION
2057
  void pack_info(Protocol* protocol);
2058
#endif /* HAVE_REPLICATION */
2059
#else
2060
  Start_log_event_v3() {}
2061
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2062
#endif
2063
2064
  Start_log_event_v3(const char* buf,
2065
                     const Format_description_log_event* description_event);
2066
  ~Start_log_event_v3() {}
2067
  Log_event_type get_type_code() { return START_EVENT_V3;}
2068
#ifndef MYSQL_CLIENT
2069
  bool write(IO_CACHE* file);
2070
#endif
2071
  bool is_valid() const { return 1; }
2072
  int get_data_size()
2073
  {
2074
    return START_V3_HEADER_LEN; //no variable-sized part
2075
  }
2076
  virtual bool is_artificial_event() { return artificial_event; }
2077
2078
protected:
2079
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2080
  virtual int do_apply_event(Relay_log_info const *rli);
2081
  virtual enum_skip_reason do_shall_skip(Relay_log_info*)
2082
  {
2083
    /*
2084
      Events from ourself should be skipped, but they should not
2085
      decrease the slave skip counter.
2086
     */
2087
    if (this->server_id == ::server_id)
2088
      return Log_event::EVENT_SKIP_IGNORE;
2089
    else
2090
      return Log_event::EVENT_SKIP_NOT;
2091
  }
2092
#endif
2093
};
2094
2095
2096
/**
2097
  @class Format_description_log_event
2098
2099
  For binlog version 4.
2100
  This event is saved by threads which read it, as they need it for future
2101
  use (to decode the ordinary events).
2102
2103
  @section Format_description_log_event_binary_format Binary Format
2104
*/
2105
2106
class Format_description_log_event: public Start_log_event_v3
2107
{
2108
public:
2109
  /*
2110
     The size of the fixed header which _all_ events have
2111
     (for binlogs written by this version, this is equal to
2112
     LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
2113
     (those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
2114
  */
206 by Brian Aker
Removed final uint dead types.
2115
  uint8_t common_header_len;
2116
  uint8_t number_of_event_types;
1 by brian
clean slate
2117
  /* The list of post-headers' lengthes */
206 by Brian Aker
Removed final uint dead types.
2118
  uint8_t *post_header_len;
1 by brian
clean slate
2119
  uchar server_version_split[3];
206 by Brian Aker
Removed final uint dead types.
2120
  const uint8_t *event_type_permutation;
1 by brian
clean slate
2121
206 by Brian Aker
Removed final uint dead types.
2122
  Format_description_log_event(uint8_t binlog_ver, const char* server_ver=0);
1 by brian
clean slate
2123
  Format_description_log_event(const char* buf, uint event_len,
2124
                               const Format_description_log_event
2125
                               *description_event);
2126
  ~Format_description_log_event()
2127
  {
2128
    my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
2129
  }
2130
  Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
2131
#ifndef MYSQL_CLIENT
2132
  bool write(IO_CACHE* file);
2133
#endif
2134
  bool is_valid() const
2135
  {
2136
    return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN :
2137
                                   LOG_EVENT_MINIMAL_HEADER_LEN)) &&
2138
            (post_header_len != NULL));
2139
  }
2140
  int get_data_size()
2141
  {
2142
    /*
2143
      The vector of post-header lengths is considered as part of the
2144
      post-header, because in a given version it never changes (contrary to the
2145
      query in a Query_log_event).
2146
    */
2147
    return FORMAT_DESCRIPTION_HEADER_LEN;
2148
  }
2149
2150
  void calc_server_version_split();
2151
2152
protected:
2153
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2154
  virtual int do_apply_event(Relay_log_info const *rli);
2155
  virtual int do_update_pos(Relay_log_info *rli);
2156
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2157
#endif
2158
};
2159
2160
2161
/**
2162
  @class Intvar_log_event
2163
2164
  An Intvar_log_event will be created just before a Query_log_event,
2165
  if the query uses one of the variables LAST_INSERT_ID or INSERT_ID.
2166
  Each Intvar_log_event holds the value of one of these variables.
2167
2168
  @section Intvar_log_event_binary_format Binary Format
2169
2170
  The Post-Header has two components:
2171
2172
  <table>
2173
  <caption>Post-Header for Intvar_log_event</caption>
2174
2175
  <tr>
2176
    <th>Name</th>
2177
    <th>Format</th>
2178
    <th>Description</th>
2179
  </tr>
2180
2181
  <tr>
2182
    <td>type</td>
2183
    <td>1 byte enumeration</td>
2184
    <td>One byte identifying the type of variable stored.  Currently,
2185
    two identifiers are supported:  LAST_INSERT_ID_EVENT==1 and
2186
    INSERT_ID_EVENT==2.
2187
    </td>
2188
  </tr>
2189
2190
  <tr>
2191
    <td>value</td>
2192
    <td>8 byte unsigned integer</td>
2193
    <td>The value of the variable.</td>
2194
  </tr>
2195
2196
  </table>
2197
*/
2198
class Intvar_log_event: public Log_event
2199
{
2200
public:
151 by Brian Aker
Ulonglong to uint64_t
2201
  uint64_t val;
1 by brian
clean slate
2202
  uchar type;
2203
2204
#ifndef MYSQL_CLIENT
151 by Brian Aker
Ulonglong to uint64_t
2205
  Intvar_log_event(THD* thd_arg,uchar type_arg, uint64_t val_arg)
1 by brian
clean slate
2206
    :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
2207
  {}
2208
#ifdef HAVE_REPLICATION
2209
  void pack_info(Protocol* protocol);
2210
#endif /* HAVE_REPLICATION */
2211
#else
2212
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2213
#endif
2214
2215
  Intvar_log_event(const char* buf,
2216
                   const Format_description_log_event *description_event);
2217
  ~Intvar_log_event() {}
2218
  Log_event_type get_type_code() { return INTVAR_EVENT;}
2219
  const char* get_var_type_name();
2220
  int get_data_size() { return  9; /* sizeof(type) + sizeof(val) */;}
2221
#ifndef MYSQL_CLIENT
2222
  bool write(IO_CACHE* file);
2223
#endif
2224
  bool is_valid() const { return 1; }
2225
2226
private:
2227
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2228
  virtual int do_apply_event(Relay_log_info const *rli);
2229
  virtual int do_update_pos(Relay_log_info *rli);
2230
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2231
#endif
2232
};
2233
2234
2235
/**
2236
  @class Rand_log_event
2237
2238
  Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
2239
  4.1.1 does not need it (it's repeatable again) so this event needn't be
2240
  written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
2241
  waste, it does not cause bugs).
2242
2243
  The state of the random number generation consists of 128 bits,
2244
  which are stored internally as two 64-bit numbers.
2245
2246
  @section Rand_log_event_binary_format Binary Format  
2247
  This event type has no Post-Header. The Body of this event type has
2248
  two components:
2249
2250
  <table>
2251
  <caption>Post-Header for Intvar_log_event</caption>
2252
2253
  <tr>
2254
    <th>Name</th>
2255
    <th>Format</th>
2256
    <th>Description</th>
2257
  </tr>
2258
2259
  <tr>
2260
    <td>seed1</td>
2261
    <td>8 byte unsigned integer</td>
2262
    <td>64 bit random seed1.</td>
2263
  </tr>
2264
2265
  <tr>
2266
    <td>seed2</td>
2267
    <td>8 byte unsigned integer</td>
2268
    <td>64 bit random seed2.</td>
2269
  </tr>
2270
  </table>
2271
*/
2272
2273
class Rand_log_event: public Log_event
2274
{
2275
 public:
151 by Brian Aker
Ulonglong to uint64_t
2276
  uint64_t seed1;
2277
  uint64_t seed2;
1 by brian
clean slate
2278
2279
#ifndef MYSQL_CLIENT
151 by Brian Aker
Ulonglong to uint64_t
2280
  Rand_log_event(THD* thd_arg, uint64_t seed1_arg, uint64_t seed2_arg)
1 by brian
clean slate
2281
    :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2282
  {}
2283
#ifdef HAVE_REPLICATION
2284
  void pack_info(Protocol* protocol);
2285
#endif /* HAVE_REPLICATION */
2286
#else
2287
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2288
#endif
2289
2290
  Rand_log_event(const char* buf,
2291
                 const Format_description_log_event *description_event);
2292
  ~Rand_log_event() {}
2293
  Log_event_type get_type_code() { return RAND_EVENT;}
151 by Brian Aker
Ulonglong to uint64_t
2294
  int get_data_size() { return 16; /* sizeof(uint64_t) * 2*/ }
1 by brian
clean slate
2295
#ifndef MYSQL_CLIENT
2296
  bool write(IO_CACHE* file);
2297
#endif
2298
  bool is_valid() const { return 1; }
2299
2300
private:
2301
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2302
  virtual int do_apply_event(Relay_log_info const *rli);
2303
  virtual int do_update_pos(Relay_log_info *rli);
2304
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2305
#endif
2306
};
2307
2308
/**
2309
  @class Xid_log_event
2310
2311
  Logs xid of the transaction-to-be-committed in the 2pc protocol.
2312
  Has no meaning in replication, slaves ignore it.
2313
2314
  @section Xid_log_event_binary_format Binary Format  
2315
*/
2316
#ifdef MYSQL_CLIENT
151 by Brian Aker
Ulonglong to uint64_t
2317
typedef uint64_t my_xid; // this line is the same as in handler.h
1 by brian
clean slate
2318
#endif
2319
2320
class Xid_log_event: public Log_event
2321
{
2322
 public:
2323
   my_xid xid;
2324
2325
#ifndef MYSQL_CLIENT
2326
  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
2327
#ifdef HAVE_REPLICATION
2328
  void pack_info(Protocol* protocol);
2329
#endif /* HAVE_REPLICATION */
2330
#else
2331
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2332
#endif
2333
2334
  Xid_log_event(const char* buf,
2335
                const Format_description_log_event *description_event);
2336
  ~Xid_log_event() {}
2337
  Log_event_type get_type_code() { return XID_EVENT;}
2338
  int get_data_size() { return sizeof(xid); }
2339
#ifndef MYSQL_CLIENT
2340
  bool write(IO_CACHE* file);
2341
#endif
2342
  bool is_valid() const { return 1; }
2343
2344
private:
2345
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2346
  virtual int do_apply_event(Relay_log_info const *rli);
2347
  enum_skip_reason do_shall_skip(Relay_log_info *rli);
2348
#endif
2349
};
2350
2351
/**
2352
  @class User_var_log_event
2353
2354
  Every time a query uses the value of a user variable, a User_var_log_event is
2355
  written before the Query_log_event, to set the user variable.
2356
2357
  @section User_var_log_event_binary_format Binary Format  
2358
*/
2359
2360
class User_var_log_event: public Log_event
2361
{
2362
public:
2363
  char *name;
2364
  uint name_len;
2365
  char *val;
2366
  ulong val_len;
2367
  Item_result type;
2368
  uint charset_number;
2369
  bool is_null;
2370
#ifndef MYSQL_CLIENT
77.1.7 by Monty Taylor
Heap builds clean.
2371
  User_var_log_event(THD* thd_arg __attribute__((__unused__)),
2372
                     char *name_arg, uint name_len_arg,
1 by brian
clean slate
2373
                     char *val_arg, ulong val_len_arg, Item_result type_arg,
2374
		     uint charset_number_arg)
2375
    :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
2376
    val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
2377
    { is_null= !val; }
2378
  void pack_info(Protocol* protocol);
2379
#else
2380
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2381
#endif
2382
2383
  User_var_log_event(const char* buf,
2384
                     const Format_description_log_event *description_event);
2385
  ~User_var_log_event() {}
2386
  Log_event_type get_type_code() { return USER_VAR_EVENT;}
2387
#ifndef MYSQL_CLIENT
2388
  bool write(IO_CACHE* file);
2389
#endif
2390
  bool is_valid() const { return 1; }
2391
2392
private:
2393
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2394
  virtual int do_apply_event(Relay_log_info const *rli);
2395
  virtual int do_update_pos(Relay_log_info *rli);
2396
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2397
#endif
2398
};
2399
2400
2401
/**
2402
  @class Stop_log_event
2403
2404
  @section Stop_log_event_binary_format Binary Format
2405
2406
  The Post-Header and Body for this event type are empty; it only has
2407
  the Common-Header.
2408
*/
2409
class Stop_log_event: public Log_event
2410
{
2411
public:
2412
#ifndef MYSQL_CLIENT
2413
  Stop_log_event() :Log_event()
2414
  {}
2415
#else
2416
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2417
#endif
2418
2419
  Stop_log_event(const char* buf,
2420
                 const Format_description_log_event *description_event):
2421
    Log_event(buf, description_event)
2422
  {}
2423
  ~Stop_log_event() {}
2424
  Log_event_type get_type_code() { return STOP_EVENT;}
2425
  bool is_valid() const { return 1; }
2426
2427
private:
2428
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2429
  virtual int do_update_pos(Relay_log_info *rli);
77.1.7 by Monty Taylor
Heap builds clean.
2430
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli __attribute__((__unused__)))
1 by brian
clean slate
2431
  {
2432
    /*
2433
      Events from ourself should be skipped, but they should not
2434
      decrease the slave skip counter.
2435
     */
2436
    if (this->server_id == ::server_id)
2437
      return Log_event::EVENT_SKIP_IGNORE;
2438
    else
2439
      return Log_event::EVENT_SKIP_NOT;
2440
  }
2441
#endif
2442
};
2443
2444
/**
2445
  @class Rotate_log_event
2446
2447
  This will be deprecated when we move to using sequence ids.
2448
2449
  @section Rotate_log_event_binary_format Binary Format
2450
2451
  The Post-Header has one component:
2452
2453
  <table>
2454
  <caption>Post-Header for Rotate_log_event</caption>
2455
2456
  <tr>
2457
    <th>Name</th>
2458
    <th>Format</th>
2459
    <th>Description</th>
2460
  </tr>
2461
2462
  <tr>
2463
    <td>position</td>
2464
    <td>8 byte integer</td>
2465
    <td>The position within the binlog to rotate to.</td>
2466
  </tr>
2467
2468
  </table>
2469
2470
  The Body has one component:
2471
2472
  <table>
2473
  <caption>Body for Rotate_log_event</caption>
2474
2475
  <tr>
2476
    <th>Name</th>
2477
    <th>Format</th>
2478
    <th>Description</th>
2479
  </tr>
2480
2481
  <tr>
2482
    <td>new_log</td>
2483
    <td>variable length string without trailing zero, extending to the
2484
    end of the event (determined by the length field of the
2485
    Common-Header)
2486
    </td>
2487
    <td>Name of the binlog to rotate to.</td>
2488
  </tr>
2489
2490
  </table>
2491
*/
2492
2493
class Rotate_log_event: public Log_event
2494
{
2495
public:
2496
  enum {
2497
    DUP_NAME= 2 // if constructor should dup the string argument
2498
  };
2499
  const char* new_log_ident;
151 by Brian Aker
Ulonglong to uint64_t
2500
  uint64_t pos;
1 by brian
clean slate
2501
  uint ident_len;
2502
  uint flags;
2503
#ifndef MYSQL_CLIENT
2504
  Rotate_log_event(const char* new_log_ident_arg,
2505
		   uint ident_len_arg,
151 by Brian Aker
Ulonglong to uint64_t
2506
		   uint64_t pos_arg, uint flags);
1 by brian
clean slate
2507
#ifdef HAVE_REPLICATION
2508
  void pack_info(Protocol* protocol);
2509
#endif /* HAVE_REPLICATION */
2510
#else
2511
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2512
#endif
2513
2514
  Rotate_log_event(const char* buf, uint event_len,
2515
                   const Format_description_log_event* description_event);
2516
  ~Rotate_log_event()
2517
  {
2518
    if (flags & DUP_NAME)
2519
      my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
2520
  }
2521
  Log_event_type get_type_code() { return ROTATE_EVENT;}
2522
  int get_data_size() { return  ident_len + ROTATE_HEADER_LEN;}
2523
  bool is_valid() const { return new_log_ident != 0; }
2524
#ifndef MYSQL_CLIENT
2525
  bool write(IO_CACHE* file);
2526
#endif
2527
2528
private:
2529
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2530
  virtual int do_update_pos(Relay_log_info *rli);
2531
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2532
#endif
2533
};
2534
2535
2536
/* the classes below are for the new LOAD DATA INFILE logging */
2537
2538
/**
2539
  @class Create_file_log_event
2540
2541
  @section Create_file_log_event_binary_format Binary Format
2542
*/
2543
2544
class Create_file_log_event: public Load_log_event
2545
{
2546
protected:
2547
  /*
2548
    Pretend we are Load event, so we can write out just
2549
    our Load part - used on the slave when writing event out to
2550
    SQL_LOAD-*.info file
2551
  */
2552
  bool fake_base;
2553
public:
2554
  uchar* block;
2555
  const char *event_buf;
2556
  uint block_len;
2557
  uint file_id;
2558
  bool inited_from_old;
2559
2560
#ifndef MYSQL_CLIENT
2561
  Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
2562
			const char* table_name_arg,
2563
			List<Item>& fields_arg,
2564
			enum enum_duplicates handle_dup, bool ignore,
2565
			uchar* block_arg, uint block_len_arg,
2566
			bool using_trans);
2567
#ifdef HAVE_REPLICATION
2568
  void pack_info(Protocol* protocol);
2569
#endif /* HAVE_REPLICATION */
2570
#else
2571
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2572
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2573
             bool enable_local);
2574
#endif
2575
2576
  Create_file_log_event(const char* buf, uint event_len,
2577
                        const Format_description_log_event* description_event);
2578
  ~Create_file_log_event()
2579
  {
2580
    my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
2581
  }
2582
2583
  Log_event_type get_type_code()
2584
  {
2585
    return fake_base ? Load_log_event::get_type_code() : CREATE_FILE_EVENT;
2586
  }
2587
  int get_data_size()
2588
  {
2589
    return (fake_base ? Load_log_event::get_data_size() :
2590
	    Load_log_event::get_data_size() +
2591
	    4 + 1 + block_len);
2592
  }
2593
  bool is_valid() const { return inited_from_old || block != 0; }
2594
#ifndef MYSQL_CLIENT
2595
  bool write_data_header(IO_CACHE* file);
2596
  bool write_data_body(IO_CACHE* file);
2597
  /*
2598
    Cut out Create_file extentions and
2599
    write it as Load event - used on the slave
2600
  */
2601
  bool write_base(IO_CACHE* file);
2602
#endif
2603
2604
private:
2605
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2606
  virtual int do_apply_event(Relay_log_info const *rli);
2607
#endif
2608
};
2609
2610
2611
/**
2612
  @class Append_block_log_event
2613
2614
  @section Append_block_log_event_binary_format Binary Format
2615
*/
2616
2617
class Append_block_log_event: public Log_event
2618
{
2619
public:
2620
  uchar* block;
2621
  uint block_len;
2622
  uint file_id;
2623
  /*
2624
    'db' is filled when the event is created in mysql_load() (the
2625
    event needs to have a 'db' member to be well filtered by
2626
    binlog-*-db rules). 'db' is not written to the binlog (it's not
2627
    used by Append_block_log_event::write()), so it can't be read in
2628
    the Append_block_log_event(const char* buf, int event_len)
2629
    constructor.  In other words, 'db' is used only for filtering by
2630
    binlog-*-db rules.  Create_file_log_event is different: it's 'db'
2631
    (which is inherited from Load_log_event) is written to the binlog
2632
    and can be re-read.
2633
  */
2634
  const char* db;
2635
2636
#ifndef MYSQL_CLIENT
2637
  Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
2638
			 uint block_len_arg, bool using_trans);
2639
#ifdef HAVE_REPLICATION
2640
  void pack_info(Protocol* protocol);
2641
  virtual int get_create_or_append() const;
2642
#endif /* HAVE_REPLICATION */
2643
#else
2644
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2645
#endif
2646
2647
  Append_block_log_event(const char* buf, uint event_len,
2648
                         const Format_description_log_event
2649
                         *description_event);
2650
  ~Append_block_log_event() {}
2651
  Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
2652
  int get_data_size() { return  block_len + APPEND_BLOCK_HEADER_LEN ;}
2653
  bool is_valid() const { return block != 0; }
2654
#ifndef MYSQL_CLIENT
2655
  bool write(IO_CACHE* file);
2656
  const char* get_db() { return db; }
2657
#endif
2658
2659
private:
2660
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2661
  virtual int do_apply_event(Relay_log_info const *rli);
2662
#endif
2663
};
2664
2665
2666
/**
2667
  @class Delete_file_log_event
2668
2669
  @section Delete_file_log_event_binary_format Binary Format
2670
*/
2671
2672
class Delete_file_log_event: public Log_event
2673
{
2674
public:
2675
  uint file_id;
2676
  const char* db; /* see comment in Append_block_log_event */
2677
2678
#ifndef MYSQL_CLIENT
2679
  Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
2680
#ifdef HAVE_REPLICATION
2681
  void pack_info(Protocol* protocol);
2682
#endif /* HAVE_REPLICATION */
2683
#else
2684
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2685
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2686
             bool enable_local);
2687
#endif
2688
2689
  Delete_file_log_event(const char* buf, uint event_len,
2690
                        const Format_description_log_event* description_event);
2691
  ~Delete_file_log_event() {}
2692
  Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
2693
  int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
2694
  bool is_valid() const { return file_id != 0; }
2695
#ifndef MYSQL_CLIENT
2696
  bool write(IO_CACHE* file);
2697
  const char* get_db() { return db; }
2698
#endif
2699
2700
private:
2701
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2702
  virtual int do_apply_event(Relay_log_info const *rli);
2703
#endif
2704
};
2705
2706
2707
/**
2708
  @class Execute_load_log_event
2709
2710
  @section Delete_file_log_event_binary_format Binary Format
2711
*/
2712
2713
class Execute_load_log_event: public Log_event
2714
{
2715
public:
2716
  uint file_id;
2717
  const char* db; /* see comment in Append_block_log_event */
2718
2719
#ifndef MYSQL_CLIENT
2720
  Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
2721
#ifdef HAVE_REPLICATION
2722
  void pack_info(Protocol* protocol);
2723
#endif /* HAVE_REPLICATION */
2724
#else
2725
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2726
#endif
2727
2728
  Execute_load_log_event(const char* buf, uint event_len,
2729
                         const Format_description_log_event
2730
                         *description_event);
2731
  ~Execute_load_log_event() {}
2732
  Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
2733
  int get_data_size() { return  EXEC_LOAD_HEADER_LEN ;}
2734
  bool is_valid() const { return file_id != 0; }
2735
#ifndef MYSQL_CLIENT
2736
  bool write(IO_CACHE* file);
2737
  const char* get_db() { return db; }
2738
#endif
2739
2740
private:
2741
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2742
  virtual int do_apply_event(Relay_log_info const *rli);
2743
#endif
2744
};
2745
2746
2747
/**
2748
  @class Begin_load_query_log_event
2749
2750
  Event for the first block of file to be loaded, its only difference from
2751
  Append_block event is that this event creates or truncates existing file
2752
  before writing data.
2753
2754
  @section Begin_load_query_log_event_binary_format Binary Format
2755
*/
2756
class Begin_load_query_log_event: public Append_block_log_event
2757
{
2758
public:
2759
#ifndef MYSQL_CLIENT
2760
  Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
2761
                             uchar* block_arg, uint block_len_arg,
2762
                             bool using_trans);
2763
#ifdef HAVE_REPLICATION
2764
  Begin_load_query_log_event(THD* thd);
2765
  int get_create_or_append() const;
2766
#endif /* HAVE_REPLICATION */
2767
#endif
2768
  Begin_load_query_log_event(const char* buf, uint event_len,
2769
                             const Format_description_log_event
2770
                             *description_event);
2771
  ~Begin_load_query_log_event() {}
2772
  Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
2773
private:
2774
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2775
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2776
#endif
2777
};
2778
2779
2780
/*
2781
  Elements of this enum describe how LOAD DATA handles duplicates.
2782
*/
2783
enum enum_load_dup_handling { LOAD_DUP_ERROR= 0, LOAD_DUP_IGNORE,
2784
                              LOAD_DUP_REPLACE };
2785
2786
/**
2787
  @class Execute_load_query_log_event
2788
2789
  Event responsible for LOAD DATA execution, it similar to Query_log_event
2790
  but before executing the query it substitutes original filename in LOAD DATA
2791
  query with name of temporary file.
2792
2793
  @section Execute_load_query_log_event_binary_format Binary Format
2794
*/
2795
class Execute_load_query_log_event: public Query_log_event
2796
{
2797
public:
2798
  uint file_id;       // file_id of temporary file
2799
  uint fn_pos_start;  // pointer to the part of the query that should
2800
                      // be substituted
2801
  uint fn_pos_end;    // pointer to the end of this part of query
2802
  /*
2803
    We have to store type of duplicate handling explicitly, because
2804
    for LOAD DATA it also depends on LOCAL option. And this part
2805
    of query will be rewritten during replication so this information
2806
    may be lost...
2807
  */
2808
  enum_load_dup_handling dup_handling;
2809
2810
#ifndef MYSQL_CLIENT
2811
  Execute_load_query_log_event(THD* thd, const char* query_arg,
2812
                               ulong query_length, uint fn_pos_start_arg,
2813
                               uint fn_pos_end_arg,
2814
                               enum_load_dup_handling dup_handling_arg,
2815
                               bool using_trans, bool suppress_use,
2816
                               THD::killed_state
2817
                               killed_err_arg= THD::KILLED_NO_VALUE);
2818
#ifdef HAVE_REPLICATION
2819
  void pack_info(Protocol* protocol);
2820
#endif /* HAVE_REPLICATION */
2821
#else
2822
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2823
  /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2824
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2825
	     const char *local_fname);
2826
#endif
2827
  Execute_load_query_log_event(const char* buf, uint event_len,
2828
                               const Format_description_log_event
2829
                               *description_event);
2830
  ~Execute_load_query_log_event() {}
2831
2832
  Log_event_type get_type_code() { return EXECUTE_LOAD_QUERY_EVENT; }
2833
  bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
2834
2835
  ulong get_post_header_size_for_derived();
2836
#ifndef MYSQL_CLIENT
2837
  bool write_post_header_for_derived(IO_CACHE* file);
2838
#endif
2839
2840
private:
2841
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2842
  virtual int do_apply_event(Relay_log_info const *rli);
2843
#endif
2844
};
2845
2846
2847
#ifdef MYSQL_CLIENT
2848
/**
2849
  @class Unknown_log_event
2850
2851
  @section Unknown_log_event_binary_format Binary Format
2852
*/
2853
class Unknown_log_event: public Log_event
2854
{
2855
public:
2856
  /*
2857
    Even if this is an unknown event, we still pass description_event to
2858
    Log_event's ctor, this way we can extract maximum information from the
2859
    event's header (the unique ID for example).
2860
  */
2861
  Unknown_log_event(const char* buf,
2862
                    const Format_description_log_event *description_event):
2863
    Log_event(buf, description_event)
2864
  {}
2865
  ~Unknown_log_event() {}
2866
  void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2867
  Log_event_type get_type_code() { return UNKNOWN_EVENT;}
2868
  bool is_valid() const { return 1; }
2869
};
2870
#endif
2871
char *str_to_hex(char *to, const char *from, uint len);
2872
2873
/**
2874
  @class Table_map_log_event
2875
2876
  In row-based mode, every row operation event is preceded by a
2877
  Table_map_log_event which maps a table definition to a number.  The
2878
  table definition consists of database name, table name, and column
2879
  definitions.
2880
2881
  @section Table_map_log_event_binary_format Binary Format
2882
2883
  The Post-Header has the following components:
2884
2885
  <table>
2886
  <caption>Post-Header for Table_map_log_event</caption>
2887
2888
  <tr>
2889
    <th>Name</th>
2890
    <th>Format</th>
2891
    <th>Description</th>
2892
  </tr>
2893
2894
  <tr>
2895
    <td>table_id</td>
2896
    <td>6 bytes unsigned integer</td>
2897
    <td>The number that identifies the table.</td>
2898
  </tr>
2899
2900
  <tr>
2901
    <td>flags</td>
2902
    <td>2 byte bitfield</td>
2903
    <td>Reserved for future use; currently always 0.</td>
2904
  </tr>
2905
2906
  </table>
2907
2908
  The Body has the following components:
2909
2910
  <table>
2911
  <caption>Body for Table_map_log_event</caption>
2912
2913
  <tr>
2914
    <th>Name</th>
2915
    <th>Format</th>
2916
    <th>Description</th>
2917
  </tr>
2918
2919
  <tr>
2920
    <td>database_name</td>
2921
    <td>one byte string length, followed by null-terminated string</td>
2922
    <td>The name of the database in which the table resides.  The name
2923
    is represented as a one byte unsigned integer representing the
2924
    number of bytes in the name, followed by length bytes containing
2925
    the database name, followed by a terminating 0 byte.  (Note the
2926
    redundancy in the representation of the length.)  </td>
2927
  </tr>
2928
2929
  <tr>
2930
    <td>table_name</td>
2931
    <td>one byte string length, followed by null-terminated string</td>
2932
    <td>The name of the table, encoded the same way as the database
2933
    name above.</td>
2934
  </tr>
2935
2936
  <tr>
2937
    <td>column_count</td>
2938
    <td>@ref packed_integer "Packed Integer"</td>
2939
    <td>The number of columns in the table, represented as a packed
2940
    variable-length integer.</td>
2941
  </tr>
2942
2943
  <tr>
2944
    <td>column_type</td>
2945
    <td>List of column_count 1 byte enumeration values</td>
2946
    <td>The type of each column in the table, listed from left to
2947
    right.  Each byte is mapped to a column type according to the
2948
    enumeration type enum_field_types defined in mysql_com.h.  The
2949
    mapping of types to numbers is listed in the table @ref
2950
    Table_table_map_log_event_column_types "below" (along with
2951
    description of the associated metadata field).  </td>
2952
  </tr>
2953
2954
  <tr>
2955
    <td>metadata_length</td>
2956
    <td>@ref packed_integer "Packed Integer"</td>
2957
    <td>The length of the following metadata block</td>
2958
  </tr>
2959
2960
  <tr>
2961
    <td>metadata</td>
2962
    <td>list of metadata for each column</td>
2963
    <td>For each column from left to right, a chunk of data who's
2964
    length and semantics depends on the type of the column.  The
2965
    length and semantics for the metadata for each column are listed
2966
    in the table @ref Table_table_map_log_event_column_types
2967
    "below".</td>
2968
  </tr>
2969
2970
  <tr>
2971
    <td>null_bits</td>
2972
    <td>column_count bits, rounded up to nearest byte</td>
2973
    <td>For each column, a bit indicating whether data in the column
2974
    can be NULL or not.  The number of bytes needed for this is
2975
    int((column_count+7)/8).  The flag for the first column from the
2976
    left is in the least-significant bit of the first byte, the second
2977
    is in the second least significant bit of the first byte, the
2978
    ninth is in the least significant bit of the second byte, and so
2979
    on.  </td>
2980
  </tr>
2981
2982
  </table>
2983
2984
  The table below lists all column types, along with the numerical
2985
  identifier for it and the size and interpretation of meta-data used
2986
  to describe the type.
2987
2988
  @anchor Table_table_map_log_event_column_types
2989
  <table>
2990
  <caption>Table_map_log_event column types: numerical identifier and
2991
  metadata</caption>
2992
  <tr>
2993
    <th>Name</th>
2994
    <th>Identifier</th>
2995
    <th>Size of metadata in bytes</th>
2996
    <th>Description of metadata</th>
2997
  </tr>
2998
2999
  <tr>
3000
    <td>MYSQL_TYPE_TINY</td><td>1</td>
3001
    <td>0</td>
3002
    <td>No column metadata.</td>
3003
  </tr>
3004
3005
  <tr>
3006
    <td>MYSQL_TYPE_SHORT</td><td>2</td>
3007
    <td>0</td>
3008
    <td>No column metadata.</td>
3009
  </tr>
3010
3011
  <tr>
3012
    <td>MYSQL_TYPE_LONG</td><td>3</td>
3013
    <td>0</td>
3014
    <td>No column metadata.</td>
3015
  </tr>
3016
3017
  <tr>
3018
    <td>MYSQL_TYPE_DOUBLE</td><td>5</td>
3019
    <td>1 byte</td>
3020
    <td>1 byte unsigned integer, representing the "pack_length", which
3021
    is equal to sizeof(double) on the server from which the event
3022
    originates.</td>
3023
  </tr>
3024
3025
  <tr>
3026
    <td>MYSQL_TYPE_NULL</td><td>6</td>
3027
    <td>0</td>
3028
    <td>No column metadata.</td>
3029
  </tr>
3030
3031
  <tr>
3032
    <td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
3033
    <td>0</td>
3034
    <td>No column metadata.</td>
3035
  </tr>
3036
3037
  <tr>
3038
    <td>MYSQL_TYPE_LONGLONG</td><td>8</td>
3039
    <td>0</td>
3040
    <td>No column metadata.</td>
3041
  </tr>
3042
3043
  <tr>
3044
    <td>MYSQL_TYPE_DATE</td><td>10</td>
3045
    <td>0</td>
3046
    <td>No column metadata.</td>
3047
  </tr>
3048
3049
  <tr>
3050
    <td>MYSQL_TYPE_TIME</td><td>11</td>
3051
    <td>0</td>
3052
    <td>No column metadata.</td>
3053
  </tr>
3054
3055
  <tr>
3056
    <td>MYSQL_TYPE_DATETIME</td><td>12</td>
3057
    <td>0</td>
3058
    <td>No column metadata.</td>
3059
  </tr>
3060
3061
  <tr>
3062
    <td>MYSQL_TYPE_YEAR</td><td>13</td>
3063
    <td>0</td>
3064
    <td>No column metadata.</td>
3065
  </tr>
3066
3067
  <tr>
3068
    <td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
3069
    <td>&ndash;</td>
3070
    <td><i>This enumeration value is only used internally and cannot
3071
    exist in a binlog.</i></td>
3072
  </tr>
3073
3074
  <tr>
3075
    <td>MYSQL_TYPE_VARCHAR</td><td>15</td>
3076
    <td>2 bytes</td>
3077
    <td>2 byte unsigned integer representing the maximum length of
3078
    the string.</td>
3079
  </tr>
3080
3081
  <tr>
3082
    <td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
3083
    <td>2 bytes</td>
3084
    <td>A 1 byte unsigned int representing the precision, followed
3085
    by a 1 byte unsigned int representing the number of decimals.</td>
3086
  </tr>
3087
3088
  <tr>
3089
    <td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
3090
    <td>&ndash;</td>
3091
    <td><i>This enumeration value is only used internally and cannot
3092
    exist in a binlog.</i></td>
3093
  </tr>
3094
3095
  <tr>
3096
    <td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
3097
    <td>&ndash;</td>
3098
    <td><i>This enumeration value is only used internally and cannot
3099
    exist in a binlog.</i></td>
3100
  </tr>
3101
3102
  <tr>
3103
    <td>MYSQL_TYPE_BLOB</td><td>252</td>
3104
    <td>1 byte</td>
3105
    <td>The pack length, i.e., the number of bytes needed to represent
3106
    the length of the blob: 1, 2, 3, or 4.</td>
3107
  </tr>
3108
3109
  <tr>
3110
    <td>MYSQL_TYPE_STRING</td><td>254</td>
3111
    <td>2 bytes</td>
3112
    <td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
3113
    The second byte is the field size, i.e., the number of bytes in
3114
    the representation of size of the string: 3 or 4.</td>
3115
  </tr>
3116
3117
  </table>
3118
*/
3119
class Table_map_log_event : public Log_event
3120
{
3121
public:
3122
  /* Constants */
3123
  enum
3124
  {
3125
    TYPE_CODE = TABLE_MAP_EVENT
3126
  };
3127
3128
  /**
3129
     Enumeration of the errors that can be returned.
3130
   */
3131
  enum enum_error
3132
  {
3133
    ERR_OPEN_FAILURE = -1,               /**< Failure to open table */
3134
    ERR_OK = 0,                                 /**< No error */
3135
    ERR_TABLE_LIMIT_EXCEEDED = 1,      /**< No more room for tables */
3136
    ERR_OUT_OF_MEM = 2,                         /**< Out of memory */
3137
    ERR_BAD_TABLE_DEF = 3,     /**< Table definition does not match */
3138
    ERR_RBR_TO_SBR = 4  /**< daisy-chanining RBR to SBR not allowed */
3139
  };
3140
3141
  enum enum_flag
3142
  {
3143
    /* 
3144
       Nothing here right now, but the flags support is there in
3145
       preparation for changes that are coming.  Need to add a
3146
       constant to make it compile under HP-UX: aCC does not like
3147
       empty enumerations.
3148
    */
3149
    ENUM_FLAG_COUNT
3150
  };
3151
206 by Brian Aker
Removed final uint dead types.
3152
  typedef uint16_t flag_set;
1 by brian
clean slate
3153
3154
  /* Special constants representing sets of flags */
3155
  enum 
3156
  {
3157
    TM_NO_FLAGS = 0U
3158
  };
3159
3160
  void set_flags(flag_set flag) { m_flags |= flag; }
3161
  void clear_flags(flag_set flag) { m_flags &= ~flag; }
3162
  flag_set get_flags(flag_set flag) const { return m_flags & flag; }
3163
3164
#ifndef MYSQL_CLIENT
3165
  Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, 
206 by Brian Aker
Removed final uint dead types.
3166
		      bool is_transactional, uint16_t flags);
1 by brian
clean slate
3167
#endif
3168
#ifdef HAVE_REPLICATION
3169
  Table_map_log_event(const char *buf, uint event_len, 
3170
                      const Format_description_log_event *description_event);
3171
#endif
3172
3173
  ~Table_map_log_event();
3174
3175
  virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; }
3176
  virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
3177
3178
  virtual int get_data_size() { return m_data_size; } 
3179
#ifndef MYSQL_CLIENT
3180
  virtual int save_field_metadata();
3181
  virtual bool write_data_header(IO_CACHE *file);
3182
  virtual bool write_data_body(IO_CACHE *file);
3183
  virtual const char *get_db() { return m_dbnam; }
3184
#endif
3185
3186
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3187
  virtual void pack_info(Protocol *protocol);
3188
#endif
3189
3190
#ifdef MYSQL_CLIENT
3191
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3192
#endif
3193
3194
3195
private:
3196
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3197
  virtual int do_apply_event(Relay_log_info const *rli);
3198
  virtual int do_update_pos(Relay_log_info *rli);
3199
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3200
#endif
3201
3202
#ifndef MYSQL_CLIENT
3203
  TABLE         *m_table;
3204
#endif
3205
  char const    *m_dbnam;
3206
  size_t         m_dblen;
3207
  char const    *m_tblnam;
3208
  size_t         m_tbllen;
3209
  ulong          m_colcnt;
3210
  uchar         *m_coltype;
3211
3212
  uchar         *m_memory;
3213
  ulong          m_table_id;
3214
  flag_set       m_flags;
3215
3216
  size_t         m_data_size;
3217
3218
  uchar          *m_field_metadata;        // buffer for field metadata
3219
  /*
3220
    The size of field metadata buffer set by calling save_field_metadata()
3221
  */
3222
  ulong          m_field_metadata_size;   
3223
  uchar         *m_null_bits;
3224
  uchar         *m_meta_memory;
3225
};
3226
3227
3228
/**
3229
  @class Rows_log_event
3230
3231
 Common base class for all row-containing log events.
3232
3233
 RESPONSIBILITIES
3234
3235
   Encode the common parts of all events containing rows, which are:
3236
   - Write data header and data body to an IO_CACHE.
3237
   - Provide an interface for adding an individual row to the event.
3238
3239
  @section Rows_log_event_binary_format Binary Format
3240
*/
3241
3242
3243
class Rows_log_event : public Log_event
3244
{
3245
public:
3246
  /**
3247
     Enumeration of the errors that can be returned.
3248
   */
3249
  enum enum_error
3250
  {
3251
    ERR_OPEN_FAILURE = -1,               /**< Failure to open table */
3252
    ERR_OK = 0,                                 /**< No error */
3253
    ERR_TABLE_LIMIT_EXCEEDED = 1,      /**< No more room for tables */
3254
    ERR_OUT_OF_MEM = 2,                         /**< Out of memory */
3255
    ERR_BAD_TABLE_DEF = 3,     /**< Table definition does not match */
3256
    ERR_RBR_TO_SBR = 4  /**< daisy-chanining RBR to SBR not allowed */
3257
  };
3258
3259
  /*
3260
    These definitions allow you to combine the flags into an
3261
    appropriate flag set using the normal bitwise operators.  The
3262
    implicit conversion from an enum-constant to an integer is
3263
    accepted by the compiler, which is then used to set the real set
3264
    of flags.
3265
  */
3266
  enum enum_flag
3267
  {
3268
    /* Last event of a statement */
3269
    STMT_END_F = (1U << 0),
3270
3271
    /* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in thd->options */
3272
    NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
3273
3274
    /* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
3275
    RELAXED_UNIQUE_CHECKS_F = (1U << 2),
3276
3277
    /** 
3278
      Indicates that rows in this event are complete, that is contain
3279
      values for all columns of the table.
3280
     */
3281
    COMPLETE_ROWS_F = (1U << 3)
3282
  };
3283
206 by Brian Aker
Removed final uint dead types.
3284
  typedef uint16_t flag_set;
1 by brian
clean slate
3285
3286
  /* Special constants representing sets of flags */
3287
  enum 
3288
  {
3289
      RLE_NO_FLAGS = 0U
3290
  };
3291
3292
  virtual ~Rows_log_event();
3293
3294
  void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
3295
  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
3296
  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
3297
3298
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3299
  virtual void pack_info(Protocol *protocol);
3300
#endif
3301
3302
#ifdef MYSQL_CLIENT
3303
  /* not for direct call, each derived has its own ::print() */
3304
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0;
3305
#endif
3306
3307
#ifndef MYSQL_CLIENT
3308
  int add_row_data(uchar *data, size_t length)
3309
  {
3310
    return do_add_row_data(data,length); 
3311
  }
3312
#endif
3313
3314
  /* Member functions to implement superclass interface */
3315
  virtual int get_data_size();
3316
3317
  MY_BITMAP const *get_cols() const { return &m_cols; }
3318
  size_t get_width() const          { return m_width; }
3319
  ulong get_table_id() const        { return m_table_id; }
3320
3321
#ifndef MYSQL_CLIENT
3322
  virtual bool write_data_header(IO_CACHE *file);
3323
  virtual bool write_data_body(IO_CACHE *file);
3324
  virtual const char *get_db() { return m_table->s->db.str; }
3325
#endif
3326
  /*
3327
    Check that malloc() succeeded in allocating memory for the rows
3328
    buffer and the COLS vector. Checking that an Update_rows_log_event
3329
    is valid is done in the Update_rows_log_event::is_valid()
3330
    function.
3331
  */
3332
  virtual bool is_valid() const
3333
  {
3334
    return m_rows_buf && m_cols.bitmap;
3335
  }
3336
3337
  uint     m_row_count;         /* The number of rows added to the event */
3338
3339
protected:
3340
  /* 
3341
     The constructors are protected since you're supposed to inherit
3342
     this class, not create instances of this class.
3343
  */
3344
#ifndef MYSQL_CLIENT
3345
  Rows_log_event(THD*, TABLE*, ulong table_id, 
3346
		 MY_BITMAP const *cols, bool is_transactional);
3347
#endif
3348
  Rows_log_event(const char *row_data, uint event_len, 
3349
		 Log_event_type event_type,
3350
		 const Format_description_log_event *description_event);
3351
3352
#ifdef MYSQL_CLIENT
3353
  void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
3354
#endif
3355
3356
#ifndef MYSQL_CLIENT
3357
  virtual int do_add_row_data(uchar *data, size_t length);
3358
#endif
3359
3360
#ifndef MYSQL_CLIENT
3361
  TABLE *m_table;		/* The table the rows belong to */
3362
#endif
3363
  ulong       m_table_id;	/* Table ID */
3364
  MY_BITMAP   m_cols;		/* Bitmap denoting columns available */
3365
  ulong       m_width;          /* The width of the columns bitmap */
3366
  /*
3367
    Bitmap for columns available in the after image, if present. These
3368
    fields are only available for Update_rows events. Observe that the
3369
    width of both the before image COLS vector and the after image
3370
    COLS vector is the same: the number of columns of the table on the
3371
    master.
3372
  */
3373
  MY_BITMAP   m_cols_ai;
3374
3375
  ulong       m_master_reclength; /* Length of record on master side */
3376
3377
  /* Bit buffers in the same memory as the class */
205 by Brian Aker
uint32 -> uin32_t
3378
  uint32_t    m_bitbuf[128/(sizeof(uint32_t)*8)];
3379
  uint32_t    m_bitbuf_ai[128/(sizeof(uint32_t)*8)];
1 by brian
clean slate
3380
3381
  uchar    *m_rows_buf;		/* The rows in packed format */
3382
  uchar    *m_rows_cur;		/* One-after the end of the data */
3383
  uchar    *m_rows_end;		/* One-after the end of the allocated space */
3384
3385
  flag_set m_flags;		/* Flags for row-level events */
3386
3387
  /* helper functions */
3388
3389
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3390
  const uchar *m_curr_row;     /* Start of the row being processed */
3391
  const uchar *m_curr_row_end; /* One-after the end of the current row */
3392
  uchar    *m_key;      /* Buffer to keep key value during searches */
3393
3394
  int find_row(const Relay_log_info *const);
3395
  int write_row(const Relay_log_info *const, const bool);
3396
3397
  // Unpack the current row into m_table->record[0]
3398
  int unpack_current_row(const Relay_log_info *const rli,
3399
                         MY_BITMAP const *cols)
3400
  { 
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
3401
    assert(m_table);
1 by brian
clean slate
3402
    ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
3403
    int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
3404
                                   &m_curr_row_end, &m_master_reclength);
3405
    if (m_curr_row_end > m_rows_end)
3406
      my_error(ER_SLAVE_CORRUPT_EVENT, MYF(0));
3407
    ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
3408
    return result;
3409
  }
3410
#endif
3411
3412
private:
3413
3414
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3415
  virtual int do_apply_event(Relay_log_info const *rli);
3416
  virtual int do_update_pos(Relay_log_info *rli);
3417
  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3418
3419
  /*
3420
    Primitive to prepare for a sequence of row executions.
3421
3422
    DESCRIPTION
3423
3424
      Before doing a sequence of do_prepare_row() and do_exec_row()
3425
      calls, this member function should be called to prepare for the
3426
      entire sequence. Typically, this member function will allocate
3427
      space for any buffers that are needed for the two member
3428
      functions mentioned above.
3429
3430
    RETURN VALUE
3431
3432
      The member function will return 0 if all went OK, or a non-zero
3433
      error code otherwise.
3434
  */
3435
  virtual 
3436
  int do_before_row_operations(const Slave_reporting_capability *const log) = 0;
3437
3438
  /*
3439
    Primitive to clean up after a sequence of row executions.
3440
3441
    DESCRIPTION
3442
    
3443
      After doing a sequence of do_prepare_row() and do_exec_row(),
3444
      this member function should be called to clean up and release
3445
      any allocated buffers.
3446
      
3447
      The error argument, if non-zero, indicates an error which happened during
3448
      row processing before this function was called. In this case, even if 
3449
      function is successful, it should return the error code given in the argument.
3450
  */
3451
  virtual 
3452
  int do_after_row_operations(const Slave_reporting_capability *const log,
3453
                              int error) = 0;
3454
3455
  /*
3456
    Primitive to do the actual execution necessary for a row.
3457
3458
    DESCRIPTION
3459
      The member function will do the actual execution needed to handle a row.
3460
      The row is located at m_curr_row. When the function returns, 
3461
      m_curr_row_end should point at the next row (one byte after the end
3462
      of the current row).    
3463
3464
    RETURN VALUE
3465
      0 if execution succeeded, 1 if execution failed.
3466
      
3467
  */
3468
  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
3469
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3470
3471
  friend class Old_rows_log_event;
3472
};
3473
3474
/**
3475
  @class Write_rows_log_event
3476
3477
  Log row insertions and updates. The event contain several
3478
  insert/update rows for a table. Note that each event contains only
3479
  rows for one table.
3480
3481
  @section Write_rows_log_event_binary_format Binary Format
3482
*/
3483
class Write_rows_log_event : public Rows_log_event
3484
{
3485
public:
3486
  enum 
3487
  {
3488
    /* Support interface to THD::binlog_prepare_pending_rows_event */
3489
    TYPE_CODE = WRITE_ROWS_EVENT
3490
  };
3491
3492
#if !defined(MYSQL_CLIENT)
3493
  Write_rows_log_event(THD*, TABLE*, ulong table_id, 
3494
		       bool is_transactional);
3495
#endif
3496
#ifdef HAVE_REPLICATION
3497
  Write_rows_log_event(const char *buf, uint event_len, 
3498
                       const Format_description_log_event *description_event);
3499
#endif
3500
#if !defined(MYSQL_CLIENT) 
3501
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3502
                                          bool is_transactional,
3503
                                          const uchar *before_record
3504
                                          __attribute__((unused)),
3505
                                          const uchar *after_record)
3506
  {
3507
    return thd->binlog_write_row(table, is_transactional, after_record);
3508
  }
3509
#endif
3510
3511
private:
3512
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3513
3514
#ifdef MYSQL_CLIENT
3515
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3516
#endif
3517
3518
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3519
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3520
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3521
  virtual int do_exec_row(const Relay_log_info *const);
3522
#endif
3523
};
3524
3525
3526
/**
3527
  @class Update_rows_log_event
3528
3529
  Log row updates with a before image. The event contain several
3530
  update rows for a table. Note that each event contains only rows for
3531
  one table.
3532
3533
  Also note that the row data consists of pairs of row data: one row
3534
  for the old data and one row for the new data.
3535
3536
  @section Update_rows_log_event_binary_format Binary Format
3537
*/
3538
class Update_rows_log_event : public Rows_log_event
3539
{
3540
public:
3541
  enum 
3542
  {
3543
    /* Support interface to THD::binlog_prepare_pending_rows_event */
3544
    TYPE_CODE = UPDATE_ROWS_EVENT
3545
  };
3546
3547
#ifndef MYSQL_CLIENT
3548
  Update_rows_log_event(THD*, TABLE*, ulong table_id,
3549
                        bool is_transactional);
3550
3551
  void init(MY_BITMAP const *cols);
3552
#endif
3553
3554
  virtual ~Update_rows_log_event();
3555
3556
#ifdef HAVE_REPLICATION
3557
  Update_rows_log_event(const char *buf, uint event_len, 
3558
			const Format_description_log_event *description_event);
3559
#endif
3560
3561
#if !defined(MYSQL_CLIENT) 
3562
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3563
                                          bool is_transactional,
3564
                                          const uchar *before_record,
3565
                                          const uchar *after_record)
3566
  {
3567
    return thd->binlog_update_row(table, is_transactional,
3568
                                  before_record, after_record);
3569
  }
3570
#endif
3571
3572
  virtual bool is_valid() const
3573
  {
3574
    return Rows_log_event::is_valid() && m_cols_ai.bitmap;
3575
  }
3576
3577
protected:
3578
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3579
3580
#ifdef MYSQL_CLIENT
3581
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3582
#endif
3583
3584
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3585
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3586
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3587
  virtual int do_exec_row(const Relay_log_info *const);
3588
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
3589
};
3590
3591
/**
3592
  @class Delete_rows_log_event
3593
3594
  Log row deletions. The event contain several delete rows for a
3595
  table. Note that each event contains only rows for one table.
3596
3597
  RESPONSIBILITIES
3598
3599
    - Act as a container for rows that has been deleted on the master
3600
      and should be deleted on the slave. 
3601
3602
  COLLABORATION
3603
3604
    Row_writer
3605
      Create the event and add rows to the event.
3606
    Row_reader
3607
      Extract the rows from the event.
3608
3609
  @section Delete_rows_log_event_binary_format Binary Format
3610
*/
3611
class Delete_rows_log_event : public Rows_log_event
3612
{
3613
public:
3614
  enum 
3615
  {
3616
    /* Support interface to THD::binlog_prepare_pending_rows_event */
3617
    TYPE_CODE = DELETE_ROWS_EVENT
3618
  };
3619
3620
#ifndef MYSQL_CLIENT
3621
  Delete_rows_log_event(THD*, TABLE*, ulong, 
3622
			bool is_transactional);
3623
#endif
3624
#ifdef HAVE_REPLICATION
3625
  Delete_rows_log_event(const char *buf, uint event_len, 
3626
			const Format_description_log_event *description_event);
3627
#endif
3628
#if !defined(MYSQL_CLIENT) 
3629
  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3630
                                          bool is_transactional,
3631
                                          const uchar *before_record,
3632
                                          const uchar *after_record
3633
                                          __attribute__((unused)))
3634
  {
3635
    return thd->binlog_delete_row(table, is_transactional, before_record);
3636
  }
3637
#endif
3638
  
3639
protected:
3640
  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3641
3642
#ifdef MYSQL_CLIENT
3643
  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3644
#endif
3645
3646
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3647
  virtual int do_before_row_operations(const Slave_reporting_capability *const);
3648
  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3649
  virtual int do_exec_row(const Relay_log_info *const);
3650
#endif
3651
};
3652
3653
3654
/**
3655
  @class Incident_log_event
3656
3657
   Class representing an incident, an occurance out of the ordinary,
3658
   that happened on the master.
3659
3660
   The event is used to inform the slave that something out of the
3661
   ordinary happened on the master that might cause the database to be
3662
   in an inconsistent state.
3663
3664
   <table id="IncidentFormat">
3665
   <caption>Incident event format</caption>
3666
   <tr>
3667
     <th>Symbol</th>
3668
     <th>Format</th>
3669
     <th>Description</th>
3670
   </tr>
3671
   <tr>
3672
     <td>INCIDENT</td>
3673
     <td align="right">2</td>
3674
     <td>Incident number as an unsigned integer</td>
3675
   </tr>
3676
   <tr>
3677
     <td>MSGLEN</td>
3678
     <td align="right">1</td>
3679
     <td>Message length as an unsigned integer</td>
3680
   </tr>
3681
   <tr>
3682
     <td>MESSAGE</td>
3683
     <td align="right">MSGLEN</td>
3684
     <td>The message, if present. Not null terminated.</td>
3685
   </tr>
3686
   </table>
3687
3688
  @section Delete_rows_log_event_binary_format Binary Format
3689
*/
3690
class Incident_log_event : public Log_event {
3691
public:
3692
#ifndef MYSQL_CLIENT
3693
  Incident_log_event(THD *thd_arg, Incident incident)
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
3694
    : Log_event(thd_arg, 0, false), m_incident(incident)
1 by brian
clean slate
3695
  {
3696
    m_message.str= NULL;                    /* Just as a precaution */
3697
    m_message.length= 0;
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
3698
    return;
1 by brian
clean slate
3699
  }
3700
3701
  Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
163 by Brian Aker
Merge Monty's code.
3702
    : Log_event(thd_arg, 0, false), m_incident(incident)
1 by brian
clean slate
3703
  {
3704
    m_message= msg;
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
3705
    return;
1 by brian
clean slate
3706
  }
3707
#endif
3708
3709
#ifndef MYSQL_CLIENT
3710
  void pack_info(Protocol*);
3711
#endif
3712
3713
  Incident_log_event(const char *buf, uint event_len,
3714
                     const Format_description_log_event *descr_event);
3715
3716
  virtual ~Incident_log_event();
3717
3718
#ifdef MYSQL_CLIENT
3719
  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3720
#endif
3721
3722
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3723
  virtual int do_apply_event(Relay_log_info const *rli);
3724
#endif
3725
3726
  virtual bool write_data_header(IO_CACHE *file);
3727
  virtual bool write_data_body(IO_CACHE *file);
3728
3729
  virtual Log_event_type get_type_code() { return INCIDENT_EVENT; }
3730
3731
  virtual bool is_valid() const { return 1; }
3732
  virtual int get_data_size() {
3733
    return INCIDENT_HEADER_LEN + 1 + m_message.length;
3734
  }
3735
3736
private:
3737
  const char *description() const;
3738
3739
  Incident m_incident;
3740
  LEX_STRING m_message;
3741
};
3742
3743
static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3744
                                                       FILE *file)
3745
{
3746
  return         
3747
    my_b_copy_to_file(cache, file) ||
51.1.31 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
3748
    reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
1 by brian
clean slate
3749
}
3750
3751
#ifndef MYSQL_CLIENT
3752
/*****************************************************************************
3753
3754
  Heartbeat Log Event class
3755
3756
  Replication event to ensure to slave that master is alive.
3757
  The event is originated by master's dump thread and sent straight to
3758
  slave without being logged. Slave itself does not store it in relay log
3759
  but rather uses a data for immediate checks and throws away the event.
3760
3761
  Two members of the class log_ident and Log_event::log_pos comprise 
3762
  @see the event_coordinates instance. The coordinates that a heartbeat
3763
  instance carries correspond to the last event master has sent from
3764
  its binlog.
3765
3766
 ****************************************************************************/
3767
class Heartbeat_log_event: public Log_event
3768
{
3769
public:
3770
  Heartbeat_log_event(const char* buf, uint event_len,
3771
                      const Format_description_log_event* description_event);
3772
  Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
3773
  bool is_valid() const
3774
    {
3775
      return (log_ident != NULL &&
3776
              log_pos >= BIN_LOG_HEADER_SIZE);
3777
    }
3778
  const char * get_log_ident() { return log_ident; }
3779
  uint get_ident_len() { return ident_len; }
3780
  
3781
private:
3782
  const char* log_ident;
3783
  uint ident_len;
3784
};
3785
#endif
3786
3787
/**
3788
  @} (end of group Replication)
3789
*/
3790
3791
#endif /* _log_event_h */