126
118
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
127
119
Relay_log_info const *rli, THD *thd,
128
TABLE *table, const char * type,
120
Table *table, const char * type,
129
121
const char *log_name, ulong pos)
131
123
const char *handler_error= HA_ERR(ha_error);
132
124
char buff[MAX_SLAVE_ERRMSG], *slider;
133
125
const char *buff_end= buff + sizeof(buff);
135
List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
127
List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
139
131
for (err= it++, slider= buff; err && slider < buff_end - 1;
140
132
slider += len, err= it++)
142
len= my_snprintf(slider, buff_end - slider,
143
" %s, Error_code: %d;", err->msg, err->code);
134
len= snprintf(slider, buff_end - slider,
135
_(" %s, Error_code: %d;"), err->msg, err->code);
146
138
rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0,
147
"Could not execute %s event on table %s.%s;"
148
"%s handler error %s; "
149
"the event's master log %s, end_log_pos %lu",
139
_("Could not execute %s event on table %s.%s;"
140
"%s handler error %s; "
141
"the event's master log %s, end_log_pos %lu"),
150
142
type, table->s->db.str,
151
143
table->s->table_name.str,
153
handler_error == NULL? "<unknown>" : handler_error,
145
handler_error == NULL? _("<unknown>") : handler_error,
159
151
Cache that will automatically be written to a dedicated file on
1200
1033
if (!ev || !ev->is_valid())
1202
DBUG_PRINT("error",("Found invalid event in binary log"));
1206
if (!force_opt) /* then mysqlbinlog dies */
1208
*error= "Found invalid event in binary log";
1211
ev= new Unknown_log_event(buf, description_event);
1213
1036
*error= "Found invalid event in binary log";
1223
Log_event::print_header()
1226
void Log_event::print_header(IO_CACHE* file,
1227
PRINT_EVENT_INFO* print_event_info,
1228
bool is_more __attribute__((unused)))
1231
my_off_t hexdump_from= print_event_info->hexdump_from;
1232
DBUG_ENTER("Log_event::print_header");
1234
my_b_printf(file, "#");
1235
print_timestamp(file);
1236
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1237
llstr(log_pos,llbuff));
1239
/* mysqlbinlog --hexdump */
1240
if (print_event_info->hexdump_from)
1242
my_b_printf(file, "\n");
1243
uchar *ptr= (uchar*)temp_buf;
1245
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1248
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1249
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1250
char *c, char_string[16+1]= {0};
1252
/* Pretty-print event common header if header is exactly 19 bytes */
1253
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1255
char emit_buf[256]; // Enough for storing one line
1256
my_b_printf(file, "# Position Timestamp Type Master ID "
1257
"Size Master Pos Flags \n");
1258
int const bytes_written=
1259
my_snprintf(emit_buf, sizeof(emit_buf),
1260
"# %8.8lx %02x %02x %02x %02x %02x "
1261
"%02x %02x %02x %02x %02x %02x %02x %02x "
1262
"%02x %02x %02x %02x %02x %02x\n",
1263
(unsigned long) hexdump_from,
1264
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1265
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1266
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));
1269
my_b_write(file, (uchar*) emit_buf, bytes_written);
1270
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1271
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1274
/* Rest of event (without common header) */
1275
for (i= 0, c= char_string, h=hex_string;
1279
my_snprintf(h, 4, "%02x ", *ptr);
1282
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1287
my_b_printf() does not support full printf() formats, so we
1288
have to do it this way.
1290
TODO: Rewrite my_b_printf() to support full printf() syntax.
1293
int const bytes_written=
1294
my_snprintf(emit_buf, sizeof(emit_buf),
1295
"# %8.8lx %-48.48s |%16s|\n",
1296
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1297
hex_string, char_string);
1298
DBUG_ASSERT(bytes_written >= 0);
1299
DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1300
my_b_write(file, (uchar*) emit_buf, bytes_written);
1306
else if (i % 8 == 7) *h++ = ' ';
1313
int const bytes_written=
1314
my_snprintf(emit_buf, sizeof(emit_buf),
1315
"# %8.8lx %-48.48s |%s|\n",
1316
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1317
hex_string, char_string);
1318
DBUG_ASSERT(bytes_written >= 0);
1319
DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1320
my_b_write(file, (uchar*) emit_buf, bytes_written);
1323
need a # to prefix the rest of printouts for example those of
1324
Rows_log_event::print_helper().
1326
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1332
void Log_event::print_base64(IO_CACHE* file,
1333
PRINT_EVENT_INFO* print_event_info,
1336
const uchar *ptr= (const uchar *)temp_buf;
1337
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
1338
DBUG_ENTER("Log_event::print_base64");
1340
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1341
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1343
fprintf(stderr, "\nError: Out of memory. "
1344
"Could not print correct binlog event.\n");
1348
if (base64_encode(ptr, (size_t) size, tmp_str))
1353
if (my_b_tell(file) == 0)
1354
my_b_printf(file, "\nBINLOG '\n");
1356
my_b_printf(file, "%s\n", tmp_str);
1359
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1361
my_free(tmp_str, MYF(0));
1367
Log_event::print_timestamp()
1370
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1373
DBUG_ENTER("Log_event::print_timestamp");
1376
#ifdef MYSQL_SERVER // This is always false
1378
localtime_r(ts,(res= &tm_tmp));
1383
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1393
#endif /* MYSQL_CLIENT */
1396
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1397
1042
inline Log_event::enum_skip_reason
1398
1043
Log_event::continue_group(Relay_log_info *rli)
1843
1457
This is used by the SQL slave thread to prepare the event before execution.
1845
Query_log_event::Query_log_event(const char* buf, uint event_len,
1459
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
1846
1460
const Format_description_log_event
1847
1461
*description_event,
1848
1462
Log_event_type event_type)
1849
:Log_event(buf, description_event), data_buf(0), query(NullS),
1850
db(NullS), catalog_len(0), status_vars_len(0),
1463
:Log_event(buf, description_event), data_buf(0), query(NULL),
1464
db(NULL), catalog_len(0), status_vars_len(0),
1851
1465
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1852
1466
auto_increment_increment(1), auto_increment_offset(1),
1853
1467
time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1857
uint8 common_header_len, post_header_len;
1471
uint8_t common_header_len, post_header_len;
1858
1472
Log_event::Byte *start;
1859
1473
const Log_event::Byte *end;
1860
1474
bool catalog_nz= 1;
1861
DBUG_ENTER("Query_log_event::Query_log_event(char*,...)");
1863
1476
common_header_len= description_event->common_header_len;
1864
1477
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
1480
We test if the event's length is sensible, and if so we compute data_len.
2034
1621
/* A 2nd variable part; this is common to all versions */
2035
memcpy((char*) start, end, data_len); // Copy db and query
1622
memcpy(start, end, data_len); // Copy db and query
2036
1623
start[data_len]= '\0'; // End query with \0 (For safetly)
2037
1624
db= (char *)start;
2038
1625
query= (char *)(start + db_len + 1);
2039
1626
q_len= data_len - db_len -1;
2046
Query_log_event::print().
2049
print the catalog ??
2051
void Query_log_event::print_query_header(IO_CACHE* file,
2052
PRINT_EVENT_INFO* print_event_info)
2054
// TODO: print the catalog ??
2055
char buff[40],*end; // Enough for SET TIMESTAMP
2056
bool different_db= 1;
2059
if (!print_event_info->short_form)
2061
print_header(file, print_event_info, FALSE);
2062
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
2063
get_type_str(), (ulong) thread_id, (ulong) exec_time,
2067
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
2069
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
2070
memcpy(print_event_info->db, db, db_len + 1);
2071
if (db[0] && different_db)
2072
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
2075
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
2076
end= strmov(end, print_event_info->delimiter);
2078
my_b_write(file, (uchar*) buff, (uint) (end-buff));
2079
if ((!print_event_info->thread_id_printed ||
2080
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
2081
thread_id != print_event_info->thread_id)))
2083
// If --short-form, print deterministic value instead of pseudo_thread_id.
2084
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
2085
short_form ? 999999999 : (ulong)thread_id,
2086
print_event_info->delimiter);
2087
print_event_info->thread_id= thread_id;
2088
print_event_info->thread_id_printed= 1;
2092
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
2093
print (remember we don't produce mixed relay logs so there cannot be
2094
5.0 events before that one so there is nothing to reset).
2096
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
2098
/* tmp is a bitmask of bits which have changed. */
2099
if (likely(print_event_info->flags2_inited))
2100
/* All bits which have changed */
2101
tmp= (print_event_info->flags2) ^ flags2;
2102
else /* that's the first Query event we read */
2104
print_event_info->flags2_inited= 1;
2105
tmp= ~((uint32)0); /* all bits have changed */
2108
if (unlikely(tmp)) /* some bits have changed */
2111
my_b_printf(file, "SET ");
2112
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2113
"@@session.foreign_key_checks", &need_comma);
2114
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2115
"@@session.sql_auto_is_null", &need_comma);
2116
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2117
"@@session.unique_checks", &need_comma);
2118
my_b_printf(file,"%s\n", print_event_info->delimiter);
2119
print_event_info->flags2= flags2;
2124
Now the session variables;
2125
it's more efficient to pass SQL_MODE as a number instead of a
2126
comma-separated list.
2127
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2128
variables (they have no global version; they're not listed in
2129
sql_class.h), The tests below work for pure binlogs or pure relay
2130
logs. Won't work for mixed relay logs but we don't create mixed
2131
relay logs (that is, there is no relay log with a format change
2132
except within the 3 first events, which mysqlbinlog handles
2133
gracefully). So this code should always be good.
2136
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2137
print_event_info->auto_increment_offset != auto_increment_offset)
2139
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2140
auto_increment_increment,auto_increment_offset,
2141
print_event_info->delimiter);
2142
print_event_info->auto_increment_increment= auto_increment_increment;
2143
print_event_info->auto_increment_offset= auto_increment_offset;
2146
/* TODO: print the catalog when we feature SET CATALOG */
2148
if (likely(charset_inited) &&
2149
(unlikely(!print_event_info->charset_inited ||
2150
bcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
2152
CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2155
/* for mysql client */
2156
my_b_printf(file, "/*!\\C %s */%s\n",
2157
cs_info->csname, print_event_info->delimiter);
2159
my_b_printf(file,"SET "
2160
"@@session.character_set_client=%d,"
2161
"@@session.collation_connection=%d,"
2162
"@@session.collation_server=%d"
2165
uint2korr(charset+2),
2166
uint2korr(charset+4),
2167
print_event_info->delimiter);
2168
memcpy(print_event_info->charset, charset, 6);
2169
print_event_info->charset_inited= 1;
2173
if (bcmp((uchar*) print_event_info->time_zone_str,
2174
(uchar*) time_zone_str, time_zone_len+1))
2176
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2177
time_zone_str, print_event_info->delimiter);
2178
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2181
if (lc_time_names_number != print_event_info->lc_time_names_number)
2183
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2184
lc_time_names_number, print_event_info->delimiter);
2185
print_event_info->lc_time_names_number= lc_time_names_number;
2187
if (charset_database_number != print_event_info->charset_database_number)
2189
if (charset_database_number)
2190
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2191
charset_database_number, print_event_info->delimiter);
2193
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2194
print_event_info->delimiter);
2195
print_event_info->charset_database_number= charset_database_number;
2200
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2202
Write_on_release_cache cache(&print_event_info->head_cache, file);
2204
print_query_header(&cache, print_event_info);
2205
my_b_write(&cache, (uchar*) query, q_len);
2206
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2208
#endif /* MYSQL_CLIENT */
2212
1632
Query_log_event::do_apply_event()
2215
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2217
1634
int Query_log_event::do_apply_event(Relay_log_info const *rli)
2219
1636
return do_apply_event(rli, query, q_len);
2528
1907
Log_event::enum_skip_reason
2529
1908
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);
1910
assert(query && q_len > 0);
2535
1912
if (rli->slave_skip_counter > 0)
2537
1914
if (strcmp("BEGIN", query) == 0)
2539
1916
thd->options|= OPTION_BEGIN;
2540
DBUG_RETURN(Log_event::continue_group(rli));
1917
return(Log_event::continue_group(rli));
2543
1920
if (strcmp("COMMIT", query) == 0 || strcmp("ROLLBACK", query) == 0)
2545
1922
thd->options&= ~OPTION_BEGIN;
2546
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
1923
return(Log_event::EVENT_SKIP_COUNT);
2549
DBUG_RETURN(Log_event::do_shall_skip(rli));
1926
return(Log_event::do_shall_skip(rli));
2555
1930
/**************************************************************************
2556
1931
Start_log_event_v3 methods
2557
1932
**************************************************************************/
2559
#ifndef MYSQL_CLIENT
2560
1934
Start_log_event_v3::Start_log_event_v3()
2561
1935
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
2562
1936
artificial_event(0), dont_set_created(0)
2564
1938
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2569
1942
Start_log_event_v3::pack_info()
2572
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2573
1945
void Start_log_event_v3::pack_info(Protocol *protocol)
2575
1947
char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
2576
pos= strmov(buf, "Server ver: ");
2577
pos= strmov(pos, server_version);
2578
pos= strmov(pos, ", Binlog ver: ");
1948
pos= my_stpcpy(buf, "Server ver: ");
1949
pos= my_stpcpy(pos, server_version);
1950
pos= my_stpcpy(pos, ", Binlog ver: ");
2579
1951
pos= int10_to_str(binlog_version, pos, 10);
2580
1952
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2586
Start_log_event_v3::print()
2590
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2592
DBUG_ENTER("Start_log_event_v3::print");
2594
Write_on_release_cache cache(&print_event_info->head_cache, file,
2595
Write_on_release_cache::FLUSH_F);
2597
if (!print_event_info->short_form)
2599
print_header(&cache, print_event_info, FALSE);
2600
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2601
binlog_version, server_version);
2602
print_timestamp(&cache);
2604
my_b_printf(&cache," at startup");
2605
my_b_printf(&cache, "\n");
2606
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2607
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2608
"Most probably mysqld crashed writing it.\n");
2610
if (!artificial_event && created)
2612
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2614
This is for mysqlbinlog: like in replication, we want to delete the stale
2615
tmp files left by an unclean shutdown of mysqld (temporary tables)
2616
and rollback unfinished transaction.
2617
Probably this can be done with RESET CONNECTION (syntax to be defined).
2619
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2621
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2625
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2626
!print_event_info->short_form)
2628
my_b_printf(&cache, "BINLOG '\n");
2629
print_base64(&cache, print_event_info, FALSE);
2630
print_event_info->printed_fd_event= TRUE;
2634
#endif /* MYSQL_CLIENT */
2637
1957
Start_log_event_v3::Start_log_event_v3()
3005
2297
Since we use (permuted) event id's to index the post_header_len
3006
2298
array, we need to permute the post_header_len array too.
3008
uint8 post_header_len_temp[23];
2300
uint8_t post_header_len_temp[23];
3009
2301
for (int i= 1; i < 23; i++)
3010
2302
post_header_len_temp[perm[i] - 1]= post_header_len[i - 1];
3011
2303
for (int i= 0; i < 22; i++)
3012
2304
post_header_len[i] = post_header_len_temp[i];
3017
#ifndef MYSQL_CLIENT
3018
2309
bool Format_description_log_event::write(IO_CACHE* file)
3021
2312
We don't call Start_log_event_v3::write() because this would make 2
3022
2313
my_b_safe_write().
3024
uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
2315
unsigned char buff[FORMAT_DESCRIPTION_HEADER_LEN];
3025
2316
int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
3026
memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
2317
memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
3027
2318
if (!dont_set_created)
3028
2319
created= when= get_time();
3029
2320
int4store(buff + ST_CREATED_OFFSET,created);
3030
2321
buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN;
3031
memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (uchar*) post_header_len,
2322
memcpy(buff+ST_COMMON_HEADER_LEN_OFFSET+1, post_header_len,
3032
2323
LOG_EVENT_TYPES);
3033
2324
return (write_header(file, sizeof(buff)) ||
3034
2325
my_b_safe_write(file, buff, sizeof(buff)));
3038
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3039
2329
int Format_description_log_event::do_apply_event(Relay_log_info const *rli)
3041
DBUG_ENTER("Format_description_log_event::do_apply_event");
3044
2332
As a transaction NEVER spans on 2 or more binlogs:
3045
2333
if we have an active transaction at this point, the master died
3199
2480
if (need_db && db && db_len)
3201
pos= strmov(pos, "use `");
2482
pos= my_stpcpy(pos, "use `");
3202
2483
memcpy(pos, db, db_len);
3203
pos= strmov(pos+db_len, "`; ");
2484
pos= my_stpcpy(pos+db_len, "`; ");
3206
pos= strmov(pos, "LOAD DATA ");
2487
pos= my_stpcpy(pos, "LOAD DATA ");
3209
2490
*fn_start= pos;
3211
2492
if (check_fname_outside_temp_buf())
3212
pos= strmov(pos, "LOCAL ");
3213
pos= strmov(pos, "INFILE '");
2493
pos= my_stpcpy(pos, "LOCAL ");
2494
pos= my_stpcpy(pos, "INFILE '");
3214
2495
memcpy(pos, fname, fname_len);
3215
pos= strmov(pos+fname_len, "' ");
2496
pos= my_stpcpy(pos+fname_len, "' ");
3217
2498
if (sql_ex.opt_flags & REPLACE_FLAG)
3218
pos= strmov(pos, " REPLACE ");
2499
pos= my_stpcpy(pos, " REPLACE ");
3219
2500
else if (sql_ex.opt_flags & IGNORE_FLAG)
3220
pos= strmov(pos, " IGNORE ");
2501
pos= my_stpcpy(pos, " IGNORE ");
3222
pos= strmov(pos ,"INTO");
2503
pos= my_stpcpy(pos ,"INTO");
3227
pos= strmov(pos ," TABLE `");
2508
pos= my_stpcpy(pos ," Table `");
3228
2509
memcpy(pos, table_name, table_name_len);
3229
2510
pos+= table_name_len;
3231
2512
/* We have to create all optinal fields as the default is not empty */
3232
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2513
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3233
2514
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
3234
2515
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3235
pos= strmov(pos, " OPTIONALLY ");
3236
pos= strmov(pos, " ENCLOSED BY ");
2516
pos= my_stpcpy(pos, " OPTIONALLY ");
2517
pos= my_stpcpy(pos, " ENCLOSED BY ");
3237
2518
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
3239
pos= strmov(pos, " ESCAPED BY ");
2520
pos= my_stpcpy(pos, " ESCAPED BY ");
3240
2521
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
3242
pos= strmov(pos, " LINES TERMINATED BY ");
2523
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3243
2524
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
3244
2525
if (sql_ex.line_start_len)
3246
pos= strmov(pos, " STARTING BY ");
2527
pos= my_stpcpy(pos, " STARTING BY ");
3247
2528
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
3250
2531
if ((long) skip_lines > 0)
3252
pos= strmov(pos, " IGNORE ");
3253
pos= longlong10_to_str((longlong) skip_lines, pos, 10);
3254
pos= strmov(pos," LINES ");
2533
pos= my_stpcpy(pos, " IGNORE ");
2534
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2535
pos= my_stpcpy(pos," LINES ");
3257
2538
if (num_fields)
3260
2541
const char *field= fields;
3261
pos= strmov(pos, " (");
2542
pos= my_stpcpy(pos, " (");
3262
2543
for (i = 0; i < num_fields; i++)
3346
2624
num_fields(0),fields(0),
3347
2625
field_lens(0),field_block_len(0),
3348
2626
table_name(table_name_arg ? table_name_arg : ""),
3349
db(db_arg), fname(ex->file_name), local_fname(FALSE)
2627
db(db_arg), fname(ex->file_name), local_fname(false)
3351
2629
time_t end_time;
3352
2630
time(&end_time);
3353
2631
exec_time = (ulong) (end_time - thd_arg->start_time);
3354
2632
/* db can never be a zero pointer in 4.0 */
3355
db_len = (uint32) strlen(db);
3356
table_name_len = (uint32) strlen(table_name);
2633
db_len = (uint32_t) strlen(db);
2634
table_name_len = (uint32_t) strlen(table_name);
3357
2635
fname_len = (fname) ? (uint) strlen(fname) : 0;
3358
2636
sql_ex.field_term = (char*) ex->field_term->ptr();
3359
sql_ex.field_term_len = (uint8) ex->field_term->length();
2637
sql_ex.field_term_len = (uint8_t) ex->field_term->length();
3360
2638
sql_ex.enclosed = (char*) ex->enclosed->ptr();
3361
sql_ex.enclosed_len = (uint8) ex->enclosed->length();
2639
sql_ex.enclosed_len = (uint8_t) ex->enclosed->length();
3362
2640
sql_ex.line_term = (char*) ex->line_term->ptr();
3363
sql_ex.line_term_len = (uint8) ex->line_term->length();
2641
sql_ex.line_term_len = (uint8_t) ex->line_term->length();
3364
2642
sql_ex.line_start = (char*) ex->line_start->ptr();
3365
sql_ex.line_start_len = (uint8) ex->line_start->length();
2643
sql_ex.line_start_len = (uint8_t) ex->line_start->length();
3366
2644
sql_ex.escaped = (char*) ex->escaped->ptr();
3367
sql_ex.escaped_len = (uint8) ex->escaped->length();
2645
sql_ex.escaped_len = (uint8_t) ex->escaped->length();
3368
2646
sql_ex.opt_flags = 0;
3369
2647
sql_ex.cached_new_format = -1;
3490
2765
fname_len = strlen(fname);
3491
2766
// null termination is accomplished by the caller doing buf[event_len]=0
3498
Load_log_event::print()
3502
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3504
print(file, print_event_info, 0);
3508
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3511
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3513
DBUG_ENTER("Load_log_event::print");
3514
if (!print_event_info->short_form)
3516
print_header(&cache, print_event_info, FALSE);
3517
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3518
thread_id, exec_time);
3521
bool different_db= 1;
3525
If the database is different from the one of the previous statement, we
3526
need to print the "use" command, and we update the last_db.
3527
But if commented, the "use" is going to be commented so we should not
3530
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3532
memcpy(print_event_info->db, db, db_len + 1);
3535
if (db && db[0] && different_db)
3536
my_b_printf(&cache, "%suse %s%s\n",
3537
commented ? "# " : "",
3538
db, print_event_info->delimiter);
3540
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3541
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3542
commented ? "# " : "", (ulong)thread_id,
3543
print_event_info->delimiter);
3544
my_b_printf(&cache, "%sLOAD DATA ",
3545
commented ? "# " : "");
3546
if (check_fname_outside_temp_buf())
3547
my_b_printf(&cache, "LOCAL ");
3548
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3550
if (sql_ex.opt_flags & REPLACE_FLAG)
3551
my_b_printf(&cache," REPLACE ");
3552
else if (sql_ex.opt_flags & IGNORE_FLAG)
3553
my_b_printf(&cache," IGNORE ");
3555
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3556
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3557
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3559
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3560
my_b_printf(&cache," OPTIONALLY ");
3561
my_b_printf(&cache, " ENCLOSED BY ");
3562
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3564
my_b_printf(&cache, " ESCAPED BY ");
3565
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3567
my_b_printf(&cache," LINES TERMINATED BY ");
3568
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3571
if (sql_ex.line_start)
3573
my_b_printf(&cache," STARTING BY ");
3574
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3576
if ((long) skip_lines > 0)
3577
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3582
const char* field = fields;
3583
my_b_printf(&cache, " (");
3584
for (i = 0; i < num_fields; i++)
3587
my_b_printf(&cache, ",");
3588
my_b_printf(&cache, field);
3590
field += field_lens[i] + 1;
3592
my_b_printf(&cache, ")");
3595
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3598
#endif /* MYSQL_CLIENT */
3600
#ifndef MYSQL_CLIENT
3603
2773
Load_log_event::set_fields()
3974
#ifndef MYSQL_CLIENT
3975
3113
Rotate_log_event::Rotate_log_event(const char* new_log_ident_arg,
3976
uint ident_len_arg, ulonglong pos_arg,
3114
uint32_t ident_len_arg, uint64_t pos_arg,
3978
3116
:Log_event(), new_log_ident(new_log_ident_arg),
3979
3117
pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3980
3118
(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
3120
if (flags & DUP_NAME)
3989
3121
new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3995
Rotate_log_event::Rotate_log_event(const char* buf, uint event_len,
3126
Rotate_log_event::Rotate_log_event(const char* buf, uint32_t event_len,
3996
3127
const Format_description_log_event* description_event)
3997
3128
:Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3999
DBUG_ENTER("Rotate_log_event::Rotate_log_event(char*,...)");
4000
3130
// The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
4001
uint8 header_size= description_event->common_header_len;
4002
uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3131
uint8_t header_size= description_event->common_header_len;
3132
uint8_t post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3133
uint32_t ident_offset;
4004
3134
if (event_len < header_size)
4006
3136
buf += header_size;
4007
3137
pos = post_header_len ? uint8korr(buf + R_POS_OFFSET) : 4;
4008
3138
ident_len = (uint)(event_len -
4186
3287
Intvar_log_event::write()
4189
#ifndef MYSQL_CLIENT
4190
3290
bool Intvar_log_event::write(IO_CACHE* file)
4193
buf[I_TYPE_OFFSET]= (uchar) type;
3292
unsigned char buf[9];
3293
buf[I_TYPE_OFFSET]= (unsigned char) type;
4194
3294
int8store(buf + I_VAL_OFFSET, val);
4195
3295
return (write_header(file, sizeof(buf)) ||
4196
3296
my_b_safe_write(file, buf, sizeof(buf)));
4202
3301
Intvar_log_event::print()
4206
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4210
Write_on_release_cache cache(&print_event_info->head_cache, file,
4211
Write_on_release_cache::FLUSH_F);
4213
if (!print_event_info->short_form)
4215
print_header(&cache, print_event_info, FALSE);
4216
my_b_printf(&cache, "\tIntvar\n");
4219
my_b_printf(&cache, "SET ");
4221
case LAST_INSERT_ID_EVENT:
4222
msg="LAST_INSERT_ID";
4224
case INSERT_ID_EVENT:
4227
case INVALID_INT_EVENT:
4228
default: // cannot happen
4232
my_b_printf(&cache, "%s=%s%s\n",
4233
msg, llstr(val,llbuff), print_event_info->delimiter);
4239
3305
Intvar_log_event::do_apply_event()
4242
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
4243
3308
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4410
3445
:Log_event(buf, description_event)
4412
3447
buf+= description_event->common_header_len;
4413
memcpy((char*) &xid, buf, sizeof(xid));
3448
memcpy(&xid, buf, sizeof(xid));
4417
#ifndef MYSQL_CLIENT
4418
3452
bool Xid_log_event::write(IO_CACHE* file)
4420
DBUG_EXECUTE_IF("do_not_write_xid", return 0;);
4421
3454
return write_header(file, sizeof(xid)) ||
4422
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4428
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4430
Write_on_release_cache cache(&print_event_info->head_cache, file,
4431
Write_on_release_cache::FLUSH_F);
4433
if (!print_event_info->short_form)
4436
longlong10_to_str(xid, buf, 10);
4438
print_header(&cache, print_event_info, FALSE);
4439
my_b_printf(&cache, "\tXid = %s\n", buf);
4441
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4443
#endif /* MYSQL_CLIENT */
4446
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4447
int Xid_log_event::do_apply_event(Relay_log_info const *rli)
4449
/* For a slave Xid_log_event is COMMIT */
4450
general_log_print(thd, COM_QUERY,
4451
"COMMIT /* implicit, from Xid_log_event */");
3455
my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
3459
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4452
3461
return end_trans(thd, COMMIT);
4455
3464
Log_event::enum_skip_reason
4456
3465
Xid_log_event::do_shall_skip(Relay_log_info *rli)
4458
DBUG_ENTER("Xid_log_event::do_shall_skip");
4459
3467
if (rli->slave_skip_counter > 0) {
4460
3468
thd->options&= ~OPTION_BEGIN;
4461
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
3469
return(Log_event::EVENT_SKIP_COUNT);
4463
DBUG_RETURN(Log_event::do_shall_skip(rli));
3471
return(Log_event::do_shall_skip(rli));
4465
#endif /* !MYSQL_CLIENT */
4468
3475
/**************************************************************************
4469
3476
User_var_log_event methods
4470
3477
**************************************************************************/
4472
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4473
3479
void User_var_log_event::pack_info(Protocol* protocol)
4476
uint val_offset= 4 + name_len;
4477
uint event_len= val_offset;
3482
uint32_t val_offset= 4 + name_len;
3483
uint32_t event_len= val_offset;
4481
3487
if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
4483
strmov(buf + val_offset, "NULL");
3489
my_stpcpy(buf + val_offset, "NULL");
4484
3490
event_len= val_offset + 4;
4634
3638
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
4636
3640
return (write_header(file, event_length) ||
4637
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4638
my_b_safe_write(file, (uchar*) name, name_len) ||
4639
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3641
my_b_safe_write(file, (unsigned char*) buf, sizeof(buf)) ||
3642
my_b_safe_write(file, (unsigned char*) name, name_len) ||
3643
my_b_safe_write(file, (unsigned char*) buf1, buf1_length) ||
4640
3644
my_b_safe_write(file, pos, val_len));
4646
User_var_log_event::print()
4650
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4652
Write_on_release_cache cache(&print_event_info->head_cache, file,
4653
Write_on_release_cache::FLUSH_F);
4655
if (!print_event_info->short_form)
4657
print_header(&cache, print_event_info, FALSE);
4658
my_b_printf(&cache, "\tUser_var\n");
4661
my_b_printf(&cache, "SET @`");
4662
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4663
my_b_printf(&cache, "`");
4667
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4674
char real_buf[FMT_G_BUFSIZE(14)];
4675
float8get(real_val, val);
4676
my_sprintf(real_buf, (real_buf, "%.14g", real_val));
4677
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4681
longlong10_to_str(uint8korr(val), int_buf, -10);
4682
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4684
case DECIMAL_RESULT:
4687
int str_len= sizeof(str_buf) - 1;
4688
int precision= (int)val[0];
4689
int scale= (int)val[1];
4690
decimal_digit_t dec_buf[10];
4695
bin2decimal((uchar*) val+2, &dec, precision, scale);
4696
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4697
str_buf[str_len]= 0;
4698
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4704
Let's express the string in hex. That's the most robust way. If we
4705
print it in character form instead, we need to escape it with
4706
character_set_client which we don't know (we will know it in 5.0, but
4707
in 4.1 we don't know it easily when we are printing
4708
User_var_log_event). Explanation why we would need to bother with
4709
character_set_client (quoting Bar):
4710
> Note, the parser doesn't switch to another unescaping mode after
4711
> it has met a character set introducer.
4712
> For example, if an SJIS client says something like:
4713
> SET @a= _ucs2 \0a\0b'
4714
> the string constant is still unescaped according to SJIS, not
4715
> according to UCS2.
4720
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4721
break; // no error, as we are 'void'
4722
str_to_hex(hex_str, val, val_len);
4724
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4725
specify the variable's collation. It will however cause problems when
4726
people want to mysqlbinlog|mysql into another server not supporting the
4727
character set. But there's not much to do about this and it's unlikely.
4729
if (!(cs= get_charset(charset_number, MYF(0))))
4731
Generate an unusable command (=> syntax error) is probably the best
4732
thing we can do here.
4734
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4736
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4737
cs->csname, hex_str, cs->name,
4738
print_event_info->delimiter);
4753
3650
User_var_log_event::do_apply_event()
4756
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4757
3653
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
4760
CHARSET_INFO *charset;
3656
const CHARSET_INFO *charset;
4761
3657
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
4763
3659
LEX_STRING user_var_name;
4764
3660
user_var_name.str= name;
4765
3661
user_var_name.length= name_len;
4766
3662
double real_val;
4770
3666
We are now in a statement until the associated query log event has
4845
3741
return continue_group(rli);
4847
#endif /* !MYSQL_CLIENT */
4850
3745
/**************************************************************************
4851
3746
Slave_log_event methods
4852
3747
**************************************************************************/
4854
#ifdef HAVE_REPLICATION
4856
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4858
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4860
if (print_event_info->short_form)
4862
print_header(&cache, print_event_info, FALSE);
4863
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4867
#ifndef MYSQL_CLIENT
4868
3749
void Slave_log_event::pack_info(Protocol *protocol)
4870
3751
char buf[256+HOSTNAME_LENGTH], *pos;
4871
pos= strmov(buf, "host=");
4872
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4873
pos= strmov(pos, ",port=");
3752
pos= my_stpcpy(buf, "host=");
3753
pos= my_stpncpy(pos, master_host.c_str(), HOSTNAME_LENGTH);
3754
pos= my_stpcpy(pos, ",port=");
4874
3755
pos= int10_to_str((long) master_port, pos, 10);
4875
pos= strmov(pos, ",log=");
4876
pos= strmov(pos, master_log);
4877
pos= strmov(pos, ",pos=");
4878
pos= longlong10_to_str(master_pos, pos, 10);
3756
pos= my_stpcpy(pos, ",log=");
3757
pos= my_stpcpy(pos, master_log.c_str());
3758
pos= my_stpcpy(pos, ",pos=");
3759
pos= int64_t10_to_str(master_pos, pos, 10);
4879
3760
protocol->store(buf, pos-buf, &my_charset_bin);
4881
#endif /* !MYSQL_CLIENT */
4884
#ifndef MYSQL_CLIENT
4887
3766
re-write this better without holding both locks at the same time
4890
3769
Relay_log_info* rli)
4891
3770
:Log_event(thd_arg, 0, 0) , mem_pool(0), master_host(0)
4893
DBUG_ENTER("Slave_log_event");
4894
3772
if (!rli->inited) // QQ When can this happen ?
4897
3775
Master_info* mi = rli->mi;
4898
3776
// TODO: re-write this better without holding both locks at the same time
4899
3777
pthread_mutex_lock(&mi->data_lock);
4900
3778
pthread_mutex_lock(&rli->data_lock);
4901
master_host_len = strlen(mi->host);
4902
master_log_len = strlen(rli->group_master_log_name);
4903
3779
// on OOM, just do not initialize the structure and print the error
4904
3780
if ((mem_pool = (char*)my_malloc(get_data_size() + 1,
4907
master_host = mem_pool + SL_MASTER_HOST_OFFSET ;
4908
memcpy(master_host, mi->host, master_host_len + 1);
4909
master_log = master_host + master_host_len + 1;
4910
memcpy(master_log, rli->group_master_log_name, master_log_len + 1);
4911
master_port = mi->port;
3783
master_host.assign(mi->getHostname());
3784
master_log.assign(rli->group_master_log_name);
3785
master_port = mi->getPort();
4912
3786
master_pos = rli->group_master_log_pos;
4913
DBUG_PRINT("info", ("master_log: %s pos: %lu", master_log,
4914
(ulong) master_pos));
4917
sql_print_error("Out of memory while recording slave event");
3789
sql_print_error(_("Out of memory while recording slave event"));
4918
3790
pthread_mutex_unlock(&rli->data_lock);
4919
3791
pthread_mutex_unlock(&mi->data_lock);
4922
#endif /* !MYSQL_CLIENT */
4925
3796
Slave_log_event::~Slave_log_event()
4927
my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
4932
void Slave_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4934
Write_on_release_cache cache(&print_event_info->head_cache, file);
4937
if (print_event_info->short_form)
4939
print_header(&cache, print_event_info, FALSE);
4940
my_b_printf(&cache, "\n\
4941
Slave: master_host: '%s' master_port: %d master_log: '%s' master_pos: %s\n",
4942
master_host, master_port, master_log, llstr(master_pos, llbuff));
4944
#endif /* MYSQL_CLIENT */
4947
3802
int Slave_log_event::get_data_size()
4949
return master_host_len + master_log_len + 1 + SL_MASTER_HOST_OFFSET;
3804
return master_host.length() + master_log.length() + 1 + SL_MASTER_HOST_OFFSET;
4953
#ifndef MYSQL_CLIENT
4954
3808
bool Slave_log_event::write(IO_CACHE* file)
4956
3810
ulong event_length= get_data_size();
4959
3813
// log and host are already there
4961
3815
return (write_header(file, event_length) ||
4962
my_b_safe_write(file, (uchar*) mem_pool, event_length));
3816
my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
4967
void Slave_log_event::init_from_mem_pool(int data_size)
3820
void Slave_log_event::init_from_mem_pool()
4969
3822
master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET);
4970
3823
master_port = uint2korr(mem_pool + SL_MASTER_PORT_OFFSET);
4971
master_host = mem_pool + SL_MASTER_HOST_OFFSET;
4972
master_host_len = strlen(master_host);
4974
master_log = master_host + master_host_len + 1;
4975
if (master_log > mem_pool + data_size)
4980
master_log_len = strlen(master_log);
4984
/** This code is not used, so has not been updated to be format-tolerant. */
4985
Slave_log_event::Slave_log_event(const char* buf, uint event_len)
4986
:Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0)
4988
if (event_len < LOG_EVENT_HEADER_LEN)
4990
event_len -= LOG_EVENT_HEADER_LEN;
4991
if (!(mem_pool = (char*) my_malloc(event_len + 1, MYF(MY_WME))))
4993
memcpy(mem_pool, buf + LOG_EVENT_HEADER_LEN, event_len);
4994
mem_pool[event_len] = 0;
4995
init_from_mem_pool(event_len);
4999
#ifndef MYSQL_CLIENT
5000
int Slave_log_event::do_apply_event(Relay_log_info const *rli)
3825
/* Assign these correctly */
3826
master_host.assign(mem_pool + SL_MASTER_HOST_OFFSET);
3827
master_log.assign();
3832
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5002
3834
if (mysql_bin_log.is_open())
5003
3835
mysql_bin_log.write(this);
5006
#endif /* !MYSQL_CLIENT */
5009
3840
/**************************************************************************
5185
3988
sql_ex.force_new_format();
5186
3989
inited_from_old = 1;
5193
Create_file_log_event::print()
5197
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5200
Write_on_release_cache cache(&print_event_info->head_cache, file);
5202
if (print_event_info->short_form)
5204
if (enable_local && check_fname_outside_temp_buf())
5205
Load_log_event::print(file, print_event_info);
5211
Load_log_event::print(file, print_event_info,
5212
!check_fname_outside_temp_buf());
5214
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5215
SHOW BINLOG EVENTS we don't.
5217
my_b_printf(&cache, "#");
5220
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5224
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5226
print(file, print_event_info, 0);
5228
#endif /* MYSQL_CLIENT */
5232
3996
Create_file_log_event::pack_info()
5235
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5236
3999
void Create_file_log_event::pack_info(Protocol *protocol)
5238
4001
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
5239
pos= strmov(buf, "db=");
4002
pos= my_stpcpy(buf, "db=");
5240
4003
memcpy(pos, db, db_len);
5241
pos= strmov(pos + db_len, ";table=");
4004
pos= my_stpcpy(pos + db_len, ";table=");
5242
4005
memcpy(pos, table_name, table_name_len);
5243
pos= strmov(pos + table_name_len, ";file_id=");
4006
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5244
4007
pos= int10_to_str((long) file_id, pos, 10);
5245
pos= strmov(pos, ";block_len=");
4008
pos= my_stpcpy(pos, ";block_len=");
5246
4009
pos= int10_to_str((long) block_len, pos, 10);
5247
4010
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5249
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5253
4015
Create_file_log_event::do_apply_event()
5256
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5257
4018
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
5259
4020
char proc_info[17+FN_REFLEN+10], *fname_buf;
5265
bzero((char*)&file, sizeof(file));
5266
fname_buf= strmov(proc_info, "Making temp file ");
4026
memset(&file, 0, sizeof(file));
4027
fname_buf= my_stpcpy(proc_info, "Making temp file ");
5267
4028
ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
5268
thd_proc_info(thd, proc_info);
4029
thd->set_proc_info(proc_info);
5269
4030
my_delete(fname_buf, MYF(0)); // old copy may exist already
5270
4031
if ((fd= my_create(fname_buf, CREATE_MODE,
5271
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5272
4033
MYF(MY_WME))) < 0 ||
5273
4034
init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0,
5274
4035
MYF(MY_WME|MY_NABP)))
5276
4037
rli->report(ERROR_LEVEL, my_errno,
5277
"Error in Create_file event: could not open file '%s'",
4038
_("Error in Create_file event: could not open file '%s'"),
5282
4043
// a trick to avoid allocating another buffer
5283
4044
fname= fname_buf;
5284
fname_len= (uint) (strmov(ext, ".data") - fname);
4045
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5285
4046
if (write_base(&file))
5287
strmov(ext, ".info"); // to have it right in the error message
4048
my_stpcpy(ext, ".info"); // to have it right in the error message
5288
4049
rli->report(ERROR_LEVEL, my_errno,
5289
"Error in Create_file event: could not write to file '%s'",
4050
_("Error in Create_file event: could not write to file '%s'"),
5293
4054
end_io_cache(&file);
5294
4055
my_close(fd, MYF(0));
5296
4057
// fname_buf now already has .data, not .info, because we did our trick
5297
4058
my_delete(fname_buf, MYF(0)); // old copy may exist already
5298
4059
if ((fd= my_create(fname_buf, CREATE_MODE,
5299
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5302
4063
rli->report(ERROR_LEVEL, my_errno,
5303
"Error in Create_file event: could not open file '%s'",
4064
_("Error in Create_file event: could not open file '%s'"),
5307
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4068
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5309
4070
rli->report(ERROR_LEVEL, my_errno,
5310
"Error in Create_file event: write to '%s' failed",
4071
_("Error in Create_file event: write to '%s' failed"),
5332
4092
Append_block_log_event ctor
5335
#ifndef MYSQL_CLIENT
5336
4095
Append_block_log_event::Append_block_log_event(THD *thd_arg,
5337
4096
const char *db_arg,
4097
unsigned char *block_arg,
4098
uint32_t block_len_arg,
5340
4099
bool using_trans)
5341
4100
:Log_event(thd_arg,0, using_trans), block(block_arg),
5342
4101
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
5349
4107
Append_block_log_event ctor
5352
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4110
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5353
4111
const Format_description_log_event* description_event)
5354
4112
:Log_event(buf, description_event),block(0)
5356
DBUG_ENTER("Append_block_log_event::Append_block_log_event(char*,...)");
5357
uint8 common_header_len= description_event->common_header_len;
5358
uint8 append_block_header_len=
4114
uint8_t common_header_len= description_event->common_header_len;
4115
uint8_t append_block_header_len=
5359
4116
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
5360
uint total_header_len= common_header_len+append_block_header_len;
4117
uint32_t total_header_len= common_header_len+append_block_header_len;
5361
4118
if (len < total_header_len)
5363
4120
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
5364
block= (uchar*)buf + total_header_len;
4121
block= (unsigned char*)buf + total_header_len;
5365
4122
block_len= len - total_header_len;
5371
4128
Append_block_log_event::write()
5374
#ifndef MYSQL_CLIENT
5375
4131
bool Append_block_log_event::write(IO_CACHE* file)
5377
uchar buf[APPEND_BLOCK_HEADER_LEN];
4133
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5378
4134
int4store(buf + AB_FILE_ID_OFFSET, file_id);
5379
4135
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
5380
4136
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
5381
my_b_safe_write(file, (uchar*) block, block_len));
5387
Append_block_log_event::print()
5391
void Append_block_log_event::print(FILE* file,
5392
PRINT_EVENT_INFO* print_event_info)
5394
Write_on_release_cache cache(&print_event_info->head_cache, file);
5396
if (print_event_info->short_form)
5398
print_header(&cache, print_event_info, FALSE);
5399
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5400
get_type_str(), file_id, block_len);
5402
#endif /* MYSQL_CLIENT */
4137
my_b_safe_write(file, (unsigned char*) block, block_len));
5406
4142
Append_block_log_event::pack_info()
5409
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5410
4145
void Append_block_log_event::pack_info(Protocol *protocol)
5414
length= (uint) my_sprintf(buf,
5415
(buf, ";file_id=%u;block_len=%u", file_id,
4149
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
5417
4151
protocol->store(buf, length, &my_charset_bin);
5436
4170
char proc_info[17+FN_REFLEN+10], *fname= proc_info+17;
5439
DBUG_ENTER("Append_block_log_event::do_apply_event");
5441
fname= strmov(proc_info, "Making temp file ");
4174
fname= my_stpcpy(proc_info, "Making temp file ");
5442
4175
slave_load_file_stem(fname, file_id, server_id, ".data");
5443
thd_proc_info(thd, proc_info);
4176
thd->set_proc_info(proc_info);
5444
4177
if (get_create_or_append())
5446
4179
my_delete(fname, MYF(0)); // old copy may exist already
5447
4180
if ((fd= my_create(fname, CREATE_MODE,
5448
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5449
4182
MYF(MY_WME))) < 0)
5451
4184
rli->report(ERROR_LEVEL, my_errno,
5452
"Error in %s event: could not create file '%s'",
4185
_("Error in %s event: could not create file '%s'"),
5453
4186
get_type_str(), fname);
5457
else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW,
4190
else if ((fd = my_open(fname, O_WRONLY | O_APPEND,
5458
4191
MYF(MY_WME))) < 0)
5460
4193
rli->report(ERROR_LEVEL, my_errno,
5461
"Error in %s event: could not open file '%s'",
4194
_("Error in %s event: could not open file '%s'"),
5462
4195
get_type_str(), fname);
5465
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4198
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5467
4200
rli->report(ERROR_LEVEL, my_errno,
5468
"Error in %s event: write to '%s' failed",
4201
_("Error in %s event: write to '%s' failed"),
5469
4202
get_type_str(), fname);
5516
4246
Delete_file_log_event::write()
5519
#ifndef MYSQL_CLIENT
5520
4249
bool Delete_file_log_event::write(IO_CACHE* file)
5522
uchar buf[DELETE_FILE_HEADER_LEN];
4251
unsigned char buf[DELETE_FILE_HEADER_LEN];
5523
4252
int4store(buf + DF_FILE_ID_OFFSET, file_id);
5524
4253
return (write_header(file, sizeof(buf)) ||
5525
4254
my_b_safe_write(file, buf, sizeof(buf)));
5531
Delete_file_log_event::print()
5535
void Delete_file_log_event::print(FILE* file,
5536
PRINT_EVENT_INFO* print_event_info)
5538
Write_on_release_cache cache(&print_event_info->head_cache, file);
5540
if (print_event_info->short_form)
5542
print_header(&cache, print_event_info, FALSE);
5543
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5545
#endif /* MYSQL_CLIENT */
5548
4259
Delete_file_log_event::pack_info()
5551
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5552
4262
void Delete_file_log_event::pack_info(Protocol *protocol)
5556
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5557
protocol->store(buf, (int32) length, &my_charset_bin);
4266
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4267
protocol->store(buf, (int32_t) length, &my_charset_bin);
5562
4271
Delete_file_log_event::do_apply_event()
5565
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5566
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli)
4274
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5568
4276
char fname[FN_REFLEN+10];
5569
4277
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
5570
4278
(void) my_delete(fname, MYF(MY_WME));
5571
strmov(ext, ".info");
4279
my_stpcpy(ext, ".info");
5572
4280
(void) my_delete(fname, MYF(MY_WME));
5575
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5578
4285
/**************************************************************************
5613
4318
Execute_load_log_event::write()
5616
#ifndef MYSQL_CLIENT
5617
4321
bool Execute_load_log_event::write(IO_CACHE* file)
5619
uchar buf[EXEC_LOAD_HEADER_LEN];
4323
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5620
4324
int4store(buf + EL_FILE_ID_OFFSET, file_id);
5621
4325
return (write_header(file, sizeof(buf)) ||
5622
4326
my_b_safe_write(file, buf, sizeof(buf)));
5628
Execute_load_log_event::print()
5632
void Execute_load_log_event::print(FILE* file,
5633
PRINT_EVENT_INFO* print_event_info)
5635
Write_on_release_cache cache(&print_event_info->head_cache, file);
5637
if (print_event_info->short_form)
5639
print_header(&cache, print_event_info, FALSE);
5640
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
5646
4331
Execute_load_log_event::pack_info()
5649
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5650
4334
void Execute_load_log_event::pack_info(Protocol *protocol)
5654
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5655
protocol->store(buf, (int32) length, &my_charset_bin);
4338
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4339
protocol->store(buf, (int32_t) length, &my_charset_bin);
5747
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5750
4435
/**************************************************************************
5751
4436
Begin_load_query_log_event methods
5752
4437
**************************************************************************/
5754
#ifndef MYSQL_CLIENT
5755
4439
Begin_load_query_log_event::
5756
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5757
uint block_len_arg, bool using_trans)
4440
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, unsigned char* block_arg,
4441
uint32_t block_len_arg, bool using_trans)
5758
4442
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
5761
4445
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
5766
4449
Begin_load_query_log_event::
5767
Begin_load_query_log_event(const char* buf, uint len,
4450
Begin_load_query_log_event(const char* buf, uint32_t len,
5768
4451
const Format_description_log_event* desc_event)
5769
4452
:Append_block_log_event(buf, len, desc_event)
5774
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5775
4457
int Begin_load_query_log_event::get_create_or_append() const
5777
4459
return 1; /* create the file */
5779
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5782
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
5783
4463
Log_event::enum_skip_reason
5784
4464
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5846
#ifndef MYSQL_CLIENT
5848
4524
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
5850
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4526
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5851
4527
int4store(buf, file_id);
5852
4528
int4store(buf + 4, fn_pos_start);
5853
4529
int4store(buf + 4 + 4, fn_pos_end);
5854
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4530
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5855
4531
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5861
void Execute_load_query_log_event::print(FILE* file,
5862
PRINT_EVENT_INFO* print_event_info)
5864
print(file, print_event_info, 0);
5868
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5870
void Execute_load_query_log_event::print(FILE* file,
5871
PRINT_EVENT_INFO* print_event_info,
5872
const char *local_fname)
5874
Write_on_release_cache cache(&print_event_info->head_cache, file);
5876
print_query_header(&cache, print_event_info);
5880
my_b_write(&cache, (uchar*) query, fn_pos_start);
5881
my_b_printf(&cache, " LOCAL INFILE \'");
5882
my_b_printf(&cache, local_fname);
5883
my_b_printf(&cache, "\'");
5884
if (dup_handling == LOAD_DUP_REPLACE)
5885
my_b_printf(&cache, " REPLACE");
5886
my_b_printf(&cache, " INTO");
5887
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5888
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5892
my_b_write(&cache, (uchar*) query, q_len);
5893
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5896
if (!print_event_info->short_form)
5897
my_b_printf(&cache, "# file_id: %d \n", file_id);
5902
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5903
4535
void Execute_load_query_log_event::pack_info(Protocol *protocol)
5905
4537
char *buf, *pos;
6166
4781
m_flags= uint2korr(post_start);
6168
uchar const *const var_start=
6169
(const uchar *)buf + common_header_len + post_header_len;
6170
uchar const *const ptr_width= var_start;
6171
uchar *ptr_after_width= (uchar*) ptr_width;
6172
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
4783
unsigned char const *const var_start=
4784
(const unsigned char *)buf + common_header_len + post_header_len;
4785
unsigned char const *const ptr_width= var_start;
4786
unsigned char *ptr_after_width= (unsigned char*) ptr_width;
6173
4787
m_width = net_field_length(&ptr_after_width);
6174
DBUG_PRINT("debug", ("m_width=%lu", m_width));
6175
4788
/* if bitmap_init fails, catched in is_valid() */
6176
4789
if (likely(!bitmap_init(&m_cols,
6177
4790
m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL,
6181
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6182
4794
memcpy(m_cols.bitmap, ptr_after_width, (m_width + 7) / 8);
6183
4795
create_last_word_mask(&m_cols);
6184
4796
ptr_after_width+= (m_width + 7) / 8;
6185
DBUG_DUMP("m_cols", (uchar*) m_cols.bitmap, no_bytes_in_map(&m_cols));
6189
4800
// Needed because bitmap_init() does not set it to null on failure
6190
4801
m_cols.bitmap= NULL;
6194
4805
m_cols_ai.bitmap= m_cols.bitmap; /* See explanation in is_valid() */
6196
4807
if (event_type == UPDATE_ROWS_EVENT)
6198
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6200
4809
/* if bitmap_init fails, caught in is_valid() */
6201
4810
if (likely(!bitmap_init(&m_cols_ai,
6202
4811
m_width <= sizeof(m_bitbuf_ai)*8 ? m_bitbuf_ai : NULL,
6206
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
6207
4815
memcpy(m_cols_ai.bitmap, ptr_after_width, (m_width + 7) / 8);
6208
4816
create_last_word_mask(&m_cols_ai);
6209
4817
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
4821
// Needed because bitmap_init() does not set it to null on failure
6216
4822
m_cols_ai.bitmap= 0;
6221
const uchar* const ptr_rows_data= (const uchar*) ptr_after_width;
6223
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
m_rows_buf= (uchar*) my_malloc(data_size, MYF(MY_WME));
4827
const unsigned char* const ptr_rows_data= (const unsigned char*) ptr_after_width;
4829
size_t const data_size= event_len - (ptr_rows_data - (const unsigned char *) buf);
4831
m_rows_buf= (unsigned char*) my_malloc(data_size, MYF(MY_WME));
6228
4832
if (likely((bool)m_rows_buf))
6230
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6231
4834
m_curr_row= m_rows_buf;
6233
4835
m_rows_end= m_rows_buf + data_size;
6234
4836
m_rows_cur= m_rows_end;
6235
4837
memcpy(m_rows_buf, ptr_rows_data, data_size);
6874
5434
Note that this should be the number of *bits*, not the number of
6877
uchar sbuf[sizeof(m_width)];
5437
unsigned char sbuf[sizeof(m_width)];
6878
5438
my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf;
6879
5439
bool res= false;
6880
uchar *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
6881
DBUG_ASSERT(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
5440
unsigned char *const sbuf_end= net_store_length(sbuf, (size_t) m_width);
5441
assert(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
6883
DBUG_DUMP("m_width", sbuf, (size_t) (sbuf_end - sbuf));
6884
5443
res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
6886
DBUG_PRINT_BITSET("debug", "writing cols: %s", &m_cols);
6887
res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
5445
res= res || my_b_safe_write(file, (unsigned char*) m_cols.bitmap,
6888
5446
no_bytes_in_map(&m_cols));
6890
5448
TODO[refactor write]: Remove the "down cast" here (and elsewhere).
6892
5450
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
res= res || my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
5452
res= res || my_b_safe_write(file, (unsigned char*) m_cols_ai.bitmap,
6897
5453
no_bytes_in_map(&m_cols_ai));
6899
DBUG_DUMP("rows", m_rows_buf, data_size);
6900
5455
res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
6907
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6908
5462
void Rows_log_event::pack_info(Protocol *protocol)
6911
5465
char const *const flagstr=
6912
5466
get_flags(STMT_END_F) ? " flags: STMT_END_F" : "";
6913
size_t bytes= my_snprintf(buf, sizeof(buf),
6914
"table_id: %lu%s", m_table_id, flagstr);
5467
size_t bytes= snprintf(buf, sizeof(buf),
5468
"table_id: %lu%s", m_table_id, flagstr);
6915
5469
protocol->store(buf, bytes, &my_charset_bin);
6920
void Rows_log_event::print_helper(FILE *file,
6921
PRINT_EVENT_INFO *print_event_info,
6922
char const *const name)
6924
IO_CACHE *const head= &print_event_info->head_cache;
6925
IO_CACHE *const body= &print_event_info->body_cache;
6926
if (!print_event_info->short_form)
6928
bool const last_stmt_event= get_flags(STMT_END_F);
6929
print_header(head, print_event_info, !last_stmt_event);
6930
my_b_printf(head, "\t%s: table id %lu%s\n",
6932
last_stmt_event ? " flags: STMT_END_F" : "");
6933
print_base64(body, print_event_info, !last_stmt_event);
6936
if (get_flags(STMT_END_F))
6938
copy_event_cache_to_file_and_reinit(head, file);
6939
copy_event_cache_to_file_and_reinit(body, file);
6944
5473
/**************************************************************************
6945
5474
Table_map_log_event member functions and support functions
7159
5670
const char *const vpart= buf + common_header_len + post_header_len;
7161
5672
/* Extract the length of the various parts from the buffer */
7162
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
7163
m_dblen= *(uchar*) ptr_dblen;
5673
unsigned char const *const ptr_dblen= (unsigned char const*)vpart + 0;
5674
m_dblen= *(unsigned char*) ptr_dblen;
7165
5676
/* Length of database name + counter + terminating null */
7166
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
7167
m_tbllen= *(uchar*) ptr_tbllen;
5677
unsigned char const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
5678
m_tbllen= *(unsigned char*) ptr_tbllen;
7169
5680
/* Length of table name + counter + terminating null */
7170
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
7171
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5681
unsigned char const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
5682
unsigned char *ptr_after_colcnt= (unsigned char*) ptr_colcnt;
7172
5683
m_colcnt= net_field_length(&ptr_after_colcnt);
7174
DBUG_PRINT("info",("m_dblen: %lu off: %ld m_tbllen: %lu off: %ld m_colcnt: %lu off: %ld",
7175
(ulong) m_dblen, (long) (ptr_dblen-(const uchar*)vpart),
7176
(ulong) m_tbllen, (long) (ptr_tbllen-(const uchar*)vpart),
7177
m_colcnt, (long) (ptr_colcnt-(const uchar*)vpart)));
7179
5685
/* Allocate mem for all fields in one go. If fails, caught in is_valid() */
7180
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5686
m_memory= (unsigned char*) my_multi_malloc(MYF(MY_WME),
7181
5687
&m_dbnam, (uint) m_dblen + 1,
7182
5688
&m_tblnam, (uint) m_tbllen + 1,
7183
5689
&m_coltype, (uint) m_colcnt,
7191
5697
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
7193
5699
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
7194
bytes_read= ptr_after_colcnt - (uchar *)buf;
7195
DBUG_PRINT("info", ("Bytes read: %d.\n", bytes_read));
5700
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
7196
5701
if (bytes_read < event_len)
7198
5703
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
7199
DBUG_ASSERT(m_field_metadata_size <= (m_colcnt * 2));
7200
uint num_null_bytes= (m_colcnt + 7) / 8;
7201
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5704
assert(m_field_metadata_size <= (m_colcnt * 2));
5705
uint32_t num_null_bytes= (m_colcnt + 7) / 8;
5706
m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
7202
5707
&m_null_bits, num_null_bytes,
7203
5708
&m_field_metadata, m_field_metadata_size,
7205
5710
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
7206
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5711
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
7207
5712
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
7215
5719
Table_map_log_event::~Table_map_log_event()
7217
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
7218
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5721
free(m_meta_memory);
7245
5747
pthread_mutex_unlock(&LOCK_thread_count);
7247
5749
if (!(memory= my_multi_malloc(MYF(MY_WME),
7248
&table_list, (uint) sizeof(RPL_TABLE_LIST),
5750
&table_list, (uint) sizeof(RPL_TableList),
7249
5751
&db_mem, (uint) NAME_LEN + 1,
7250
5752
&tname_mem, (uint) NAME_LEN + 1,
7252
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5754
return(HA_ERR_OUT_OF_MEM);
7254
bzero(table_list, sizeof(*table_list));
5756
memset(table_list, 0, sizeof(*table_list));
7255
5757
table_list->db = db_mem;
7256
5758
table_list->alias= table_list->table_name = tname_mem;
7257
5759
table_list->lock_type= TL_WRITE;
7258
5760
table_list->next_global= table_list->next_local= 0;
7259
5761
table_list->table_id= m_table_id;
7260
5762
table_list->updating= 1;
7261
strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
7262
strmov(table_list->table_name, m_tblnam);
5763
my_stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
5764
my_stpcpy(table_list->table_name, m_tblnam);
7266
5768
if (!rpl_filter->db_ok(table_list->db) ||
7267
5769
(rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
7269
my_free(memory, MYF(MY_WME));
7385
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
7387
#ifndef MYSQL_CLIENT
7388
5889
bool Table_map_log_event::write_data_header(IO_CACHE *file)
7390
DBUG_ASSERT(m_table_id != ~0UL);
7391
uchar buf[TABLE_MAP_HEADER_LEN];
7392
DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master",
7394
int4store(buf + 0, m_table_id);
7395
int2store(buf + 4, m_flags);
7396
return (my_b_safe_write(file, buf, 6));
7398
int6store(buf + TM_MAPID_OFFSET, (ulonglong)m_table_id);
5891
assert(m_table_id != UINT32_MAX);
5892
unsigned char buf[TABLE_MAP_HEADER_LEN];
5893
int6store(buf + TM_MAPID_OFFSET, (uint64_t)m_table_id);
7399
5894
int2store(buf + TM_FLAGS_OFFSET, m_flags);
7400
5895
return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
7403
5898
bool Table_map_log_event::write_data_body(IO_CACHE *file)
7405
DBUG_ASSERT(m_dbnam != NULL);
7406
DBUG_ASSERT(m_tblnam != NULL);
5900
assert(m_dbnam != NULL);
5901
assert(m_tblnam != NULL);
7407
5902
/* We use only one byte per length for storage in event: */
7408
DBUG_ASSERT(m_dblen < 128);
7409
DBUG_ASSERT(m_tbllen < 128);
7411
uchar const dbuf[]= { (uchar) m_dblen };
7412
uchar const tbuf[]= { (uchar) m_tbllen };
7414
uchar cbuf[sizeof(m_colcnt)];
7415
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
7416
DBUG_ASSERT(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
5903
assert(m_dblen < 128);
5904
assert(m_tbllen < 128);
5906
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5907
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
5909
unsigned char cbuf[sizeof(m_colcnt)];
5910
unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5911
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
7419
5914
Store the size of the field metadata.
7421
uchar mbuf[sizeof(m_field_metadata_size)];
7422
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
5916
unsigned char mbuf[sizeof(m_field_metadata_size)];
5917
unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
7424
5919
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
7425
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
5920
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7426
5921
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
7427
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
5922
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7428
5923
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
7429
5924
my_b_safe_write(file, m_coltype, m_colcnt) ||
7430
5925
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
7431
5926
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
7432
5927
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7436
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
7439
5932
Print some useful information for the SHOW BINARY LOG information
7443
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
7444
5936
void Table_map_log_event::pack_info(Protocol *protocol)
7447
size_t bytes= my_snprintf(buf, sizeof(buf),
7448
"table_id: %lu (%s.%s)",
7449
m_table_id, m_dbnam, m_tblnam);
5939
size_t bytes= snprintf(buf, sizeof(buf),
5940
"table_id: %lu (%s.%s)",
5941
m_table_id, m_dbnam, m_tblnam);
7450
5942
protocol->store(buf, bytes, &my_charset_bin);
7459
void Table_map_log_event::print(FILE *file, PRINT_EVENT_INFO *print_event_info)
7461
if (!print_event_info->short_form)
7463
print_header(&print_event_info->head_cache, print_event_info, TRUE);
7464
my_b_printf(&print_event_info->head_cache,
7465
"\tTable_map: `%s`.`%s` mapped to number %lu\n",
7466
m_dbnam, m_tblnam, m_table_id);
7467
print_base64(&print_event_info->body_cache, print_event_info, TRUE);
7472
5946
/**************************************************************************
7473
5947
Write_rows_log_event member functions
7816
6262
if (last_uniq_key(table, keynum) &&
7817
6263
!table->file->referenced_by_foreign_key())
7819
DBUG_PRINT("info",("Updating row using ha_update_row()"));
7820
6265
error=table->file->ha_update_row(table->record[1],
7821
6266
table->record[0]);
7822
6267
switch (error) {
7824
6269
case HA_ERR_RECORD_IS_THE_SAME:
7825
DBUG_PRINT("info",("ignoring HA_ERR_RECORD_IS_THE_SAME error from"
7826
" ha_update_row()"));
7833
DBUG_PRINT("info",("ha_update_row() returns error %d",error));
7834
6276
table->file->print_error(error, MYF(0));
7841
DBUG_PRINT("info",("Deleting offending row and trying to write new one again"));
7842
6283
if ((error= table->file->ha_delete_row(table->record[1])))
7844
DBUG_PRINT("info",("ha_delete_row() returns error %d",error));
7845
6285
table->file->print_error(error, MYF(0));
7848
6288
/* Will retry ha_write_row() with the offending row removed. */
7858
6297
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
7860
DBUG_ASSERT(m_table != NULL);
6299
assert(m_table != NULL);
7862
6301
write_row(rli, /* if 1 then overwrite */
7863
6302
bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1);
7865
6304
if (error && !thd->is_error())
7868
6307
my_error(ER_UNKNOWN_ERROR, MYF(0));
7874
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
7877
void Write_rows_log_event::print(FILE *file, PRINT_EVENT_INFO* print_event_info)
7879
Rows_log_event::print_helper(file, print_event_info, "Write_rows");
7883
6314
/**************************************************************************
7884
6315
Delete_rows_log_event member functions
7885
6316
**************************************************************************/
7887
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
7889
6319
Compares table->record[0] and table->record[1]
7891
6321
Returns TRUE if different.
7893
static bool record_compare(TABLE *table)
6323
static bool record_compare(Table *table)
7896
6326
Need to set the X bit and the filler bits in both records since
8211
6598
Note: above record_compare will take into accout all record fields
8212
6599
which might be incorrect in case a partial row was given in the event
8216
Have to restart the scan to be able to fetch the next row.
8218
if (restart_count == 2)
8220
DBUG_PRINT("info", ("Record not found"));
8224
DBUG_DUMP("record found", table->record[0], table->s->reclength);
8226
6601
table->file->ha_rnd_end();
8228
DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
6603
assert(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
8232
6607
table->default_column_bitmaps();
8235
6610
table->default_column_bitmaps();
8242
6616
Constructor used to build an event for writing to the binary log.
8245
#ifndef MYSQL_CLIENT
8246
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6619
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, Table *tbl_arg,
8248
6621
bool is_transactional)
8249
6622
: Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
8252
#endif /* #if !defined(MYSQL_CLIENT) */
8255
6627
Constructor used by slave to read the event from the binary log.
8257
#ifdef HAVE_REPLICATION
8258
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint event_len,
6629
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint32_t event_len,
8259
6630
const Format_description_log_event
8260
6631
*description_event)
8261
6632
: Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event)
8266
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
8269
6638
Delete_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
8473
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
8476
void Update_rows_log_event::print(FILE *file,
8477
PRINT_EVENT_INFO* print_event_info)
8479
Rows_log_event::print_helper(file, print_event_info, "Update_rows");
8484
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6819
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
8485
6820
const Format_description_log_event *descr_event)
8486
6821
: Log_event(buf, descr_event)
8488
DBUG_ENTER("Incident_log_event::Incident_log_event");
8489
uint8 const common_header_len=
6823
uint8_t const common_header_len=
8490
6824
descr_event->common_header_len;
8491
uint8 const post_header_len=
6825
uint8_t const post_header_len=
8492
6826
descr_event->post_header_len[INCIDENT_EVENT-1];
8494
DBUG_PRINT("info",("event_len: %u; common_header_len: %d; post_header_len: %d",
8495
event_len, common_header_len, post_header_len));
8497
6828
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
8498
6829
char const *ptr= buf + common_header_len + post_header_len;
8499
6830
char const *const str_end= buf + event_len;
8500
uint8 len= 0; // Assignment to keep compiler happy
6831
uint8_t len= 0; // Assignment to keep compiler happy
8501
6832
const char *str= NULL; // Assignment to keep compiler happy
8502
6833
read_str(&ptr, str_end, &str, &len);
8503
6834
m_message.str= const_cast<char*>(str);
8504
6835
m_message.length= len;
8505
DBUG_PRINT("info", ("m_incident: %d", m_incident));
8523
DBUG_PRINT("info", ("m_incident: %d", m_incident));
8525
DBUG_ASSERT(0 <= m_incident);
8526
DBUG_ASSERT((size_t) m_incident <= sizeof(description)/sizeof(*description));
6853
assert(0 <= m_incident);
6854
assert((size_t) m_incident <= sizeof(description)/sizeof(*description));
8528
6856
return description[m_incident];
8532
#ifndef MYSQL_CLIENT
8533
6860
void Incident_log_event::pack_info(Protocol *protocol)
8537
6864
if (m_message.length > 0)
8538
bytes= my_snprintf(buf, sizeof(buf), "#%d (%s)",
8539
m_incident, description());
6865
bytes= snprintf(buf, sizeof(buf), "#%d (%s)",
6866
m_incident, description());
8541
bytes= my_snprintf(buf, sizeof(buf), "#%d (%s): %s",
8542
m_incident, description(), m_message.str);
6868
bytes= snprintf(buf, sizeof(buf), "#%d (%s): %s",
6869
m_incident, description(), m_message.str);
8543
6870
protocol->store(buf, bytes, &my_charset_bin);
8550
Incident_log_event::print(FILE *file,
8551
PRINT_EVENT_INFO *print_event_info)
8553
if (print_event_info->short_form)
8556
Write_on_release_cache cache(&print_event_info->head_cache, file);
8557
print_header(&cache, print_event_info, FALSE);
8558
my_b_printf(&cache, "\n# Incident: %s", description());
8562
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8564
6875
Incident_log_event::do_apply_event(Relay_log_info const *rli)
8566
DBUG_ENTER("Incident_log_event::do_apply_event");
8567
6877
rli->report(ERROR_LEVEL, ER_SLAVE_INCIDENT,
8568
6878
ER(ER_SLAVE_INCIDENT),
8570
6880
m_message.length > 0 ? m_message.str : "<none>");
8576
6886
Incident_log_event::write_data_header(IO_CACHE *file)
8578
DBUG_ENTER("Incident_log_event::write_data_header");
8579
DBUG_PRINT("enter", ("m_incident: %d", m_incident));
8580
uchar buf[sizeof(int16)];
8581
int2store(buf, (int16) m_incident);
8582
DBUG_RETURN(my_b_safe_write(file, buf, sizeof(buf)));
6888
unsigned char buf[sizeof(int16_t)];
6889
int2store(buf, (int16_t) m_incident);
6890
return(my_b_safe_write(file, buf, sizeof(buf)));
8586
6894
Incident_log_event::write_data_body(IO_CACHE *file)
8588
DBUG_ENTER("Incident_log_event::write_data_body");
8589
DBUG_RETURN(write_str(file, m_message.str, m_message.length));
6896
return(write_str(file, m_message.str, m_message.length));
8592
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8593
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6899
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
8594
6900
const Format_description_log_event* description_event)
8595
6901
:Log_event(buf, description_event)
8597
uint8 header_size= description_event->common_header_len;
6903
uint8_t header_size= description_event->common_header_len;
8598
6904
ident_len = event_len - header_size;
8599
6905
set_if_smaller(ident_len,FN_REFLEN-1);
8600
6906
log_ident= buf + header_size;
8607
The default values for these variables should be values that are
8608
*incorrect*, i.e., values that cannot occur in an event. This way,
8609
they will always be printed for the first event.
8611
st_print_event_info::st_print_event_info()
8612
:flags2_inited(0), sql_mode_inited(0),
8613
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8614
lc_time_names_number(~0),
8615
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8616
thread_id(0), thread_id_printed(false),
8617
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(FALSE)
8620
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8621
program's startup, but these explicit bzero() is for the day someone
8622
creates dynamic instances.
8624
bzero(db, sizeof(db));
8625
bzero(charset, sizeof(charset));
8626
bzero(time_zone_str, sizeof(time_zone_str));
8629
myf const flags = MYF(MY_WME | MY_NABP);
8630
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8631
open_cached_file(&body_cache, NULL, NULL, 0, flags);