194
194
Write_on_release_cache(IO_CACHE *cache, FILE *file, flag_set flags = 0)
195
195
: m_cache(cache), m_file(file), m_flags(flags)
197
reinit_io_cache(m_cache, WRITE_CACHE, 0L, FALSE, TRUE);
197
reinit_io_cache(m_cache, WRITE_CACHE, 0L, false, true);
200
200
~Write_on_release_cache()
679
676
rli->last_master_timestamp for only one time -
680
677
the first FLUSH LOGS in the test.
682
DBUG_EXECUTE_IF("let_first_flush_log_change_timestamp",
683
if (debug_not_change_ts_if_art_event == 1
684
&& is_artificial_event())
686
debug_not_change_ts_if_art_event= 0;
679
if (debug_not_change_ts_if_art_event == 1
680
&& is_artificial_event())
681
debug_not_change_ts_if_art_event= 0;
689
682
rli->stmt_done(log_pos,
690
683
is_artificial_event() &&
691
684
debug_not_change_ts_if_art_event > 0 ? 0 : when);
693
rli->stmt_done(log_pos, is_artificial_event()? 0 : when);
695
DBUG_EXECUTE_IF("let_first_flush_log_change_timestamp",
696
if (debug_not_change_ts_if_art_event == 0)
698
debug_not_change_ts_if_art_event= 2;
685
if (debug_not_change_ts_if_art_event == 0)
686
debug_not_change_ts_if_art_event= 2;
701
688
return 0; // Cannot fail currently
705
692
Log_event::enum_skip_reason
706
693
Log_event::do_shall_skip(Relay_log_info *rli)
708
DBUG_PRINT("info", ("ev->server_id=%lu, ::server_id=%lu,"
709
" rli->replicate_same_server_id=%d,"
710
" rli->slave_skip_counter=%d",
711
(ulong) server_id, (ulong) ::server_id,
712
rli->replicate_same_server_id,
713
rli->slave_skip_counter));
714
695
if ((server_id == ::server_id && !rli->replicate_same_server_id) || (rli->slave_skip_counter == 1 && rli->is_in_group()))
715
696
return EVENT_SKIP_IGNORE;
716
697
else if (rli->slave_skip_counter > 0)
818
797
relay log, we use the (new) my_b_safe_tell().
820
799
Note that this raises a question on the correctness of all these
821
DBUG_ASSERT(my_b_tell()=rli->event_relay_log_pos).
800
assert(my_b_tell()=rli->event_relay_log_pos).
823
802
If in a transaction, the log_pos which we calculate below is not
824
803
very good (because then my_b_safe_tell() returns start position
848
827
int4store(header+ LOG_POS_OFFSET, log_pos);
849
828
int2store(header+ FLAGS_OFFSET, flags);
851
DBUG_RETURN(my_b_safe_write(file, header, sizeof(header)) != 0);
830
return(my_b_safe_write(file, header, sizeof(header)) != 0);
966
941
LOG_EVENT_MINIMAL_HEADER_LEN);
969
DBUG_PRINT("info", ("my_b_tell: %lu", (ulong) my_b_tell(file)));
970
944
if (my_b_read(file, (uchar *) head, header_size))
972
DBUG_PRINT("info", ("Log_event::read_log_event(IO_CACHE*,Format_desc*) \
976
948
No error here; it could be that we are at the file's end. However
977
949
if the next my_b_read() fails (below), it will be an error as we
978
950
were able to read the first bytes.
982
954
uint data_len = uint4korr(head + EVENT_LEN_OFFSET);
1049
1021
const Format_description_log_event *description_event)
1052
DBUG_ENTER("Log_event::read_log_event(char*,...)");
1053
DBUG_ASSERT(description_event != 0);
1054
DBUG_PRINT("info", ("binlog_version: %d", description_event->binlog_version));
1055
DBUG_DUMP("data", (unsigned char*) buf, event_len);
1024
assert(description_event != 0);
1057
1026
/* Check the integrity */
1058
1027
if (event_len < EVENT_LEN_OFFSET ||
1092
1057
if (description_event->event_type_permutation)
1096
description_event->event_type_permutation[event_type];
1098
("converting event type %d to %d (%s)",
1099
event_type, new_event_type,
1100
get_type_str((Log_event_type)new_event_type)));
1059
int new_event_type= description_event->event_type_permutation[event_type];
1102
1060
event_type= description_event->event_type_permutation[event_type];
1177
1135
ev = new Incident_log_event(buf, event_len, description_event);
1180
DBUG_PRINT("error",("Unknown event code: %d",
1181
(int) buf[EVENT_TYPE_OFFSET]));
1187
DBUG_PRINT("read_event", ("%s(type_code: %d; event_len: %d)",
1188
ev ? ev->get_type_str() : "<unknown>",
1189
buf[EVENT_TYPE_OFFSET],
1192
1144
is_valid() are small event-specific sanity tests which are
1193
1145
important; for example there are some my_malloc() in constructors
1200
1152
if (!ev || !ev->is_valid())
1202
DBUG_PRINT("error",("Found invalid event in binary log"));
1205
1155
#ifdef MYSQL_CLIENT
1206
1156
if (!force_opt) /* then mysqlbinlog dies */
1208
1158
*error= "Found invalid event in binary log";
1211
1161
ev= new Unknown_log_event(buf, description_event);
1213
1163
*error= "Found invalid event in binary log";
1220
1170
#ifdef MYSQL_CLIENT
1264
1213
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1265
1214
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1266
1215
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1267
DBUG_ASSERT(bytes_written >= 0);
1268
DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1216
assert(bytes_written >= 0);
1217
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1269
1218
my_b_write(file, (uchar*) emit_buf, bytes_written);
1270
1219
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1271
1220
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1295
1244
"# %8.8lx %-48.48s |%16s|\n",
1296
1245
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1297
1246
hex_string, char_string);
1298
DBUG_ASSERT(bytes_written >= 0);
1299
DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1247
assert(bytes_written >= 0);
1248
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1300
1249
my_b_write(file, (uchar*) emit_buf, bytes_written);
1301
1250
hex_string[0]= 0;
1302
1251
char_string[0]= 0;
1315
1264
"# %8.8lx %-48.48s |%s|\n",
1316
1265
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1317
1266
hex_string, char_string);
1318
DBUG_ASSERT(bytes_written >= 0);
1319
DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1267
assert(bytes_written >= 0);
1268
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1320
1269
my_b_write(file, (uchar*) emit_buf, bytes_written);
1336
1285
const uchar *ptr= (const uchar *)temp_buf;
1337
1286
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
1338
DBUG_ENTER("Log_event::print_base64");
1340
1288
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1341
1289
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1342
1290
if (!tmp_str) {
1343
1291
fprintf(stderr, "\nError: Out of memory. "
1344
1292
"Could not print correct binlog event.\n");
1348
1296
if (base64_encode(ptr, (size_t) size, tmp_str))
1353
1301
if (my_b_tell(file) == 0)
1588
1535
if (time_zone_len)
1590
1537
/* In the TZ sys table, column Name is of length 64 so this should be ok */
1591
DBUG_ASSERT(time_zone_len <= MAX_TIME_ZONE_NAME_LENGTH);
1538
assert(time_zone_len <= MAX_TIME_ZONE_NAME_LENGTH);
1592
1539
*start++= Q_TIME_ZONE_CODE;
1593
1540
*start++= time_zone_len;
1594
1541
memcpy(start, time_zone_str, time_zone_len);
1597
1544
if (lc_time_names_number)
1599
DBUG_ASSERT(lc_time_names_number <= 0xFFFF);
1546
assert(lc_time_names_number <= 0xFFFF);
1600
1547
*start++= Q_LC_TIME_NAMES_CODE;
1601
1548
int2store(start, lc_time_names_number);
1604
1551
if (charset_database_number)
1606
DBUG_ASSERT(charset_database_number <= 0xFFFF);
1553
assert(charset_database_number <= 0xFFFF);
1607
1554
*start++= Q_CHARSET_DATABASE_CODE;
1608
1555
int2store(start, charset_database_number);
1717
1664
we will probably want to reclaim the 29 bits. So we need the &.
1719
1666
flags2= (uint32) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
1720
DBUG_ASSERT(thd_arg->variables.character_set_client->number < 256*256);
1721
DBUG_ASSERT(thd_arg->variables.collation_connection->number < 256*256);
1722
DBUG_ASSERT(thd_arg->variables.collation_server->number < 256*256);
1723
DBUG_ASSERT(thd_arg->variables.character_set_client->mbminlen == 1);
1667
assert(thd_arg->variables.character_set_client->number < 256*256);
1668
assert(thd_arg->variables.collation_connection->number < 256*256);
1669
assert(thd_arg->variables.collation_server->number < 256*256);
1670
assert(thd_arg->variables.character_set_client->mbminlen == 1);
1724
1671
int2store(charset, thd_arg->variables.character_set_client->number);
1725
1672
int2store(charset+2, thd_arg->variables.collation_connection->number);
1726
1673
int2store(charset+4, thd_arg->variables.collation_server->number);
1830
1773
#define CHECK_SPACE(PTR,END,CNT) \
1832
DBUG_PRINT("info", ("Read %s", code_name(pos[-1]))); \
1833
DBUG_ASSERT((PTR) + (CNT) <= (END)); \
1775
assert((PTR) + (CNT) <= (END)); \
1834
1776
if ((PTR) + (CNT) > (END)) { \
1835
DBUG_PRINT("info", ("query= 0")); \
1858
1799
Log_event::Byte *start;
1859
1800
const Log_event::Byte *end;
1860
1801
bool catalog_nz= 1;
1861
DBUG_ENTER("Query_log_event::Query_log_event(char*,...)");
1863
1803
common_header_len= description_event->common_header_len;
1864
1804
post_header_len= description_event->post_header_len[event_type-1];
1865
DBUG_PRINT("info",("event_len: %u common_header_len: %d post_header_len: %d",
1866
event_len, common_header_len, post_header_len));
1869
1807
We test if the event's length is sensible, and if so we compute data_len.
1898
1836
if (status_vars_len > min(data_len, MAX_SIZE_LOG_EVENT_STATUS))
1900
DBUG_PRINT("info", ("status_vars_len (%u) > data_len (%lu); query= 0",
1901
status_vars_len, data_len));
1905
1841
data_len-= status_vars_len;
1906
DBUG_PRINT("info", ("Query_log_event has status_vars_len: %u",
1907
(uint) status_vars_len));
1924
1858
CHECK_SPACE(pos, end, 4);
1925
1859
flags2_inited= 1;
1926
1860
flags2= uint4korr(pos);
1927
DBUG_PRINT("info",("In Query_log_event, read flags2: %lu", (ulong) flags2));
1930
1863
case Q_SQL_MODE_CODE:
1935
1866
CHECK_SPACE(pos, end, 8);
1936
1867
sql_mode_inited= 1;
1937
1868
sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong
1938
DBUG_PRINT("info",("In Query_log_event, read sql_mode: %s",
1939
llstr(sql_mode, buff)));
1943
1872
case Q_CATALOG_NZ_CODE:
1944
DBUG_PRINT("info", ("case Q_CATALOG_NZ_CODE; pos: 0x%lx; end: 0x%lx",
1945
(ulong) pos, (ulong) end));
1946
1873
if (get_str_len_and_pointer(&pos, &catalog, &catalog_len, end))
1948
DBUG_PRINT("info", ("query= 0"));
1953
1879
case Q_AUTO_INCREMENT:
2059
1982
if (!print_event_info->short_form)
2061
print_header(file, print_event_info, FALSE);
1984
print_header(file, print_event_info, false);
2062
1985
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
2063
1986
get_type_str(), (ulong) thread_id, (ulong) exec_time,
2291
2213
thd->query_id = next_query_id();
2292
2214
VOID(pthread_mutex_unlock(&LOCK_thread_count));
2293
2215
thd->variables.pseudo_thread_id= thread_id; // for temp tables
2294
DBUG_PRINT("query",("%s",thd->query));
2296
2217
if (ignored_error_code((expected_error= error_code)) ||
2297
2218
!check_expected_error(thd,rli,expected_error))
2410
2331
code, and none of them should be ignored.
2412
2333
actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0;
2413
DBUG_PRINT("info",("expected_error: %d sql_errno: %d",
2414
expected_error, actual_error));
2415
2334
if ((expected_error != actual_error) &&
2416
2335
expected_error &&
2417
2336
!ignored_error_code(actual_error) &&
2528
2445
Log_event::enum_skip_reason
2529
2446
Query_log_event::do_shall_skip(Relay_log_info *rli)
2531
DBUG_ENTER("Query_log_event::do_shall_skip");
2532
DBUG_PRINT("debug", ("query: %s; q_len: %d", query, q_len));
2533
DBUG_ASSERT(query && q_len > 0);
2448
assert(query && q_len > 0);
2535
2450
if (rli->slave_skip_counter > 0)
2537
2452
if (strcmp("BEGIN", query) == 0)
2539
2454
thd->options|= OPTION_BEGIN;
2540
DBUG_RETURN(Log_event::continue_group(rli));
2455
return(Log_event::continue_group(rli));
2543
2458
if (strcmp("COMMIT", query) == 0 || strcmp("ROLLBACK", query) == 0)
2545
2460
thd->options&= ~OPTION_BEGIN;
2546
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
2461
return(Log_event::EVENT_SKIP_COUNT);
2549
DBUG_RETURN(Log_event::do_shall_skip(rli));
2464
return(Log_event::do_shall_skip(rli));
2589
2504
#ifdef MYSQL_CLIENT
2590
2505
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2592
DBUG_ENTER("Start_log_event_v3::print");
2594
2507
Write_on_release_cache cache(&print_event_info->head_cache, file,
2595
2508
Write_on_release_cache::FLUSH_F);
2597
2510
if (!print_event_info->short_form)
2599
print_header(&cache, print_event_info, FALSE);
2512
print_header(&cache, print_event_info, false);
2600
2513
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2601
2514
binlog_version, server_version);
2602
2515
print_timestamp(&cache);
2626
2539
!print_event_info->short_form)
2628
2541
my_b_printf(&cache, "BINLOG '\n");
2629
print_base64(&cache, print_event_info, FALSE);
2630
print_event_info->printed_fd_event= TRUE;
2542
print_base64(&cache, print_event_info, false);
2543
print_event_info->printed_fd_event= true;
2634
2547
#endif /* MYSQL_CLIENT */
2770
2682
switch (binlog_ver) {
2771
2683
case 4: /* MySQL 5.0 */
2772
2684
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2773
DBUG_EXECUTE_IF("pretend_version_50034_in_binlog",
2774
strmov(server_version, "5.0.34"););
2775
2685
common_header_len= LOG_EVENT_HEADER_LEN;
2776
2686
number_of_event_types= LOG_EVENT_TYPES;
2777
2687
/* we'll catch my_malloc() error in is_valid() */
2798
2708
post_header_len[WRITE_ROWS_EVENT-1]= ROWS_HEADER_LEN;
2799
2709
post_header_len[UPDATE_ROWS_EVENT-1]= ROWS_HEADER_LEN;
2800
2710
post_header_len[DELETE_ROWS_EVENT-1]= ROWS_HEADER_LEN;
2802
We here have the possibility to simulate a master of before we changed
2803
the table map id to be stored in 6 bytes: when it was stored in 4
2804
bytes (=> post_header_len was 6). This is used to test backward
2806
This code can be removed after a few months (today is Dec 21st 2005),
2807
when we know that the 4-byte masters are not deployed anymore (check
2808
with Tomas Ulin first!), and the accompanying test (rpl_row_4_bytes)
2811
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master",
2812
post_header_len[TABLE_MAP_EVENT-1]=
2813
post_header_len[WRITE_ROWS_EVENT-1]=
2814
post_header_len[UPDATE_ROWS_EVENT-1]=
2815
post_header_len[DELETE_ROWS_EVENT-1]= 6;);
2816
2711
post_header_len[BEGIN_LOAD_QUERY_EVENT-1]= post_header_len[APPEND_BLOCK_EVENT-1];
2817
2712
post_header_len[EXECUTE_LOAD_QUERY_EVENT-1]= EXECUTE_LOAD_QUERY_HEADER_LEN;
2818
2713
post_header_len[INCIDENT_EVENT-1]= INCIDENT_HEADER_LEN;
2894
2789
description_event)
2895
2790
:Start_log_event_v3(buf, description_event), event_type_permutation(0)
2897
DBUG_ENTER("Format_description_log_event::Format_description_log_event(char*,...)");
2898
2792
buf+= LOG_EVENT_MINIMAL_HEADER_LEN;
2899
2793
if ((common_header_len=buf[ST_COMMON_HEADER_LEN_OFFSET]) < OLD_HEADER_LEN)
2900
DBUG_VOID_RETURN; /* sanity check */
2794
return; /* sanity check */
2901
2795
number_of_event_types=
2902
2796
event_len-(LOG_EVENT_MINIMAL_HEADER_LEN+ST_COMMON_HEADER_LEN_OFFSET+1);
2903
DBUG_PRINT("info", ("common_header_len=%d number_of_event_types=%d",
2904
common_header_len, number_of_event_types));
2905
2797
/* If alloc fails, we'll detect it in is_valid() */
2906
2798
post_header_len= (uint8*) my_memdup((uchar*)buf+ST_COMMON_HEADER_LEN_OFFSET+1,
2907
2799
number_of_event_types*
3139
3027
number= strtoul(p, &r, 10);
3140
3028
server_version_split[i]= (uchar)number;
3141
DBUG_ASSERT(number < 256); // fit in uchar
3029
assert(number < 256); // fit in uchar
3143
DBUG_ASSERT(!((i == 0) && (*r != '.'))); // should be true in practice
3031
assert(!((i == 0) && (*r != '.'))); // should be true in practice
3145
3033
p++; // skip the dot
3147
DBUG_PRINT("info",("Format_description_log_event::server_version_split:"
3148
" '%s' %d %d %d", server_version,
3149
server_version_split[0],
3150
server_version_split[1], server_version_split[2]));
3284
3168
if (!(buf= (char*) my_malloc(get_query_buffer_length(), MYF(MY_WME))))
3286
print_query(TRUE, buf, &end, 0, 0);
3170
print_query(true, buf, &end, 0, 0);
3287
3171
protocol->store(buf, end-buf, &my_charset_bin);
3288
3172
my_free(buf, MYF(0));
3346
3230
num_fields(0),fields(0),
3347
3231
field_lens(0),field_block_len(0),
3348
3232
table_name(table_name_arg ? table_name_arg : ""),
3349
db(db_arg), fname(ex->file_name), local_fname(FALSE)
3233
db(db_arg), fname(ex->file_name), local_fname(false)
3351
3235
time_t end_time;
3352
3236
time(&end_time);
3427
3311
const Format_description_log_event *description_event)
3428
3312
:Log_event(buf, description_event), num_fields(0), fields(0),
3429
3313
field_lens(0),field_block_len(0),
3430
table_name(0), db(0), fname(0), local_fname(FALSE)
3314
table_name(0), db(0), fname(0), local_fname(false)
3432
DBUG_ENTER("Load_log_event");
3434
3317
I (Guilhem) manually tested replication of LOAD DATA INFILE for 3.23->5.0,
3435
3318
4.0->5.0 and 5.0->5.0 and it works.
3475
3357
if (!(field_lens= (uchar*)sql_ex.init((char*)buf + body_offset,
3477
3359
buf[EVENT_TYPE_OFFSET] != LOAD_EVENT)))
3480
3362
data_len = event_len - body_offset;
3481
3363
if (num_fields > data_len) // simple sanity check against corruption
3483
3365
for (uint i = 0; i < num_fields; i++)
3484
3366
field_block_len += (uint)field_lens[i] + 1;
3511
3393
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3513
DBUG_ENTER("Load_log_event::print");
3514
3395
if (!print_event_info->short_form)
3516
print_header(&cache, print_event_info, FALSE);
3397
print_header(&cache, print_event_info, false);
3517
3398
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3518
3399
thread_id, exec_time);
3662
3543
new_db.length= db_len;
3663
3544
new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
3664
3545
thd->set_db(new_db.str, new_db.length);
3665
DBUG_ASSERT(thd->query == 0);
3546
assert(thd->query == 0);
3666
3547
thd->query_length= 0; // Should not be needed
3667
3548
thd->is_slave_error= 0;
3668
3549
clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
3670
3551
/* see Query_log_event::do_apply_event() and BUG#13360 */
3671
DBUG_ASSERT(!rli->m_table_map.count());
3552
assert(!rli->m_table_map.count());
3673
3554
Usually lex_start() is called by mysql_parse(), but we need it here
3674
3555
as the present method does not call mysql_parse().
3761
print_query(FALSE, load_data_query, &end, (char **)&thd->lex->fname_start,
3641
print_query(false, load_data_query, &end, (char **)&thd->lex->fname_start,
3762
3642
(char **)&thd->lex->fname_end);
3764
3644
thd->query_length= end - load_data_query;
3957
3834
if (print_event_info->short_form)
3959
print_header(&cache, print_event_info, FALSE);
3836
print_header(&cache, print_event_info, false);
3960
3837
my_b_printf(&cache, "\tRotate to ");
3961
3838
if (new_log_ident)
3962
3839
my_b_write(&cache, (uchar*) new_log_ident, (uint)ident_len);
3979
3856
pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3980
3857
(uint) strlen(new_log_ident_arg)), flags(flags_arg)
3984
DBUG_ENTER("Rotate_log_event::Rotate_log_event(...,flags)");
3985
DBUG_PRINT("enter",("new_log_ident: %s pos: %s flags: %lu", new_log_ident_arg,
3986
llstr(pos_arg, buff), (ulong) flags));
3988
3860
if (flags & DUP_NAME)
3989
3861
new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3996
3868
const Format_description_log_event* description_event)
3997
3869
:Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3999
DBUG_ENTER("Rotate_log_event::Rotate_log_event(char*,...)");
4000
3871
// The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
4001
3872
uint8 header_size= description_event->common_header_len;
4002
3873
uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
4003
3874
uint ident_offset;
4004
3875
if (event_len < header_size)
4006
3877
buf += header_size;
4007
3878
pos = post_header_len ? uint8korr(buf + R_POS_OFFSET) : 4;
4008
3879
ident_len = (uint)(event_len -
4010
3881
ident_offset = post_header_len;
4011
3882
set_if_smaller(ident_len,FN_REFLEN-1);
4012
3883
new_log_ident= my_strndup(buf + ident_offset, (uint) ident_len, MYF(MY_WME));
4013
DBUG_PRINT("debug", ("new_log_ident: '%s'", new_log_ident));
4049
3919
int Rotate_log_event::do_update_pos(Relay_log_info *rli)
4051
DBUG_ENTER("Rotate_log_event::do_update_pos");
4056
DBUG_PRINT("info", ("server_id=%lu; ::server_id=%lu",
4057
(ulong) this->server_id, (ulong) ::server_id));
4058
DBUG_PRINT("info", ("new_log_ident: %s", this->new_log_ident));
4059
DBUG_PRINT("info", ("pos: %s", llstr(this->pos, buf)));
4061
3923
pthread_mutex_lock(&rli->data_lock);
4062
3924
rli->event_relay_log_pos= my_b_tell(rli->cur_log);
4079
3941
if ((server_id != ::server_id || rli->replicate_same_server_id) &&
4080
3942
!rli->is_in_group())
4082
DBUG_PRINT("info", ("old group_master_log_name: '%s' "
4083
"old group_master_log_pos: %lu",
4084
rli->group_master_log_name,
4085
(ulong) rli->group_master_log_pos));
4086
3944
memcpy(rli->group_master_log_name, new_log_ident, ident_len+1);
4087
3945
rli->notify_group_master_log_name_update();
4088
3946
rli->group_master_log_pos= pos;
4090
3948
sizeof(rli->group_relay_log_name) - 1);
4091
3949
rli->notify_group_relay_log_name_update();
4092
3950
rli->group_relay_log_pos= rli->event_relay_log_pos;
4093
DBUG_PRINT("info", ("new group_master_log_name: '%s' "
4094
"new group_master_log_pos: %lu",
4095
rli->group_master_log_name,
4096
(ulong) rli->group_master_log_pos));
4098
3952
Reset thd->options and sql_mode etc, because this could be the signal of
4099
3953
a master's downgrade from 5.0 to 4.0.
4332
4186
char llbuff[22],llbuff2[22];
4333
4187
if (!print_event_info->short_form)
4335
print_header(&cache, print_event_info, FALSE);
4189
print_header(&cache, print_event_info, false);
4336
4190
my_b_printf(&cache, "\tRand\n");
4338
4192
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4436
4289
longlong10_to_str(xid, buf, 10);
4438
print_header(&cache, print_event_info, FALSE);
4291
print_header(&cache, print_event_info, false);
4439
4292
my_b_printf(&cache, "\tXid = %s\n", buf);
4441
4294
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4455
4308
Log_event::enum_skip_reason
4456
4309
Xid_log_event::do_shall_skip(Relay_log_info *rli)
4458
DBUG_ENTER("Xid_log_event::do_shall_skip");
4459
4311
if (rli->slave_skip_counter > 0) {
4460
4312
thd->options&= ~OPTION_BEGIN;
4461
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
4313
return(Log_event::EVENT_SKIP_COUNT);
4463
DBUG_RETURN(Log_event::do_shall_skip(rli));
4315
return(Log_event::do_shall_skip(rli));
4465
4317
#endif /* !MYSQL_CLIENT */
4860
4712
if (print_event_info->short_form)
4862
print_header(&cache, print_event_info, FALSE);
4714
print_header(&cache, print_event_info, false);
4863
4715
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4890
4742
Relay_log_info* rli)
4891
4743
:Log_event(thd_arg, 0, 0) , mem_pool(0), master_host(0)
4893
DBUG_ENTER("Slave_log_event");
4894
4745
if (!rli->inited) // QQ When can this happen ?
4897
4748
Master_info* mi = rli->mi;
4898
4749
// TODO: re-write this better without holding both locks at the same time
4910
4761
memcpy(master_log, rli->group_master_log_name, master_log_len + 1);
4911
4762
master_port = mi->port;
4912
4763
master_pos = rli->group_master_log_pos;
4913
DBUG_PRINT("info", ("master_log: %s pos: %lu", master_log,
4914
(ulong) master_pos));
4917
4766
sql_print_error("Out of memory while recording slave event");
4918
4767
pthread_mutex_unlock(&rli->data_lock);
4919
4768
pthread_mutex_unlock(&mi->data_lock);
4922
4771
#endif /* !MYSQL_CLIENT */
4936
4785
char llbuff[22];
4937
4786
if (print_event_info->short_form)
4939
print_header(&cache, print_event_info, FALSE);
4788
print_header(&cache, print_event_info, false);
4940
4789
my_b_printf(&cache, "\n\
4941
4790
Slave: master_host: '%s' master_port: %d master_log: '%s' master_pos: %s\n",
4942
4791
master_host, master_port, master_log, llstr(master_pos, llbuff));
5023
4872
if (print_event_info->short_form)
5026
print_header(&cache, print_event_info, FALSE);
4875
print_header(&cache, print_event_info, false);
5027
4876
my_b_printf(&cache, "\tStop\n");
5029
4878
#endif /* MYSQL_CLIENT */
5142
4990
const Format_description_log_event* description_event)
5143
4991
:Load_log_event(buf,0,description_event),fake_base(0),block(0),inited_from_old(0)
5145
DBUG_ENTER("Create_file_log_event::Create_file_log_event(char*,...)");
5146
4993
uint block_offset;
5147
4994
uint header_len= description_event->common_header_len;
5148
4995
uint8 load_header_len= description_event->post_header_len[LOAD_EVENT-1];
5353
5200
const Format_description_log_event* description_event)
5354
5201
:Log_event(buf, description_event),block(0)
5356
DBUG_ENTER("Append_block_log_event::Append_block_log_event(char*,...)");
5357
5203
uint8 common_header_len= description_event->common_header_len;
5358
5204
uint8 append_block_header_len=
5359
5205
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
5360
5206
uint total_header_len= common_header_len+append_block_header_len;
5361
5207
if (len < total_header_len)
5363
5209
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
5364
5210
block= (uchar*)buf + total_header_len;
5365
5211
block_len= len - total_header_len;
5396
5242
if (print_event_info->short_form)
5398
print_header(&cache, print_event_info, FALSE);
5244
print_header(&cache, print_event_info, false);
5399
5245
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5400
5246
get_type_str(), file_id, block_len);
5436
5282
char proc_info[17+FN_REFLEN+10], *fname= proc_info+17;
5439
DBUG_ENTER("Append_block_log_event::do_apply_event");
5441
5286
fname= strmov(proc_info, "Making temp file ");
5442
5287
slave_load_file_stem(fname, file_id, server_id, ".data");
5540
5385
if (print_event_info->short_form)
5542
print_header(&cache, print_event_info, FALSE);
5387
print_header(&cache, print_event_info, false);
5543
5388
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5545
5390
#endif /* MYSQL_CLIENT */
5637
5482
if (print_event_info->short_form)
5639
print_header(&cache, print_event_info, FALSE);
5484
print_header(&cache, print_event_info, false);
5640
5485
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
6097
5940
solution, to be able to terminate a started statement in the
6098
5941
binary log: the extraneous events will be removed in the future.
6100
DBUG_ASSERT(tbl_arg && tbl_arg->s && tid != ~0UL ||
5943
assert(tbl_arg && tbl_arg->s && tid != ~0UL ||
6101
5944
!tbl_arg && !cols && tid == ~0UL);
6103
5946
if (thd_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
6140
5982
, m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
6143
DBUG_ENTER("Rows_log_event::Rows_log_event(const char*,...)");
6144
5985
uint8 const common_header_len= description_event->common_header_len;
6145
5986
uint8 const post_header_len= description_event->post_header_len[event_type-1];
6147
DBUG_PRINT("enter",("event_len: %u common_header_len: %d "
6148
"post_header_len: %d",
6149
event_len, common_header_len,
6152
5988
const char *post_start= buf + common_header_len;
6153
5989
post_start+= RW_MAPID_OFFSET;
6154
5990
if (post_header_len == 6)
6169
6005
(const uchar *)buf + common_header_len + post_header_len;
6170
6006
uchar const *const ptr_width= var_start;
6171
6007
uchar *ptr_after_width= (uchar*) ptr_width;
6172
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6173
6008
m_width = net_field_length(&ptr_after_width);
6174
DBUG_PRINT("debug", ("m_width=%lu", m_width));
6175
6009
/* if bitmap_init fails, catched in is_valid() */
6176
6010
if (likely(!bitmap_init(&m_cols,
6177
6011
m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL,
6181
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6182
6015
memcpy(m_cols.bitmap, ptr_after_width, (m_width + 7) / 8);
6183
6016
create_last_word_mask(&m_cols);
6184
6017
ptr_after_width+= (m_width + 7) / 8;
6185
DBUG_DUMP("m_cols", (uchar*) m_cols.bitmap, no_bytes_in_map(&m_cols));
6189
6021
// Needed because bitmap_init() does not set it to null on failure
6190
6022
m_cols.bitmap= NULL;
6194
6026
m_cols_ai.bitmap= m_cols.bitmap; /* See explanation in is_valid() */
6196
6028
if (event_type == UPDATE_ROWS_EVENT)
6198
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6200
6030
/* if bitmap_init fails, caught in is_valid() */
6201
6031
if (likely(!bitmap_init(&m_cols_ai,
6202
6032
m_width <= sizeof(m_bitbuf_ai)*8 ? m_bitbuf_ai : NULL,
6206
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6207
6036
memcpy(m_cols_ai.bitmap, ptr_after_width, (m_width + 7) / 8);
6208
6037
create_last_word_mask(&m_cols_ai);
6209
6038
ptr_after_width+= (m_width + 7) / 8;
6210
DBUG_DUMP("m_cols_ai", (uchar*) m_cols_ai.bitmap,
6211
no_bytes_in_map(&m_cols_ai));
6215
6042
// Needed because bitmap_init() does not set it to null on failure
6216
6043
m_cols_ai.bitmap= 0;
6221
6048
const uchar* const ptr_rows_data= (const uchar*) ptr_after_width;
6223
6050
size_t const data_size= event_len - (ptr_rows_data - (const uchar *) buf);
6224
DBUG_PRINT("info",("m_table_id: %lu m_flags: %d m_width: %lu data_size: %lu",
6225
m_table_id, m_flags, m_width, (ulong) data_size));
6227
6052
m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME));
6228
6053
if (likely((bool)m_rows_buf))
6255
6080
uchar buf[sizeof(m_width)+1];
6256
6081
uchar *end= net_store_length(buf, (m_width + 7) / 8);
6258
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master",
6259
return 6 + no_bytes_in_map(&m_cols) + (end - buf) +
6260
(type_code == UPDATE_ROWS_EVENT ? no_bytes_in_map(&m_cols_ai) : 0) +
6261
(m_rows_cur - m_rows_buf););
6262
6083
int data_size= ROWS_HEADER_LEN;
6263
6084
data_size+= no_bytes_in_map(&m_cols);
6264
6085
data_size+= end - buf;
6279
6100
log only the primary key value instead of the entire "before image". This
6280
6101
would save binlog space. TODO
6282
DBUG_ENTER("Rows_log_event::do_add_row_data");
6283
DBUG_PRINT("enter", ("row_data: 0x%lx length: %lu", (ulong) row_data,
6287
6105
If length is zero, there is nothing to write, so we just
6291
6109
if (length == 0)
6298
Don't print debug messages when running valgrind since they can
6299
trigger false warnings.
6302
DBUG_DUMP("row_data", row_data, min(length, 32));
6305
DBUG_ASSERT(m_rows_buf <= m_rows_cur);
6306
DBUG_ASSERT(!m_rows_buf || m_rows_end && m_rows_buf <= m_rows_end);
6307
DBUG_ASSERT(m_rows_cur <= m_rows_end);
6115
assert(m_rows_buf <= m_rows_cur);
6116
assert(!m_rows_buf || m_rows_end && m_rows_buf <= m_rows_end);
6117
assert(m_rows_cur <= m_rows_end);
6309
6119
/* The cast will always work since m_rows_cur <= m_rows_end */
6310
6120
if (static_cast<size_t>(m_rows_end - m_rows_cur) <= length)
6317
6127
uchar* const new_buf= (uchar*)my_realloc((uchar*)m_rows_buf, (uint) new_alloc,
6318
6128
MYF(MY_ALLOW_ZERO_PTR|MY_WME));
6319
6129
if (unlikely(!new_buf))
6320
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6130
return(HA_ERR_OUT_OF_MEM);
6322
6132
/* If the memory moved, we need to move the pointers */
6323
6133
if (new_buf != m_rows_buf)
6333
6143
m_rows_end= m_rows_buf + new_alloc;
6336
DBUG_ASSERT(m_rows_cur + length <= m_rows_end);
6146
assert(m_rows_cur + length <= m_rows_end);
6337
6147
memcpy(m_rows_cur, row_data, length);
6338
6148
m_rows_cur+= length;
6344
6154
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6345
6155
int Rows_log_event::do_apply_event(Relay_log_info const *rli)
6347
DBUG_ENTER("Rows_log_event::do_apply_event(Relay_log_info*)");
6350
6159
If m_table_id == ~0UL, then we have a dummy event that does not
6637
6444
case HA_ERR_FOREIGN_DUPLICATE_KEY:
6638
6445
case HA_ERR_NO_REFERENCED_ROW:
6639
6446
case HA_ERR_ROW_IS_REFERENCED:
6641
DBUG_PRINT("info", ("error: %s", HA_ERR(error)));
6642
6447
if (bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
6644
6449
if (global_system_variables.log_warnings)
6660
6465
(i.e., error==0 at this point) we must call unpack_current_row() to set
6661
6466
m_curr_row_end.
6664
DBUG_PRINT("info", ("error: %d", error));
6665
DBUG_PRINT("info", ("curr_row: 0x%lu; curr_row_end: 0x%lu; rows_end: 0x%lu",
6666
(ulong) m_curr_row, (ulong) m_curr_row_end, (ulong) m_rows_end));
6668
6468
if (!m_curr_row_end && !error)
6669
6469
unpack_current_row(rli, &m_cols);
6671
6471
// at this moment m_curr_row_end should be set
6672
DBUG_ASSERT(error || m_curr_row_end != NULL);
6673
DBUG_ASSERT(error || m_curr_row < m_curr_row_end);
6674
DBUG_ASSERT(error || m_curr_row_end <= m_rows_end);
6472
assert(error || m_curr_row_end != NULL);
6473
assert(error || m_curr_row < m_curr_row_end);
6474
assert(error || m_curr_row_end <= m_rows_end);
6676
6476
m_curr_row= m_curr_row_end;
6678
6478
} // row processing loop
6680
DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
6681
const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
6682
6480
error= do_after_row_operations(rli, error);
6683
6481
if (!cache_stmt)
6685
DBUG_PRINT("info", ("Marked that we need to keep log"));
6686
6483
thd->options|= OPTION_KEEP_LOG;
6688
6485
} // if (table)
6856
6649
bool Rows_log_event::write_data_header(IO_CACHE *file)
6858
6651
uchar buf[ROWS_HEADER_LEN]; // No need to init the buffer
6859
DBUG_ASSERT(m_table_id != ~0UL);
6860
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master",
6862
int4store(buf + 0, m_table_id);
6863
int2store(buf + 4, m_flags);
6864
return (my_b_safe_write(file, buf, 6));
6652
assert(m_table_id != ~0UL);
6866
6653
int6store(buf + RW_MAPID_OFFSET, (ulonglong)m_table_id);
6867
6654
int2store(buf + RW_FLAGS_OFFSET, m_flags);
6868
6655
return (my_b_safe_write(file, buf, ROWS_HEADER_LEN));
6878
6665
my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf;
6879
6666
bool res= false;
6880
6667
uchar *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
6881
DBUG_ASSERT(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
6668
assert(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
6883
DBUG_DUMP("m_width", sbuf, (size_t) (sbuf_end - sbuf));
6884
6670
res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
6886
DBUG_PRINT_BITSET("debug", "writing cols: %s", &m_cols);
6887
6672
res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
6888
6673
no_bytes_in_map(&m_cols));
6892
6677
if (get_type_code() == UPDATE_ROWS_EVENT)
6894
DBUG_DUMP("m_cols_ai", (uchar*) m_cols_ai.bitmap,
6895
no_bytes_in_map(&m_cols_ai));
6896
6679
res= res || my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
6897
6680
no_bytes_in_map(&m_cols_ai));
6899
DBUG_DUMP("rows", m_rows_buf, data_size);
6900
6682
res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
7037
6818
m_null_bits(0),
7038
6819
m_meta_memory(NULL)
7040
DBUG_ASSERT(m_table_id != ~0UL);
6821
assert(m_table_id != ~0UL);
7042
6823
In TABLE_SHARE, "db" and "table_name" are 0-terminated (see this comment in
7043
6824
table.cc / alloc_table_share():
7044
6825
Use the fact the key is db/0/table_name/0
7045
6826
As we rely on this let's assert it.
7047
DBUG_ASSERT((tbl->s->db.str == 0) ||
6828
assert((tbl->s->db.str == 0) ||
7048
6829
(tbl->s->db.str[tbl->s->db.length] == 0));
7049
DBUG_ASSERT(tbl->s->table_name.str[tbl->s->table_name.length] == 0);
6830
assert(tbl->s->table_name.str[tbl->s->table_name.length] == 0);
7052
6833
m_data_size= TABLE_MAP_HEADER_LEN;
7053
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master", m_data_size= 6;);
7054
6834
m_data_size+= m_dblen + 2; // Include length and terminating \0
7055
6835
m_data_size+= m_tbllen + 2; // Include length and terminating \0
7056
6836
m_data_size+= 1 + m_colcnt; // COLCNT and column types
7120
6900
m_null_bits(0), m_meta_memory(NULL)
7122
6902
unsigned int bytes_read= 0;
7123
DBUG_ENTER("Table_map_log_event::Table_map_log_event(const char*,uint,...)");
7125
6904
uint8 common_header_len= description_event->common_header_len;
7126
6905
uint8 post_header_len= description_event->post_header_len[TABLE_MAP_EVENT-1];
7127
DBUG_PRINT("info",("event_len: %u common_header_len: %d post_header_len: %d",
7128
event_len, common_header_len, post_header_len));
7131
Don't print debug messages when running valgrind since they can
7132
trigger false warnings.
7135
DBUG_DUMP("event buffer", (uchar*) buf, event_len);
7138
6907
/* Read the post-header */
7139
6908
const char *post_start= buf + common_header_len;
7150
DBUG_ASSERT(post_header_len == TABLE_MAP_HEADER_LEN);
6919
assert(post_header_len == TABLE_MAP_HEADER_LEN);
7151
6920
m_table_id= (ulong) uint6korr(post_start);
7152
6921
post_start+= TM_FLAGS_OFFSET;
7155
DBUG_ASSERT(m_table_id != ~0UL);
6924
assert(m_table_id != ~0UL);
7157
6926
m_flags= uint2korr(post_start);
7172
6941
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
7173
6942
m_colcnt= net_field_length(&ptr_after_colcnt);
7175
DBUG_PRINT("info",("m_dblen: %lu off: %ld m_tbllen: %lu off: %ld m_colcnt: %lu off: %ld",
7176
(ulong) m_dblen, (long) (ptr_dblen-(const uchar*)vpart),
7177
(ulong) m_tbllen, (long) (ptr_tbllen-(const uchar*)vpart),
7178
m_colcnt, (long) (ptr_colcnt-(const uchar*)vpart)));
7180
6944
/* Allocate mem for all fields in one go. If fails, caught in is_valid() */
7181
6945
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
7182
6946
&m_dbnam, (uint) m_dblen + 1,
7194
6958
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
7195
6959
bytes_read= ptr_after_colcnt - (uchar *)buf;
7196
DBUG_PRINT("info", ("Bytes read: %d.\n", bytes_read));
7197
6960
if (bytes_read < event_len)
7199
6962
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
7200
DBUG_ASSERT(m_field_metadata_size <= (m_colcnt * 2));
6963
assert(m_field_metadata_size <= (m_colcnt * 2));
7201
6964
uint num_null_bytes= (m_colcnt + 7) / 8;
7202
6965
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
7203
6966
&m_null_bits, num_null_bytes,
7237
7000
char *db_mem, *tname_mem;
7238
7001
size_t dummy_len;
7240
DBUG_ENTER("Table_map_log_event::do_apply_event(Relay_log_info*)");
7241
DBUG_ASSERT(rli->sql_thd == thd);
7003
assert(rli->sql_thd == thd);
7243
7005
/* Step the query id to mark what columns that are actually used. */
7244
7006
pthread_mutex_lock(&LOCK_thread_count);
7250
7012
&db_mem, (uint) NAME_LEN + 1,
7251
7013
&tname_mem, (uint) NAME_LEN + 1,
7253
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
7015
return(HA_ERR_OUT_OF_MEM);
7255
7017
bzero(table_list, sizeof(*table_list));
7256
7018
table_list->db = db_mem;
7308
7070
of the pointer to make sure that it's not lost.
7311
DBUG_ASSERT(thd->lex->query_tables != table_list);
7073
assert(thd->lex->query_tables != table_list);
7312
7074
TABLE_LIST *tmp_table_list= table_list;
7313
7075
if ((error= open_tables(thd, &tmp_table_list, &count, 0)))
7349
7111
new (&table_list->m_tabledef) table_def(m_coltype, m_colcnt,
7350
7112
m_field_metadata, m_field_metadata_size, m_null_bits);
7351
table_list->m_tabledef_valid= TRUE;
7113
table_list->m_tabledef_valid= true;
7354
7116
We record in the slave's information that the table should be
7388
7150
#ifndef MYSQL_CLIENT
7389
7151
bool Table_map_log_event::write_data_header(IO_CACHE *file)
7391
DBUG_ASSERT(m_table_id != ~0UL);
7153
assert(m_table_id != ~0UL);
7392
7154
uchar buf[TABLE_MAP_HEADER_LEN];
7393
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master",
7395
int4store(buf + 0, m_table_id);
7396
int2store(buf + 4, m_flags);
7397
return (my_b_safe_write(file, buf, 6));
7399
7155
int6store(buf + TM_MAPID_OFFSET, (ulonglong)m_table_id);
7400
7156
int2store(buf + TM_FLAGS_OFFSET, m_flags);
7401
7157
return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
7404
7160
bool Table_map_log_event::write_data_body(IO_CACHE *file)
7406
DBUG_ASSERT(m_dbnam != NULL);
7407
DBUG_ASSERT(m_tblnam != NULL);
7162
assert(m_dbnam != NULL);
7163
assert(m_tblnam != NULL);
7408
7164
/* We use only one byte per length for storage in event: */
7409
DBUG_ASSERT(m_dblen < 128);
7410
DBUG_ASSERT(m_tbllen < 128);
7165
assert(m_dblen < 128);
7166
assert(m_tbllen < 128);
7412
7168
uchar const dbuf[]= { (uchar) m_dblen };
7413
7169
uchar const tbuf[]= { (uchar) m_tbllen };
7415
7171
uchar cbuf[sizeof(m_colcnt)];
7416
7172
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
7417
DBUG_ASSERT(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
7173
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
7420
7176
Store the size of the field metadata.
7463
7219
if (!print_event_info->short_form)
7465
print_header(&print_event_info->head_cache, print_event_info, TRUE);
7221
print_header(&print_event_info->head_cache, print_event_info, true);
7466
7222
my_b_printf(&print_event_info->head_cache,
7467
7223
"\tTable_map: `%s`.`%s` mapped to number %lu\n",
7468
7224
m_dbnam, m_tblnam, m_table_id);
7469
print_base64(&print_event_info->body_cache, print_event_info, TRUE);
7225
print_base64(&print_event_info->body_cache, print_event_info, true);
7685
7440
// Temporary fix to find out why it fails [/Matz]
7686
7441
memcpy(m_table->write_set->bitmap, m_cols.bitmap, (m_table->write_set->n_bits + 7) / 8);
7689
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
7690
DBUG_PRINT_BITSET("debug", "write_set = %s", table->write_set);
7691
DBUG_PRINT_BITSET("debug", "read_set = %s", table->read_set);
7695
7444
Try to write record. If a corresponding record already exists in the table,
7696
7445
we try to change it using ha_update_row() if possible. Otherwise we delete
7730
7478
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
7732
DBUG_PRINT("info",("Locating offending record using rnd_pos()"));
7733
7480
if (table->file->inited && (error= table->file->ha_index_end()))
7735
if ((error= table->file->ha_rnd_init(FALSE)))
7482
if ((error= table->file->ha_rnd_init(false)))
7738
7485
error= table->file->rnd_pos(table->record[1], table->file->dup_ref);
7739
7486
table->file->ha_rnd_end();
7742
DBUG_PRINT("info",("rnd_pos() returns error %d",error));
7743
7489
table->file->print_error(error, MYF(0));
7749
DBUG_PRINT("info",("Locating offending record using index_read_idx()"));
7751
7495
if (table->file->extra(HA_EXTRA_FLUSH_CACHE))
7753
DBUG_PRINT("info",("Error when setting HA_EXTRA_FLUSH_CACHE"));
7754
DBUG_RETURN(my_errno);
7757
7500
if (key.get() == NULL)
7794
7535
error= unpack_current_row(rli, &m_cols);
7798
DBUG_PRINT("debug",("preparing for update: before and after image"));
7799
DBUG_DUMP("record[1] (before)", table->record[1], table->s->reclength);
7800
DBUG_DUMP("record[0] (after)", table->record[0], table->s->reclength);
7804
7539
REPLACE is defined as either INSERT or DELETE + INSERT. If
7805
7540
possible, we can replace it with an UPDATE, but that will not
7818
7553
if (last_uniq_key(table, keynum) &&
7819
7554
!table->file->referenced_by_foreign_key())
7821
DBUG_PRINT("info",("Updating row using ha_update_row()"));
7822
7556
error=table->file->ha_update_row(table->record[1],
7823
7557
table->record[0]);
7824
7558
switch (error) {
7826
7560
case HA_ERR_RECORD_IS_THE_SAME:
7827
DBUG_PRINT("info",("ignoring HA_ERR_RECORD_IS_THE_SAME error from"
7828
" ha_update_row()"));
7835
DBUG_PRINT("info",("ha_update_row() returns error %d",error));
7836
7567
table->file->print_error(error, MYF(0));
7843
DBUG_PRINT("info",("Deleting offending row and trying to write new one again"));
7844
7574
if ((error= table->file->ha_delete_row(table->record[1])))
7846
DBUG_PRINT("info",("ha_delete_row() returns error %d",error));
7847
7576
table->file->print_error(error, MYF(0));
7850
7579
/* Will retry ha_write_row() with the offending row removed. */
7860
7589
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
7862
DBUG_ASSERT(m_table != NULL);
7591
assert(m_table != NULL);
7864
7593
write_row(rli, /* if 1 then overwrite */
7865
7594
bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1);
7867
7596
if (error && !thd->is_error())
7870
7599
my_error(ER_UNKNOWN_ERROR, MYF(0));
7905
7634
TODO[record format ndb]: Remove it once NDB returns correct
7906
7635
records. Check that the other engines also return correct records.
7909
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
7910
DBUG_DUMP("record[1]", table->record[1], table->s->reclength);
7913
7638
uchar saved_x[2], saved_filler[2];
7915
7640
if (table->s->null_bytes > 0)
7998
7723
int Rows_log_event::find_row(const Relay_log_info *rli)
8000
DBUG_ENTER("Rows_log_event::find_row");
8002
DBUG_ASSERT(m_table && m_table->in_use != NULL);
7725
assert(m_table && m_table->in_use != NULL);
8004
7727
TABLE *table= m_table;
8007
7730
/* unpack row - missing fields get default values */
8008
prepare_record(table, &m_cols, m_width, FALSE /* don't check errors */);
7731
prepare_record(table, &m_cols, m_width, false/* don't check errors */);
8009
7732
error= unpack_current_row(rli, &m_cols);
8011
7734
// Temporary fix to find out why it fails [/Matz]
8012
7735
memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8);
8015
DBUG_PRINT("info",("looking for the following record"));
8016
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
8017
DBUG_DUMP("read_set", (uchar*) table->read_set->bitmap, (table->read_set->n_bits + 7) / 8);
8020
7737
if ((table->file->ha_table_flags() & HA_PRIMARY_KEY_REQUIRED_FOR_POSITION) &&
8021
7738
table->s->primary_key < MAX_KEY)
8035
7752
ADD>>> store_record(table,record[1]);
8036
7753
int error= table->file->rnd_pos(table->record[0], table->file->ref);
8037
ADD>>> DBUG_ASSERT(memcmp(table->record[1], table->record[0],
7754
ADD>>> assert(memcmp(table->record[1], table->record[0],
8038
7755
table->s->reclength) == 0);
8041
DBUG_PRINT("info",("locating record using primary key (position)"));
8042
7758
int error= table->file->rnd_pos_by_record(table->record[0]);
8043
7759
table->file->ha_rnd_end();
8046
DBUG_PRINT("info",("rnd_pos returns error %d",error));
8047
7762
table->file->print_error(error, MYF(0));
8052
7767
// We can't use position() - try other methods.
8060
7775
if (table->s->keys > 0)
8062
DBUG_PRINT("info",("locating record using primary key (index_read)"));
8064
7777
/* We have a key: search the table using the index */
8065
if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE)))
7778
if (!table->file->inited && (error= table->file->ha_index_init(0, false)))
8067
DBUG_PRINT("info",("ha_index_init returns error %d",error));
8068
7780
table->file->print_error(error, MYF(0));
8072
7784
/* Fill key data for the row */
8075
7787
key_copy(m_key, table->record[0], table->key_info, 0);
8078
Don't print debug messages when running valgrind since they can
8079
trigger false warnings.
8082
DBUG_DUMP("key data", m_key, table->key_info->key_length);
8086
7790
We need to set the null bytes to ensure that the filler bit are
8087
7791
all set when returning. There are storage engines that just set
8088
7792
the necessary bits on the bytes and don't set the filler bits
8097
7801
HA_READ_KEY_EXACT)))
8099
DBUG_PRINT("info",("no record matching the key found in the table"));
8100
7803
table->file->print_error(error, MYF(0));
8101
7804
table->file->ha_index_end();
8106
Don't print debug messages when running valgrind since they can
8107
trigger false warnings.
8110
DBUG_PRINT("info",("found first matching record"));
8111
DBUG_DUMP("record[0]", table->record[0], table->s->reclength);
8114
7809
Below is a minor "optimization". If the key (i.e., key number
8115
7810
0) has the HA_NOSAME flag set, we know that we have found the
8173
DBUG_PRINT("info",("locating record using table scan (rnd_next)"));
8175
7865
int restart_count= 0; // Number of times scanning has restarted from top
8177
7867
/* We don't have a key: search the table using rnd_next() */
8178
7868
if ((error= table->file->ha_rnd_init(1)))
8180
DBUG_PRINT("info",("error initializing table scan"
8181
" (ha_rnd_init returns %d)",error));
8182
7870
table->file->print_error(error, MYF(0));
8213
7899
Note: above record_compare will take into accout all record fields
8214
7900
which might be incorrect in case a partial row was given in the event
8218
Have to restart the scan to be able to fetch the next row.
8220
if (restart_count == 2)
8222
DBUG_PRINT("info", ("Record not found"));
8226
DBUG_DUMP("record found", table->record[0], table->s->reclength);
8228
7902
table->file->ha_rnd_end();
8230
DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
7904
assert(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
8234
7908
table->default_column_bitmaps();
8237
7911
table->default_column_bitmaps();
8451
8125
Now we have the right row to update. The old row (the one we're
8452
8126
looking for) is in record[1] and the new row is in record[0].
8456
Don't print debug messages when running valgrind since they can
8457
trigger false warnings.
8459
DBUG_PRINT("info",("Updating row in table"));
8460
DBUG_DUMP("old record", m_table->record[1], m_table->s->reclength);
8461
DBUG_DUMP("new values", m_table->record[0], m_table->s->reclength);
8464
8129
// Temporary fix to find out why it fails [/Matz]
8465
8130
memcpy(m_table->read_set->bitmap, m_cols.bitmap, (m_table->read_set->n_bits + 7) / 8);
8487
8152
const Format_description_log_event *descr_event)
8488
8153
: Log_event(buf, descr_event)
8490
DBUG_ENTER("Incident_log_event::Incident_log_event");
8491
8155
uint8 const common_header_len=
8492
8156
descr_event->common_header_len;
8493
8157
uint8 const post_header_len=
8494
8158
descr_event->post_header_len[INCIDENT_EVENT-1];
8496
DBUG_PRINT("info",("event_len: %u; common_header_len: %d; post_header_len: %d",
8497
event_len, common_header_len, post_header_len));
8499
8160
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
8500
8161
char const *ptr= buf + common_header_len + post_header_len;
8501
8162
char const *const str_end= buf + event_len;
8558
8216
Write_on_release_cache cache(&print_event_info->head_cache, file);
8559
print_header(&cache, print_event_info, FALSE);
8217
print_header(&cache, print_event_info, false);
8560
8218
my_b_printf(&cache, "\n# Incident: %s", description());
8566
8224
Incident_log_event::do_apply_event(Relay_log_info const *rli)
8568
DBUG_ENTER("Incident_log_event::do_apply_event");
8569
8226
rli->report(ERROR_LEVEL, ER_SLAVE_INCIDENT,
8570
8227
ER(ER_SLAVE_INCIDENT),
8572
8229
m_message.length > 0 ? m_message.str : "<none>");
8578
8235
Incident_log_event::write_data_header(IO_CACHE *file)
8580
DBUG_ENTER("Incident_log_event::write_data_header");
8581
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
8582
8237
uchar buf[sizeof(int16)];
8583
8238
int2store(buf, (int16) m_incident);
8584
DBUG_RETURN(my_b_safe_write(file, buf, sizeof(buf)));
8239
return(my_b_safe_write(file, buf, sizeof(buf)));
8588
8243
Incident_log_event::write_data_body(IO_CACHE *file)
8590
DBUG_ENTER("Incident_log_event::write_data_body");
8591
DBUG_RETURN(write_str(file, m_message.str, m_message.length));
8245
return(write_str(file, m_message.str, m_message.length));
8594
8248
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8616
8270
lc_time_names_number(~0),
8617
8271
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8618
8272
thread_id(0), thread_id_printed(false),
8619
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(FALSE)
8273
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8622
8276
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at