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