1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
17
@addtogroup Replication
549
class DRIZZLE_BIN_LOG;
552
557
class Format_description_log_event;
553
558
class Relay_log_info;
561
enum enum_base64_output_mode {
562
BASE64_OUTPUT_NEVER= 0,
563
BASE64_OUTPUT_AUTO= 1,
564
BASE64_OUTPUT_ALWAYS= 2,
565
BASE64_OUTPUT_UNSPEC= 3,
566
/* insert new output modes here */
567
BASE64_OUTPUT_MODE_COUNT
571
A structure for mysqlbinlog to know how to print events
573
This structure is passed to the event's print() methods,
575
There are two types of settings stored here:
576
1. Last db, flags2, sql_mode etc comes from the last printed event.
577
They are stored so that only the necessary USE and SET commands
579
2. Other information on how to print the events, e.g. short_form,
580
hexdump_from. These are not dependent on the last event.
582
typedef struct st_print_event_info
585
Settings for database, sql_mode etc that comes from the last event
586
that was printed. We cache these so that we don't have to print
587
them if they are unchanged.
589
// TODO: have the last catalog here ??
590
char db[FN_REFLEN+1]; // TODO: make this a LEX_STRING when thd->db is
593
bool sql_mode_inited;
594
ulong sql_mode; /* must be same as THD.variables.sql_mode */
595
ulong auto_increment_increment, auto_increment_offset;
597
char charset[6]; // 3 variables, each of them storable in 2 bytes
598
char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
599
uint lc_time_names_number;
600
uint charset_database_number;
602
bool thread_id_printed;
604
st_print_event_info();
606
~st_print_event_info() {
607
close_cached_file(&head_cache);
608
close_cached_file(&body_cache);
610
bool init_ok() /* tells if construction was successful */
611
{ return my_b_inited(&head_cache) && my_b_inited(&body_cache); }
614
/* Settings on how to print the events */
616
enum_base64_output_mode base64_output_mode;
618
This is set whenever a Format_description_event is printed.
619
Later, when an event is printed in base64, this flag is tested: if
620
no Format_description_event has been seen, it is unsafe to print
621
the base64 event, so an error message is generated.
623
bool printed_fd_event;
624
my_off_t hexdump_from;
625
uint8 common_header_len;
629
These two caches are used by the row-based replication events to
630
collect the header information and the main body of the events
631
making up a statement.
556
639
the struct aggregates two paramenters that identify an event
557
640
uniquely in scope of communication of a particular master and slave couple.
822
907
virtual void pack_info(Protocol *protocol);
909
#endif /* HAVE_REPLICATION */
824
910
virtual const char* get_db()
826
912
return thd ? thd->db : 0;
915
Log_event() : temp_buf(0) {}
916
/* avoid having to link mysqlbinlog against libpthread */
917
static Log_event* read_log_event(IO_CACHE* file,
918
const Format_description_log_event
920
/* print*() functions are used by mysqlbinlog */
921
virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
922
void print_timestamp(IO_CACHE* file, time_t *ts = 0);
923
void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
925
void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
829
929
static void *operator new(size_t size)
831
931
return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE));
834
static void operator delete(void *ptr,
835
size_t size __attribute__((unused)))
934
static void operator delete(void *ptr, size_t size)
837
free((unsigned char*) ptr);
936
my_free((uchar*) ptr, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
840
939
/* Placement version of the above operators */
841
940
static void *operator new(size_t, void* ptr) { return ptr; }
842
941
static void operator delete(void*, void*) { }
844
944
bool write_header(IO_CACHE* file, ulong data_length);
845
945
virtual bool write(IO_CACHE* file)
1441
1544
bool sql_mode_inited;
1442
1545
bool charset_inited;
1445
1548
/* In connections sql_mode is 32 bits now but will be 64 bits soon */
1446
1549
ulong sql_mode;
1447
1550
ulong auto_increment_increment, auto_increment_offset;
1448
1551
char charset[6];
1449
uint32_t time_zone_len; /* 0 means uninited */
1552
uint time_zone_len; /* 0 means uninited */
1450
1553
const char *time_zone_str;
1451
uint32_t lc_time_names_number; /* 0 means en_US */
1452
uint32_t charset_database_number;
1554
uint lc_time_names_number; /* 0 means en_US */
1555
uint charset_database_number;
1557
#ifndef MYSQL_CLIENT
1455
1559
Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
1456
1560
bool using_trans, bool suppress_use,
1457
1561
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1458
1562
const char* get_db() { return db; }
1563
#ifdef HAVE_REPLICATION
1459
1564
void pack_info(Protocol* protocol);
1565
#endif /* HAVE_REPLICATION */
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);
1461
1571
Query_log_event();
1462
Query_log_event(const char* buf, uint32_t event_len,
1572
Query_log_event(const char* buf, uint event_len,
1463
1573
const Format_description_log_event *description_event,
1464
1574
Log_event_type event_type);
1465
1575
~Query_log_event()
1468
free((unsigned char*) data_buf);
1578
my_free((uchar*) data_buf, MYF(0));
1470
1580
Log_event_type get_type_code() { return QUERY_EVENT; }
1581
#ifndef MYSQL_CLIENT
1471
1582
bool write(IO_CACHE* file);
1472
virtual bool write_post_header_for_derived(IO_CACHE* file __attribute__((unused)))
1583
virtual bool write_post_header_for_derived(IO_CACHE* file) { return FALSE; }
1474
1585
bool is_valid() const { return query != 0; }
1543
1657
class Slave_log_event: public Log_event
1546
1660
char* mem_pool;
1547
void init_from_mem_pool();
1661
void init_from_mem_pool(int data_size);
1550
std::string master_host;
1551
std::string master_log;
1552
uint16_t master_port;
1663
my_off_t master_pos;
1666
int master_host_len;
1670
#ifndef MYSQL_CLIENT
1554
1671
Slave_log_event(THD* thd_arg, Relay_log_info* rli);
1555
1672
void pack_info(Protocol* protocol);
1674
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
1557
Slave_log_event(const char* buf, uint32_t event_len);
1677
Slave_log_event(const char* buf, uint event_len);
1558
1678
~Slave_log_event();
1559
1679
int get_data_size();
1560
bool is_valid() const { return master_host.length() != 0; }
1680
bool is_valid() const { return master_host != 0; }
1561
1681
Log_event_type get_type_code() { return SLAVE_EVENT; }
1682
#ifndef MYSQL_CLIENT
1562
1683
bool write(IO_CACHE* file);
1687
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1565
1688
virtual int do_apply_event(Relay_log_info const* rli);
1692
#endif /* HAVE_REPLICATION */
1570
1696
@class Load_log_event
1965
2113
LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
1966
2114
(those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
1968
uint8_t common_header_len;
1969
uint8_t number_of_event_types;
2116
uint8 common_header_len;
2117
uint8 number_of_event_types;
1970
2118
/* The list of post-headers' lengthes */
1971
uint8_t *post_header_len;
1972
unsigned char server_version_split[3];
1973
const uint8_t *event_type_permutation;
2119
uint8 *post_header_len;
2120
uchar server_version_split[3];
2121
const uint8 *event_type_permutation;
1975
Format_description_log_event(uint8_t binlog_ver, const char* server_ver=0);
1976
Format_description_log_event(const char* buf, uint32_t event_len,
2123
Format_description_log_event(uint8 binlog_ver, const char* server_ver=0);
2124
Format_description_log_event(const char* buf, uint event_len,
1977
2125
const Format_description_log_event
1978
2126
*description_event);
1979
2127
~Format_description_log_event()
1981
free((unsigned char*)post_header_len);
2129
my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR));
1983
2131
Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;}
2132
#ifndef MYSQL_CLIENT
1984
2133
bool write(IO_CACHE* file);
1985
2135
bool is_valid() const
1987
2137
return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN :
2112
2274
class Rand_log_event: public Log_event
2118
Rand_log_event(THD* thd_arg, uint64_t seed1_arg, uint64_t seed2_arg)
2280
#ifndef MYSQL_CLIENT
2281
Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
2119
2282
:Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2284
#ifdef HAVE_REPLICATION
2121
2285
void pack_info(Protocol* protocol);
2286
#endif /* HAVE_REPLICATION */
2288
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2123
2291
Rand_log_event(const char* buf,
2124
2292
const Format_description_log_event *description_event);
2125
2293
~Rand_log_event() {}
2126
2294
Log_event_type get_type_code() { return RAND_EVENT;}
2127
int get_data_size() { return 16; /* sizeof(uint64_t) * 2*/ }
2295
int get_data_size() { return 16; /* sizeof(ulonglong) * 2*/ }
2296
#ifndef MYSQL_CLIENT
2128
2297
bool write(IO_CACHE* file);
2129
2299
bool is_valid() const { return 1; }
2302
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2132
2303
virtual int do_apply_event(Relay_log_info const *rli);
2133
2304
virtual int do_update_pos(Relay_log_info *rli);
2134
2305
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2143
2315
@section Xid_log_event_binary_format Binary Format
2318
typedef ulonglong my_xid; // this line is the same as in handler.h
2145
2321
class Xid_log_event: public Log_event
2326
#ifndef MYSQL_CLIENT
2150
2327
Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
2328
#ifdef HAVE_REPLICATION
2151
2329
void pack_info(Protocol* protocol);
2330
#endif /* HAVE_REPLICATION */
2332
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2153
2335
Xid_log_event(const char* buf,
2154
2336
const Format_description_log_event *description_event);
2155
2337
~Xid_log_event() {}
2156
2338
Log_event_type get_type_code() { return XID_EVENT;}
2157
2339
int get_data_size() { return sizeof(xid); }
2340
#ifndef MYSQL_CLIENT
2158
2341
bool write(IO_CACHE* file);
2159
2343
bool is_valid() const { return 1; }
2346
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2162
2347
virtual int do_apply_event(Relay_log_info const *rli);
2163
2348
enum_skip_reason do_shall_skip(Relay_log_info *rli);
2182
2368
Item_result type;
2183
uint32_t charset_number;
2369
uint charset_number;
2185
User_var_log_event(THD* thd_arg __attribute__((unused)),
2186
char *name_arg, uint32_t name_len_arg,
2371
#ifndef MYSQL_CLIENT
2372
User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
2187
2373
char *val_arg, ulong val_len_arg, Item_result type_arg,
2188
uint32_t charset_number_arg)
2374
uint charset_number_arg)
2189
2375
:Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
2190
2376
val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
2191
2377
{ is_null= !val; }
2192
2378
void pack_info(Protocol* protocol);
2380
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2194
2383
User_var_log_event(const char* buf,
2195
2384
const Format_description_log_event *description_event);
2196
2385
~User_var_log_event() {}
2197
2386
Log_event_type get_type_code() { return USER_VAR_EVENT;}
2387
#ifndef MYSQL_CLIENT
2198
2388
bool write(IO_CACHE* file);
2199
2390
bool is_valid() const { return 1; }
2393
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2202
2394
virtual int do_apply_event(Relay_log_info const *rli);
2203
2395
virtual int do_update_pos(Relay_log_info *rli);
2204
2396
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2298
2497
DUP_NAME= 2 // if constructor should dup the string argument
2300
2499
const char* new_log_ident;
2503
#ifndef MYSQL_CLIENT
2304
2504
Rotate_log_event(const char* new_log_ident_arg,
2305
uint32_t ident_len_arg,
2306
uint64_t pos_arg, uint32_t flags);
2506
ulonglong pos_arg, uint flags);
2507
#ifdef HAVE_REPLICATION
2307
2508
void pack_info(Protocol* protocol);
2509
#endif /* HAVE_REPLICATION */
2511
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2309
Rotate_log_event(const char* buf, uint32_t event_len,
2514
Rotate_log_event(const char* buf, uint event_len,
2310
2515
const Format_description_log_event* description_event);
2311
2516
~Rotate_log_event()
2313
2518
if (flags & DUP_NAME)
2314
free((unsigned char*) new_log_ident);
2519
my_free((uchar*) new_log_ident, MYF(MY_ALLOW_ZERO_PTR));
2316
2521
Log_event_type get_type_code() { return ROTATE_EVENT;}
2317
2522
int get_data_size() { return ident_len + ROTATE_HEADER_LEN;}
2318
2523
bool is_valid() const { return new_log_ident != 0; }
2524
#ifndef MYSQL_CLIENT
2319
2525
bool write(IO_CACHE* file);
2529
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2322
2530
virtual int do_update_pos(Relay_log_info *rli);
2323
2531
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2343
2552
bool fake_base;
2345
unsigned char* block;
2346
2555
const char *event_buf;
2349
2558
bool inited_from_old;
2560
#ifndef MYSQL_CLIENT
2351
2561
Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
2352
2562
const char* table_name_arg,
2353
2563
List<Item>& fields_arg,
2354
2564
enum enum_duplicates handle_dup, bool ignore,
2355
unsigned char* block_arg, uint32_t block_len_arg,
2565
uchar* block_arg, uint block_len_arg,
2356
2566
bool using_trans);
2567
#ifdef HAVE_REPLICATION
2357
2568
void pack_info(Protocol* protocol);
2569
#endif /* HAVE_REPLICATION */
2571
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2572
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2359
Create_file_log_event(const char* buf, uint32_t event_len,
2576
Create_file_log_event(const char* buf, uint event_len,
2360
2577
const Format_description_log_event* description_event);
2361
2578
~Create_file_log_event()
2363
free((char*) event_buf);
2580
my_free((char*) event_buf, MYF(MY_ALLOW_ZERO_PTR));
2366
2583
Log_event_type get_type_code()
2413
2634
const char* db;
2415
Append_block_log_event(THD* thd, const char* db_arg, unsigned char* block_arg,
2416
uint32_t block_len_arg, bool using_trans);
2636
#ifndef MYSQL_CLIENT
2637
Append_block_log_event(THD* thd, const char* db_arg, uchar* block_arg,
2638
uint block_len_arg, bool using_trans);
2639
#ifdef HAVE_REPLICATION
2417
2640
void pack_info(Protocol* protocol);
2418
2641
virtual int get_create_or_append() const;
2642
#endif /* HAVE_REPLICATION */
2644
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2420
Append_block_log_event(const char* buf, uint32_t event_len,
2647
Append_block_log_event(const char* buf, uint event_len,
2421
2648
const Format_description_log_event
2422
2649
*description_event);
2423
2650
~Append_block_log_event() {}
2424
2651
Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;}
2425
2652
int get_data_size() { return block_len + APPEND_BLOCK_HEADER_LEN ;}
2426
2653
bool is_valid() const { return block != 0; }
2654
#ifndef MYSQL_CLIENT
2427
2655
bool write(IO_CACHE* file);
2428
2656
const char* get_db() { return db; }
2660
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2431
2661
virtual int do_apply_event(Relay_log_info const *rli);
2441
2672
class Delete_file_log_event: public Log_event
2445
2676
const char* db; /* see comment in Append_block_log_event */
2678
#ifndef MYSQL_CLIENT
2447
2679
Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
2680
#ifdef HAVE_REPLICATION
2448
2681
void pack_info(Protocol* protocol);
2682
#endif /* HAVE_REPLICATION */
2684
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2685
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2450
Delete_file_log_event(const char* buf, uint32_t event_len,
2689
Delete_file_log_event(const char* buf, uint event_len,
2451
2690
const Format_description_log_event* description_event);
2452
2691
~Delete_file_log_event() {}
2453
2692
Log_event_type get_type_code() { return DELETE_FILE_EVENT;}
2454
2693
int get_data_size() { return DELETE_FILE_HEADER_LEN ;}
2455
2694
bool is_valid() const { return file_id != 0; }
2695
#ifndef MYSQL_CLIENT
2456
2696
bool write(IO_CACHE* file);
2457
2697
const char* get_db() { return db; }
2701
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2460
2702
virtual int do_apply_event(Relay_log_info const *rli);
2470
2713
class Execute_load_log_event: public Log_event
2474
2717
const char* db; /* see comment in Append_block_log_event */
2719
#ifndef MYSQL_CLIENT
2476
2720
Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
2721
#ifdef HAVE_REPLICATION
2477
2722
void pack_info(Protocol* protocol);
2723
#endif /* HAVE_REPLICATION */
2725
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2479
Execute_load_log_event(const char* buf, uint32_t event_len,
2728
Execute_load_log_event(const char* buf, uint event_len,
2480
2729
const Format_description_log_event
2481
2730
*description_event);
2482
2731
~Execute_load_log_event() {}
2483
2732
Log_event_type get_type_code() { return EXEC_LOAD_EVENT;}
2484
2733
int get_data_size() { return EXEC_LOAD_HEADER_LEN ;}
2485
2734
bool is_valid() const { return file_id != 0; }
2735
#ifndef MYSQL_CLIENT
2486
2736
bool write(IO_CACHE* file);
2487
2737
const char* get_db() { return db; }
2741
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2490
2742
virtual int do_apply_event(Relay_log_info const *rli);
2503
2756
class Begin_load_query_log_event: public Append_block_log_event
2759
#ifndef MYSQL_CLIENT
2506
2760
Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
2507
unsigned char* block_arg, uint32_t block_len_arg,
2761
uchar* block_arg, uint block_len_arg,
2508
2762
bool using_trans);
2763
#ifdef HAVE_REPLICATION
2509
2764
Begin_load_query_log_event(THD* thd);
2510
2765
int get_create_or_append() const;
2511
Begin_load_query_log_event(const char* buf, uint32_t event_len,
2766
#endif /* HAVE_REPLICATION */
2768
Begin_load_query_log_event(const char* buf, uint event_len,
2512
2769
const Format_description_log_event
2513
2770
*description_event);
2514
2771
~Begin_load_query_log_event() {}
2515
2772
Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; }
2774
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2517
2775
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
2549
2808
enum_load_dup_handling dup_handling;
2810
#ifndef MYSQL_CLIENT
2551
2811
Execute_load_query_log_event(THD* thd, const char* query_arg,
2552
ulong query_length, uint32_t fn_pos_start_arg,
2553
uint32_t fn_pos_end_arg,
2812
ulong query_length, uint fn_pos_start_arg,
2813
uint fn_pos_end_arg,
2554
2814
enum_load_dup_handling dup_handling_arg,
2555
2815
bool using_trans, bool suppress_use,
2556
2816
THD::killed_state
2557
2817
killed_err_arg= THD::KILLED_NO_VALUE);
2818
#ifdef HAVE_REPLICATION
2558
2819
void pack_info(Protocol* protocol);
2559
Execute_load_query_log_event(const char* buf, uint32_t event_len,
2820
#endif /* HAVE_REPLICATION */
2822
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2823
/* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2824
void print(FILE* file, PRINT_EVENT_INFO* print_event_info,
2825
const char *local_fname);
2827
Execute_load_query_log_event(const char* buf, uint event_len,
2560
2828
const Format_description_log_event
2561
2829
*description_event);
2562
2830
~Execute_load_query_log_event() {}
2565
2833
bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; }
2567
2835
ulong get_post_header_size_for_derived();
2836
#ifndef MYSQL_CLIENT
2568
2837
bool write_post_header_for_derived(IO_CACHE* file);
2841
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2571
2842
virtual int do_apply_event(Relay_log_info const *rli);
2575
char *str_to_hex(char *to, const char *from, uint32_t len);
2849
@class Unknown_log_event
2851
@section Unknown_log_event_binary_format Binary Format
2853
class Unknown_log_event: public Log_event
2857
Even if this is an unknown event, we still pass description_event to
2858
Log_event's ctor, this way we can extract maximum information from the
2859
event's header (the unique ID for example).
2861
Unknown_log_event(const char* buf,
2862
const Format_description_log_event *description_event):
2863
Log_event(buf, description_event)
2865
~Unknown_log_event() {}
2866
void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
2867
Log_event_type get_type_code() { return UNKNOWN_EVENT;}
2868
bool is_valid() const { return 1; }
2871
char *str_to_hex(char *to, const char *from, uint len);
2578
2874
@class Table_map_log_event
2704
<td>DRIZZLE_TYPE_TINY</td><td>1</td>
2706
<td>No column metadata.</td>
2710
<td>DRIZZLE_TYPE_SHORT</td><td>2</td>
2712
<td>No column metadata.</td>
2716
<td>DRIZZLE_TYPE_LONG</td><td>3</td>
2718
<td>No column metadata.</td>
2722
<td>DRIZZLE_TYPE_DOUBLE</td><td>5</td>
3000
<td>MYSQL_TYPE_DECIMAL</td><td>0</td>
3002
<td>No column metadata.</td>
3006
<td>MYSQL_TYPE_TINY</td><td>1</td>
3008
<td>No column metadata.</td>
3012
<td>MYSQL_TYPE_SHORT</td><td>2</td>
3014
<td>No column metadata.</td>
3018
<td>MYSQL_TYPE_LONG</td><td>3</td>
3020
<td>No column metadata.</td>
3024
<td>MYSQL_TYPE_FLOAT</td><td>4</td>
3026
<td>1 byte unsigned integer, representing the "pack_length", which
3027
is equal to sizeof(float) on the server from which the event
3032
<td>MYSQL_TYPE_DOUBLE</td><td>5</td>
2723
3033
<td>1 byte</td>
2724
3034
<td>1 byte unsigned integer, representing the "pack_length", which
2725
3035
is equal to sizeof(double) on the server from which the event
2730
<td>DRIZZLE_TYPE_NULL</td><td>6</td>
2732
<td>No column metadata.</td>
2736
<td>DRIZZLE_TYPE_TIMESTAMP</td><td>7</td>
2738
<td>No column metadata.</td>
2742
<td>DRIZZLE_TYPE_LONGLONG</td><td>8</td>
2744
<td>No column metadata.</td>
2748
<td>DRIZZLE_TYPE_DATE</td><td>10</td>
2750
<td>No column metadata.</td>
2754
<td>DRIZZLE_TYPE_TIME</td><td>11</td>
2756
<td>No column metadata.</td>
2760
<td>DRIZZLE_TYPE_DATETIME</td><td>12</td>
2762
<td>No column metadata.</td>
2766
<td>DRIZZLE_TYPE_YEAR</td><td>13</td>
2768
<td>No column metadata.</td>
2772
<td><i>DRIZZLE_TYPE_NEWDATE</i></td><td><i>14</i></td>
3040
<td>MYSQL_TYPE_NULL</td><td>6</td>
3042
<td>No column metadata.</td>
3046
<td>MYSQL_TYPE_TIMESTAMP</td><td>7</td>
3048
<td>No column metadata.</td>
3052
<td>MYSQL_TYPE_LONGLONG</td><td>8</td>
3054
<td>No column metadata.</td>
3058
<td>MYSQL_TYPE_INT24</td><td>9</td>
3060
<td>No column metadata.</td>
3064
<td>MYSQL_TYPE_DATE</td><td>10</td>
3066
<td>No column metadata.</td>
3070
<td>MYSQL_TYPE_TIME</td><td>11</td>
3072
<td>No column metadata.</td>
3076
<td>MYSQL_TYPE_DATETIME</td><td>12</td>
3078
<td>No column metadata.</td>
3082
<td>MYSQL_TYPE_YEAR</td><td>13</td>
3084
<td>No column metadata.</td>
3088
<td><i>MYSQL_TYPE_NEWDATE</i></td><td><i>14</i></td>
2773
3089
<td>–</td>
2774
3090
<td><i>This enumeration value is only used internally and cannot
2775
3091
exist in a binlog.</i></td>
2779
<td>DRIZZLE_TYPE_VARCHAR</td><td>15</td>
3095
<td>MYSQL_TYPE_VARCHAR</td><td>15</td>
2780
3096
<td>2 bytes</td>
2781
3097
<td>2 byte unsigned integer representing the maximum length of
2782
3098
the string.</td>
2786
<td>DRIZZLE_TYPE_NEWDECIMAL</td><td>246</td>
3102
<td>MYSQL_TYPE_BIT</td><td>16</td>
3104
<td>A 1 byte unsigned int representing the length in bits of the
3105
bitfield (0 to 64), followed by a 1 byte unsigned int
3106
representing the number of bytes occupied by the bitfield. The
3107
number of bytes is either int((length+7)/8) or int(length/8).</td>
3111
<td>MYSQL_TYPE_NEWDECIMAL</td><td>246</td>
2787
3112
<td>2 bytes</td>
2788
3113
<td>A 1 byte unsigned int representing the precision, followed
2789
3114
by a 1 byte unsigned int representing the number of decimals.</td>
2793
<td><i>DRIZZLE_TYPE_ENUM</i></td><td><i>247</i></td>
2795
<td><i>This enumeration value is only used internally and cannot
2796
exist in a binlog.</i></td>
2800
<td><i>DRIZZLE_TYPE_SET</i></td><td><i>248</i></td>
2802
<td><i>This enumeration value is only used internally and cannot
2803
exist in a binlog.</i></td>
2807
<td>DRIZZLE_TYPE_BLOB</td><td>252</td>
3118
<td><i>MYSQL_TYPE_ENUM</i></td><td><i>247</i></td>
3120
<td><i>This enumeration value is only used internally and cannot
3121
exist in a binlog.</i></td>
3125
<td><i>MYSQL_TYPE_SET</i></td><td><i>248</i></td>
3127
<td><i>This enumeration value is only used internally and cannot
3128
exist in a binlog.</i></td>
3132
<td>MYSQL_TYPE_TINY_BLOB</td><td>249</td>
3134
<td><i>This enumeration value is only used internally and cannot
3135
exist in a binlog.</i></td>
3139
<td><i>MYSQL_TYPE_MEDIUM_BLOB</i></td><td><i>250</i></td>
3141
<td><i>This enumeration value is only used internally and cannot
3142
exist in a binlog.</i></td>
3146
<td><i>MYSQL_TYPE_LONG_BLOB</i></td><td><i>251</i></td>
3148
<td><i>This enumeration value is only used internally and cannot
3149
exist in a binlog.</i></td>
3153
<td>MYSQL_TYPE_BLOB</td><td>252</td>
2808
3154
<td>1 byte</td>
2809
3155
<td>The pack length, i.e., the number of bytes needed to represent
2810
3156
the length of the blob: 1, 2, 3, or 4.</td>
2814
<td>DRIZZLE_TYPE_STRING</td><td>254</td>
2816
<td>The first byte is always DRIZZLE_TYPE_VAR_STRING (i.e., 253).
3160
<td>MYSQL_TYPE_VAR_STRING</td><td>253</td>
3162
<td>This is used to store both strings and enumeration values.
3163
The first byte is a enumeration value storing the <i>real
3164
type</i>, which may be either MYSQL_TYPE_VAR_STRING or
3165
MYSQL_TYPE_ENUM. The second byte is a 1 byte unsigned integer
3166
representing the field size, i.e., the number of bytes needed to
3167
store the length of the string.</td>
3171
<td>MYSQL_TYPE_STRING</td><td>254</td>
3173
<td>The first byte is always MYSQL_TYPE_VAR_STRING (i.e., 253).
2817
3174
The second byte is the field size, i.e., the number of bytes in
2818
3175
the representation of size of the string: 3 or 4.</td>
3179
<td>MYSQL_TYPE_GEOMETRY</td><td>255</td>
3181
<td>The pack length, i.e., the number of bytes needed to represent
3182
the length of the geometry: 1, 2, 3, or 4.</td>
2823
3187
class Table_map_log_event : public Log_event
2876
3244
virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ }
2878
3246
virtual int get_data_size() { return m_data_size; }
3247
#ifndef MYSQL_CLIENT
2879
3248
virtual int save_field_metadata();
2880
3249
virtual bool write_data_header(IO_CACHE *file);
2881
3250
virtual bool write_data_body(IO_CACHE *file);
2882
3251
virtual const char *get_db() { return m_dbnam; }
3254
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2883
3255
virtual void pack_info(Protocol *protocol);
3259
virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3264
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
2886
3265
virtual int do_apply_event(Relay_log_info const *rli);
2887
3266
virtual int do_update_pos(Relay_log_info *rli);
2888
3267
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
3270
#ifndef MYSQL_CLIENT
2891
3273
char const *m_dbnam;
2892
3274
size_t m_dblen;
2893
3275
char const *m_tblnam;
2894
3276
size_t m_tbllen;
2895
3277
ulong m_colcnt;
2896
unsigned char *m_coltype;
2898
unsigned char *m_memory;
2899
3281
ulong m_table_id;
2900
3282
flag_set m_flags;
2902
3284
size_t m_data_size;
2904
unsigned char *m_field_metadata; // buffer for field metadata
3286
uchar *m_field_metadata; // buffer for field metadata
2906
3288
The size of field metadata buffer set by calling save_field_metadata()
2908
3290
ulong m_field_metadata_size;
2909
unsigned char *m_null_bits;
2910
unsigned char *m_meta_memory;
3292
uchar *m_meta_memory;
3009
3402
return m_rows_buf && m_cols.bitmap;
3012
uint32_t m_row_count; /* The number of rows added to the event */
3405
uint m_row_count; /* The number of rows added to the event */
3016
3409
The constructors are protected since you're supposed to inherit
3017
3410
this class, not create instances of this class.
3019
Rows_log_event(THD*, Table*, ulong table_id,
3412
#ifndef MYSQL_CLIENT
3413
Rows_log_event(THD*, TABLE*, ulong table_id,
3020
3414
MY_BITMAP const *cols, bool is_transactional);
3021
Rows_log_event(const char *row_data, uint32_t event_len,
3416
Rows_log_event(const char *row_data, uint event_len,
3022
3417
Log_event_type event_type,
3023
3418
const Format_description_log_event *description_event);
3025
virtual int do_add_row_data(unsigned char *data, size_t length);
3027
Table *m_table; /* The table the rows belong to */
3421
void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
3424
#ifndef MYSQL_CLIENT
3425
virtual int do_add_row_data(uchar *data, size_t length);
3428
#ifndef MYSQL_CLIENT
3429
TABLE *m_table; /* The table the rows belong to */
3028
3431
ulong m_table_id; /* Table ID */
3029
3432
MY_BITMAP m_cols; /* Bitmap denoting columns available */
3030
3433
ulong m_width; /* The width of the columns bitmap */
3040
3443
ulong m_master_reclength; /* Length of record on master side */
3042
3445
/* Bit buffers in the same memory as the class */
3043
uint32_t m_bitbuf[128/(sizeof(uint32_t)*8)];
3044
uint32_t m_bitbuf_ai[128/(sizeof(uint32_t)*8)];
3446
uint32 m_bitbuf[128/(sizeof(uint32)*8)];
3447
uint32 m_bitbuf_ai[128/(sizeof(uint32)*8)];
3046
unsigned char *m_rows_buf; /* The rows in packed format */
3047
unsigned char *m_rows_cur; /* One-after the end of the data */
3048
unsigned char *m_rows_end; /* One-after the end of the allocated space */
3449
uchar *m_rows_buf; /* The rows in packed format */
3450
uchar *m_rows_cur; /* One-after the end of the data */
3451
uchar *m_rows_end; /* One-after the end of the allocated space */
3050
3453
flag_set m_flags; /* Flags for row-level events */
3052
3455
/* helper functions */
3054
const unsigned char *m_curr_row; /* Start of the row being processed */
3055
const unsigned char *m_curr_row_end; /* One-after the end of the current row */
3056
unsigned char *m_key; /* Buffer to keep key value during searches */
3457
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3458
const uchar *m_curr_row; /* Start of the row being processed */
3459
const uchar *m_curr_row_end; /* One-after the end of the current row */
3460
uchar *m_key; /* Buffer to keep key value during searches */
3058
3462
int find_row(const Relay_log_info *const);
3059
3463
int write_row(const Relay_log_info *const, const bool);
3150
3557
TYPE_CODE = WRITE_ROWS_EVENT
3153
Write_rows_log_event(THD*, Table*, ulong table_id,
3560
#if !defined(MYSQL_CLIENT)
3561
Write_rows_log_event(THD*, TABLE*, ulong table_id,
3154
3562
bool is_transactional);
3155
Write_rows_log_event(const char *buf, uint32_t event_len,
3564
#ifdef HAVE_REPLICATION
3565
Write_rows_log_event(const char *buf, uint event_len,
3156
3566
const Format_description_log_event *description_event);
3157
static bool binlog_row_logging_function(THD *thd, Table *table,
3568
#if !defined(MYSQL_CLIENT)
3569
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3158
3570
bool is_transactional,
3159
const unsigned char *before_record
3571
const uchar *before_record
3160
3572
__attribute__((unused)),
3161
const unsigned char *after_record)
3573
const uchar *after_record)
3163
3575
return thd->binlog_write_row(table, is_transactional, after_record);
3167
3580
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3583
void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3586
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3169
3587
virtual int do_before_row_operations(const Slave_reporting_capability *const);
3170
3588
virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3171
3589
virtual int do_exec_row(const Relay_log_info *const);
3193
3612
TYPE_CODE = UPDATE_ROWS_EVENT
3196
Update_rows_log_event(THD*, Table*, ulong table_id,
3615
#ifndef MYSQL_CLIENT
3616
Update_rows_log_event(THD*, TABLE*, ulong table_id,
3197
3617
bool is_transactional);
3199
3619
void init(MY_BITMAP const *cols);
3201
3622
virtual ~Update_rows_log_event();
3203
Update_rows_log_event(const char *buf, uint32_t event_len,
3624
#ifdef HAVE_REPLICATION
3625
Update_rows_log_event(const char *buf, uint event_len,
3204
3626
const Format_description_log_event *description_event);
3206
static bool binlog_row_logging_function(THD *thd, Table *table,
3629
#if !defined(MYSQL_CLIENT)
3630
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3207
3631
bool is_transactional,
3208
const unsigned char *before_record,
3209
const unsigned char *after_record)
3632
const uchar *before_record,
3633
const uchar *after_record)
3211
3635
return thd->binlog_update_row(table, is_transactional,
3212
3636
before_record, after_record);
3215
3640
virtual bool is_valid() const
3254
3685
TYPE_CODE = DELETE_ROWS_EVENT
3257
Delete_rows_log_event(THD*, Table*, ulong,
3688
#ifndef MYSQL_CLIENT
3689
Delete_rows_log_event(THD*, TABLE*, ulong,
3258
3690
bool is_transactional);
3259
Delete_rows_log_event(const char *buf, uint32_t event_len,
3692
#ifdef HAVE_REPLICATION
3693
Delete_rows_log_event(const char *buf, uint event_len,
3260
3694
const Format_description_log_event *description_event);
3261
static bool binlog_row_logging_function(THD *thd, Table *table,
3696
#if !defined(MYSQL_CLIENT)
3697
static bool binlog_row_logging_function(THD *thd, TABLE *table,
3262
3698
bool is_transactional,
3263
const unsigned char *before_record,
3264
const unsigned char *after_record
3699
const uchar *before_record,
3700
const uchar *after_record
3265
3701
__attribute__((unused)))
3267
3703
return thd->binlog_delete_row(table, is_transactional, before_record);
3271
3708
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
3711
void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3714
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3273
3715
virtual int do_before_row_operations(const Slave_reporting_capability *const);
3274
3716
virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
3275
3717
virtual int do_exec_row(const Relay_log_info *const);
3315
3758
class Incident_log_event : public Log_event {
3760
#ifndef MYSQL_CLIENT
3317
3761
Incident_log_event(THD *thd_arg, Incident incident)
3318
: Log_event(thd_arg, 0, false), m_incident(incident)
3762
: Log_event(thd_arg, 0, FALSE), m_incident(incident)
3764
DBUG_ENTER("Incident_log_event::Incident_log_event");
3765
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3320
3766
m_message.str= NULL; /* Just as a precaution */
3321
3767
m_message.length= 0;
3325
3771
Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
3326
: Log_event(thd_arg, 0, false), m_incident(incident)
3772
: Log_event(thd_arg, 0, FALSE), m_incident(incident)
3774
DBUG_ENTER("Incident_log_event::Incident_log_event");
3775
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
3328
3776
m_message= msg;
3781
#ifndef MYSQL_CLIENT
3332
3782
void pack_info(Protocol*);
3334
Incident_log_event(const char *buf, uint32_t event_len,
3785
Incident_log_event(const char *buf, uint event_len,
3335
3786
const Format_description_log_event *descr_event);
3337
3788
virtual ~Incident_log_event();
3791
virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
3794
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
3339
3795
virtual int do_apply_event(Relay_log_info const *rli);
3341
3798
virtual bool write_data_header(IO_CACHE *file);
3342
3799
virtual bool write_data_body(IO_CACHE *file);