118
126
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
119
127
Relay_log_info const *rli, THD *thd,
120
Table *table, const char * type,
128
TABLE *table, const char * type,
121
129
const char *log_name, ulong pos)
123
131
const char *handler_error= HA_ERR(ha_error);
124
132
char buff[MAX_SLAVE_ERRMSG], *slider;
125
133
const char *buff_end= buff + sizeof(buff);
127
List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
135
List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
131
139
for (err= it++, slider= buff; err && slider < buff_end - 1;
132
140
slider += len, err= it++)
134
len= snprintf(slider, buff_end - slider,
135
_(" %s, Error_code: %d;"), err->msg, err->code);
142
len= my_snprintf(slider, buff_end - slider,
143
" %s, Error_code: %d;", err->msg, err->code);
138
146
rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0,
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"),
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",
142
150
type, table->s->db.str,
143
151
table->s->table_name.str,
145
handler_error == NULL? _("<unknown>") : handler_error,
153
handler_error == NULL? "<unknown>" : handler_error,
151
159
Cache that will automatically be written to a dedicated file on
1033
1200
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);
1036
1213
*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)
1042
1397
inline Log_event::enum_skip_reason
1043
1398
Log_event::continue_group(Relay_log_info *rli)
1457
1843
This is used by the SQL slave thread to prepare the event before execution.
1459
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
1845
Query_log_event::Query_log_event(const char* buf, uint event_len,
1460
1846
const Format_description_log_event
1461
1847
*description_event,
1462
1848
Log_event_type event_type)
1463
:Log_event(buf, description_event), data_buf(0), query(NULL),
1464
db(NULL), catalog_len(0), status_vars_len(0),
1849
:Log_event(buf, description_event), data_buf(0), query(NullS),
1850
db(NullS), catalog_len(0), status_vars_len(0),
1465
1851
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1466
1852
auto_increment_increment(1), auto_increment_offset(1),
1467
1853
time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1471
uint8_t common_header_len, post_header_len;
1857
uint8 common_header_len, post_header_len;
1472
1858
Log_event::Byte *start;
1473
1859
const Log_event::Byte *end;
1474
1860
bool catalog_nz= 1;
1861
DBUG_ENTER("Query_log_event::Query_log_event(char*,...)");
1476
1863
common_header_len= description_event->common_header_len;
1477
1864
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));
1480
1869
We test if the event's length is sensible, and if so we compute data_len.
1621
2034
/* A 2nd variable part; this is common to all versions */
1622
memcpy(start, end, data_len); // Copy db and query
2035
memcpy((char*) start, end, data_len); // Copy db and query
1623
2036
start[data_len]= '\0'; // End query with \0 (For safetly)
1624
2037
db= (char *)start;
1625
2038
query= (char *)(start + db_len + 1);
1626
2039
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 */
1632
2212
Query_log_event::do_apply_event()
2215
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1634
2217
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1636
2219
return do_apply_event(rli, query, q_len);
1907
2528
Log_event::enum_skip_reason
1908
2529
Query_log_event::do_shall_skip(Relay_log_info *rli)
1910
assert(query && q_len > 0);
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);
1912
2535
if (rli->slave_skip_counter > 0)
1914
2537
if (strcmp("BEGIN", query) == 0)
1916
2539
thd->options|= OPTION_BEGIN;
1917
return(Log_event::continue_group(rli));
2540
DBUG_RETURN(Log_event::continue_group(rli));
1920
2543
if (strcmp("COMMIT", query) == 0 || strcmp("ROLLBACK", query) == 0)
1922
2545
thd->options&= ~OPTION_BEGIN;
1923
return(Log_event::EVENT_SKIP_COUNT);
2546
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
1926
return(Log_event::do_shall_skip(rli));
2549
DBUG_RETURN(Log_event::do_shall_skip(rli));
1930
2555
/**************************************************************************
1931
2556
Start_log_event_v3 methods
1932
2557
**************************************************************************/
2559
#ifndef MYSQL_CLIENT
1934
2560
Start_log_event_v3::Start_log_event_v3()
1935
2561
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1936
2562
artificial_event(0), dont_set_created(0)
1938
2564
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
1942
2569
Start_log_event_v3::pack_info()
2572
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1945
2573
void Start_log_event_v3::pack_info(Protocol *protocol)
1947
2575
char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
1948
pos= my_stpcpy(buf, "Server ver: ");
1949
pos= my_stpcpy(pos, server_version);
1950
pos= my_stpcpy(pos, ", Binlog ver: ");
2576
pos= strmov(buf, "Server ver: ");
2577
pos= strmov(pos, server_version);
2578
pos= strmov(pos, ", Binlog ver: ");
1951
2579
pos= int10_to_str(binlog_version, pos, 10);
1952
2580
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 */
1957
2637
Start_log_event_v3::Start_log_event_v3()
2297
3005
Since we use (permuted) event id's to index the post_header_len
2298
3006
array, we need to permute the post_header_len array too.
2300
uint8_t post_header_len_temp[23];
3008
uint8 post_header_len_temp[23];
2301
3009
for (int i= 1; i < 23; i++)
2302
3010
post_header_len_temp[perm[i] - 1]= post_header_len[i - 1];
2303
3011
for (int i= 0; i < 22; i++)
2304
3012
post_header_len[i] = post_header_len_temp[i];
3017
#ifndef MYSQL_CLIENT
2309
3018
bool Format_description_log_event::write(IO_CACHE* file)
2312
3021
We don't call Start_log_event_v3::write() because this would make 2
2313
3022
my_b_safe_write().
2315
unsigned char buff[FORMAT_DESCRIPTION_HEADER_LEN];
3024
uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
2316
3025
int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
2317
memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
3026
memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
2318
3027
if (!dont_set_created)
2319
3028
created= when= get_time();
2320
3029
int4store(buff + ST_CREATED_OFFSET,created);
2321
3030
buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN;
2322
memcpy(buff+ST_COMMON_HEADER_LEN_OFFSET+1, post_header_len,
3031
memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (uchar*) post_header_len,
2323
3032
LOG_EVENT_TYPES);
2324
3033
return (write_header(file, sizeof(buff)) ||
2325
3034
my_b_safe_write(file, buff, sizeof(buff)));
3038
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2329
3039
int Format_description_log_event::do_apply_event(Relay_log_info const *rli)
3041
DBUG_ENTER("Format_description_log_event::do_apply_event");
2332
3044
As a transaction NEVER spans on 2 or more binlogs:
2333
3045
if we have an active transaction at this point, the master died
2480
3199
if (need_db && db && db_len)
2482
pos= my_stpcpy(pos, "use `");
3201
pos= strmov(pos, "use `");
2483
3202
memcpy(pos, db, db_len);
2484
pos= my_stpcpy(pos+db_len, "`; ");
3203
pos= strmov(pos+db_len, "`; ");
2487
pos= my_stpcpy(pos, "LOAD DATA ");
3206
pos= strmov(pos, "LOAD DATA ");
2490
3209
*fn_start= pos;
2492
3211
if (check_fname_outside_temp_buf())
2493
pos= my_stpcpy(pos, "LOCAL ");
2494
pos= my_stpcpy(pos, "INFILE '");
3212
pos= strmov(pos, "LOCAL ");
3213
pos= strmov(pos, "INFILE '");
2495
3214
memcpy(pos, fname, fname_len);
2496
pos= my_stpcpy(pos+fname_len, "' ");
3215
pos= strmov(pos+fname_len, "' ");
2498
3217
if (sql_ex.opt_flags & REPLACE_FLAG)
2499
pos= my_stpcpy(pos, " REPLACE ");
3218
pos= strmov(pos, " REPLACE ");
2500
3219
else if (sql_ex.opt_flags & IGNORE_FLAG)
2501
pos= my_stpcpy(pos, " IGNORE ");
3220
pos= strmov(pos, " IGNORE ");
2503
pos= my_stpcpy(pos ,"INTO");
3222
pos= strmov(pos ,"INTO");
2508
pos= my_stpcpy(pos ," Table `");
3227
pos= strmov(pos ," TABLE `");
2509
3228
memcpy(pos, table_name, table_name_len);
2510
3229
pos+= table_name_len;
2512
3231
/* We have to create all optinal fields as the default is not empty */
2513
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3232
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2514
3233
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2515
3234
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2516
pos= my_stpcpy(pos, " OPTIONALLY ");
2517
pos= my_stpcpy(pos, " ENCLOSED BY ");
3235
pos= strmov(pos, " OPTIONALLY ");
3236
pos= strmov(pos, " ENCLOSED BY ");
2518
3237
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2520
pos= my_stpcpy(pos, " ESCAPED BY ");
3239
pos= strmov(pos, " ESCAPED BY ");
2521
3240
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2523
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3242
pos= strmov(pos, " LINES TERMINATED BY ");
2524
3243
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2525
3244
if (sql_ex.line_start_len)
2527
pos= my_stpcpy(pos, " STARTING BY ");
3246
pos= strmov(pos, " STARTING BY ");
2528
3247
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2531
3250
if ((long) skip_lines > 0)
2533
pos= my_stpcpy(pos, " IGNORE ");
2534
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2535
pos= my_stpcpy(pos," LINES ");
3252
pos= strmov(pos, " IGNORE ");
3253
pos= longlong10_to_str((longlong) skip_lines, pos, 10);
3254
pos= strmov(pos," LINES ");
2538
3257
if (num_fields)
2541
3260
const char *field= fields;
2542
pos= my_stpcpy(pos, " (");
3261
pos= strmov(pos, " (");
2543
3262
for (i = 0; i < num_fields; i++)
2624
3346
num_fields(0),fields(0),
2625
3347
field_lens(0),field_block_len(0),
2626
3348
table_name(table_name_arg ? table_name_arg : ""),
2627
db(db_arg), fname(ex->file_name), local_fname(false)
3349
db(db_arg), fname(ex->file_name), local_fname(FALSE)
2629
3351
time_t end_time;
2630
3352
time(&end_time);
2631
3353
exec_time = (ulong) (end_time - thd_arg->start_time);
2632
3354
/* db can never be a zero pointer in 4.0 */
2633
db_len = (uint32_t) strlen(db);
2634
table_name_len = (uint32_t) strlen(table_name);
3355
db_len = (uint32) strlen(db);
3356
table_name_len = (uint32) strlen(table_name);
2635
3357
fname_len = (fname) ? (uint) strlen(fname) : 0;
2636
3358
sql_ex.field_term = (char*) ex->field_term->ptr();
2637
sql_ex.field_term_len = (uint8_t) ex->field_term->length();
3359
sql_ex.field_term_len = (uint8) ex->field_term->length();
2638
3360
sql_ex.enclosed = (char*) ex->enclosed->ptr();
2639
sql_ex.enclosed_len = (uint8_t) ex->enclosed->length();
3361
sql_ex.enclosed_len = (uint8) ex->enclosed->length();
2640
3362
sql_ex.line_term = (char*) ex->line_term->ptr();
2641
sql_ex.line_term_len = (uint8_t) ex->line_term->length();
3363
sql_ex.line_term_len = (uint8) ex->line_term->length();
2642
3364
sql_ex.line_start = (char*) ex->line_start->ptr();
2643
sql_ex.line_start_len = (uint8_t) ex->line_start->length();
3365
sql_ex.line_start_len = (uint8) ex->line_start->length();
2644
3366
sql_ex.escaped = (char*) ex->escaped->ptr();
2645
sql_ex.escaped_len = (uint8_t) ex->escaped->length();
3367
sql_ex.escaped_len = (uint8) ex->escaped->length();
2646
3368
sql_ex.opt_flags = 0;
2647
3369
sql_ex.cached_new_format = -1;
2765
3490
fname_len = strlen(fname);
2766
3491
// 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
2773
3603
Load_log_event::set_fields()
3974
#ifndef MYSQL_CLIENT
3113
3975
Rotate_log_event::Rotate_log_event(const char* new_log_ident_arg,
3114
uint32_t ident_len_arg, uint64_t pos_arg,
3976
uint ident_len_arg, ulonglong pos_arg,
3116
3978
:Log_event(), new_log_ident(new_log_ident_arg),
3117
3979
pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3118
3980
(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));
3120
3988
if (flags & DUP_NAME)
3121
3989
new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3126
Rotate_log_event::Rotate_log_event(const char* buf, uint32_t event_len,
3995
Rotate_log_event::Rotate_log_event(const char* buf, uint event_len,
3127
3996
const Format_description_log_event* description_event)
3128
3997
:Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3999
DBUG_ENTER("Rotate_log_event::Rotate_log_event(char*,...)");
3130
4000
// The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
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;
4001
uint8 header_size= description_event->common_header_len;
4002
uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3134
4004
if (event_len < header_size)
3136
4006
buf += header_size;
3137
4007
pos = post_header_len ? uint8korr(buf + R_POS_OFFSET) : 4;
3138
4008
ident_len = (uint)(event_len -
3287
4186
Intvar_log_event::write()
4189
#ifndef MYSQL_CLIENT
3290
4190
bool Intvar_log_event::write(IO_CACHE* file)
3292
unsigned char buf[9];
3293
buf[I_TYPE_OFFSET]= (unsigned char) type;
4193
buf[I_TYPE_OFFSET]= (uchar) type;
3294
4194
int8store(buf + I_VAL_OFFSET, val);
3295
4195
return (write_header(file, sizeof(buf)) ||
3296
4196
my_b_safe_write(file, buf, sizeof(buf)));
3301
4202
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);
3305
4239
Intvar_log_event::do_apply_event()
4242
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3308
4243
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
3445
4410
:Log_event(buf, description_event)
3447
4412
buf+= description_event->common_header_len;
3448
memcpy(&xid, buf, sizeof(xid));
4413
memcpy((char*) &xid, buf, sizeof(xid));
4417
#ifndef MYSQL_CLIENT
3452
4418
bool Xid_log_event::write(IO_CACHE* file)
4420
DBUG_EXECUTE_IF("do_not_write_xid", return 0;);
3454
4421
return write_header(file, sizeof(xid)) ||
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)))
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 */");
3461
4452
return end_trans(thd, COMMIT);
3464
4455
Log_event::enum_skip_reason
3465
4456
Xid_log_event::do_shall_skip(Relay_log_info *rli)
4458
DBUG_ENTER("Xid_log_event::do_shall_skip");
3467
4459
if (rli->slave_skip_counter > 0) {
3468
4460
thd->options&= ~OPTION_BEGIN;
3469
return(Log_event::EVENT_SKIP_COUNT);
4461
DBUG_RETURN(Log_event::EVENT_SKIP_COUNT);
3471
return(Log_event::do_shall_skip(rli));
4463
DBUG_RETURN(Log_event::do_shall_skip(rli));
4465
#endif /* !MYSQL_CLIENT */
3475
4468
/**************************************************************************
3476
4469
User_var_log_event methods
3477
4470
**************************************************************************/
4472
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3479
4473
void User_var_log_event::pack_info(Protocol* protocol)
3482
uint32_t val_offset= 4 + name_len;
3483
uint32_t event_len= val_offset;
4476
uint val_offset= 4 + name_len;
4477
uint event_len= val_offset;
3487
4481
if (!(buf= (char*) my_malloc(val_offset + 5, MYF(MY_WME))))
3489
my_stpcpy(buf + val_offset, "NULL");
4483
strmov(buf + val_offset, "NULL");
3490
4484
event_len= val_offset + 4;
3638
4634
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3640
4636
return (write_header(file, event_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) ||
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) ||
3644
4640
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);
3650
4753
User_var_log_event::do_apply_event()
4756
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3653
4757
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3656
const CHARSET_INFO *charset;
4760
CHARSET_INFO *charset;
3657
4761
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3659
4763
LEX_STRING user_var_name;
3660
4764
user_var_name.str= name;
3661
4765
user_var_name.length= name_len;
3662
4766
double real_val;
3666
4770
We are now in a statement until the associated query log event has
3741
4845
return continue_group(rli);
4847
#endif /* !MYSQL_CLIENT */
3745
4850
/**************************************************************************
3746
4851
Slave_log_event methods
3747
4852
**************************************************************************/
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
3749
4868
void Slave_log_event::pack_info(Protocol *protocol)
3751
4870
char buf[256+HOSTNAME_LENGTH], *pos;
3752
pos= my_stpcpy(buf, "host=");
3753
pos= my_stpncpy(pos, master_host.c_str(), HOSTNAME_LENGTH);
3754
pos= my_stpcpy(pos, ",port=");
4871
pos= strmov(buf, "host=");
4872
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4873
pos= strmov(pos, ",port=");
3755
4874
pos= int10_to_str((long) master_port, 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);
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);
3760
4879
protocol->store(buf, pos-buf, &my_charset_bin);
4881
#endif /* !MYSQL_CLIENT */
4884
#ifndef MYSQL_CLIENT
3766
4887
re-write this better without holding both locks at the same time
3769
4890
Relay_log_info* rli)
3770
4891
:Log_event(thd_arg, 0, 0) , mem_pool(0), master_host(0)
4893
DBUG_ENTER("Slave_log_event");
3772
4894
if (!rli->inited) // QQ When can this happen ?
3775
4897
Master_info* mi = rli->mi;
3776
4898
// TODO: re-write this better without holding both locks at the same time
3777
4899
pthread_mutex_lock(&mi->data_lock);
3778
4900
pthread_mutex_lock(&rli->data_lock);
4901
master_host_len = strlen(mi->host);
4902
master_log_len = strlen(rli->group_master_log_name);
3779
4903
// on OOM, just do not initialize the structure and print the error
3780
4904
if ((mem_pool = (char*)my_malloc(get_data_size() + 1,
3783
master_host.assign(mi->getHostname());
3784
master_log.assign(rli->group_master_log_name);
3785
master_port = mi->getPort();
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;
3786
4912
master_pos = rli->group_master_log_pos;
4913
DBUG_PRINT("info", ("master_log: %s pos: %lu", master_log,
4914
(ulong) master_pos));
3789
sql_print_error(_("Out of memory while recording slave event"));
4917
sql_print_error("Out of memory while recording slave event");
3790
4918
pthread_mutex_unlock(&rli->data_lock);
3791
4919
pthread_mutex_unlock(&mi->data_lock);
4922
#endif /* !MYSQL_CLIENT */
3796
4925
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 */
3802
4947
int Slave_log_event::get_data_size()
3804
return master_host.length() + master_log.length() + 1 + SL_MASTER_HOST_OFFSET;
4949
return master_host_len + master_log_len + 1 + SL_MASTER_HOST_OFFSET;
4953
#ifndef MYSQL_CLIENT
3808
4954
bool Slave_log_event::write(IO_CACHE* file)
3810
4956
ulong event_length= get_data_size();
3813
4959
// log and host are already there
3815
4961
return (write_header(file, event_length) ||
3816
my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
4962
my_b_safe_write(file, (uchar*) mem_pool, event_length));
3820
void Slave_log_event::init_from_mem_pool()
4967
void Slave_log_event::init_from_mem_pool(int data_size)
3822
4969
master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET);
3823
4970
master_port = uint2korr(mem_pool + SL_MASTER_PORT_OFFSET);
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)))
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)
3834
5002
if (mysql_bin_log.is_open())
3835
5003
mysql_bin_log.write(this);
5006
#endif /* !MYSQL_CLIENT */
3840
5009
/**************************************************************************
3988
5185
sql_ex.force_new_format();
3989
5186
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 */
3996
5232
Create_file_log_event::pack_info()
5235
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3999
5236
void Create_file_log_event::pack_info(Protocol *protocol)
4001
5238
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4002
pos= my_stpcpy(buf, "db=");
5239
pos= strmov(buf, "db=");
4003
5240
memcpy(pos, db, db_len);
4004
pos= my_stpcpy(pos + db_len, ";table=");
5241
pos= strmov(pos + db_len, ";table=");
4005
5242
memcpy(pos, table_name, table_name_len);
4006
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5243
pos= strmov(pos + table_name_len, ";file_id=");
4007
5244
pos= int10_to_str((long) file_id, pos, 10);
4008
pos= my_stpcpy(pos, ";block_len=");
5245
pos= strmov(pos, ";block_len=");
4009
5246
pos= int10_to_str((long) block_len, pos, 10);
4010
5247
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5249
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4015
5253
Create_file_log_event::do_apply_event()
5256
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4018
5257
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4020
5259
char proc_info[17+FN_REFLEN+10], *fname_buf;
4026
memset(&file, 0, sizeof(file));
4027
fname_buf= my_stpcpy(proc_info, "Making temp file ");
5265
bzero((char*)&file, sizeof(file));
5266
fname_buf= strmov(proc_info, "Making temp file ");
4028
5267
ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4029
thd->set_proc_info(proc_info);
5268
thd_proc_info(thd, proc_info);
4030
5269
my_delete(fname_buf, MYF(0)); // old copy may exist already
4031
5270
if ((fd= my_create(fname_buf, CREATE_MODE,
5271
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4033
5272
MYF(MY_WME))) < 0 ||
4034
5273
init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0,
4035
5274
MYF(MY_WME|MY_NABP)))
4037
5276
rli->report(ERROR_LEVEL, my_errno,
4038
_("Error in Create_file event: could not open file '%s'"),
5277
"Error in Create_file event: could not open file '%s'",
4043
5282
// a trick to avoid allocating another buffer
4044
5283
fname= fname_buf;
4045
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5284
fname_len= (uint) (strmov(ext, ".data") - fname);
4046
5285
if (write_base(&file))
4048
my_stpcpy(ext, ".info"); // to have it right in the error message
5287
strmov(ext, ".info"); // to have it right in the error message
4049
5288
rli->report(ERROR_LEVEL, my_errno,
4050
_("Error in Create_file event: could not write to file '%s'"),
5289
"Error in Create_file event: could not write to file '%s'",
4054
5293
end_io_cache(&file);
4055
5294
my_close(fd, MYF(0));
4057
5296
// fname_buf now already has .data, not .info, because we did our trick
4058
5297
my_delete(fname_buf, MYF(0)); // old copy may exist already
4059
5298
if ((fd= my_create(fname_buf, CREATE_MODE,
5299
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4063
5302
rli->report(ERROR_LEVEL, my_errno,
4064
_("Error in Create_file event: could not open file '%s'"),
5303
"Error in Create_file event: could not open file '%s'",
4068
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5307
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4070
5309
rli->report(ERROR_LEVEL, my_errno,
4071
_("Error in Create_file event: write to '%s' failed"),
5310
"Error in Create_file event: write to '%s' failed",
4092
5332
Append_block_log_event ctor
5335
#ifndef MYSQL_CLIENT
4095
5336
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4096
5337
const char *db_arg,
4097
unsigned char *block_arg,
4098
uint32_t block_len_arg,
4099
5340
bool using_trans)
4100
5341
:Log_event(thd_arg,0, using_trans), block(block_arg),
4101
5342
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4107
5349
Append_block_log_event ctor
4110
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5352
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4111
5353
const Format_description_log_event* description_event)
4112
5354
:Log_event(buf, description_event),block(0)
4114
uint8_t common_header_len= description_event->common_header_len;
4115
uint8_t append_block_header_len=
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=
4116
5359
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4117
uint32_t total_header_len= common_header_len+append_block_header_len;
5360
uint total_header_len= common_header_len+append_block_header_len;
4118
5361
if (len < total_header_len)
4120
5363
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4121
block= (unsigned char*)buf + total_header_len;
5364
block= (uchar*)buf + total_header_len;
4122
5365
block_len= len - total_header_len;
4128
5371
Append_block_log_event::write()
5374
#ifndef MYSQL_CLIENT
4131
5375
bool Append_block_log_event::write(IO_CACHE* file)
4133
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5377
uchar buf[APPEND_BLOCK_HEADER_LEN];
4134
5378
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4135
5379
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4136
5380
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4137
my_b_safe_write(file, (unsigned char*) block, block_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 */
4142
5406
Append_block_log_event::pack_info()
5409
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4145
5410
void Append_block_log_event::pack_info(Protocol *protocol)
4149
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
5414
length= (uint) my_sprintf(buf,
5415
(buf, ";file_id=%u;block_len=%u", file_id,
4151
5417
protocol->store(buf, length, &my_charset_bin);
4170
5436
char proc_info[17+FN_REFLEN+10], *fname= proc_info+17;
5439
DBUG_ENTER("Append_block_log_event::do_apply_event");
4174
fname= my_stpcpy(proc_info, "Making temp file ");
5441
fname= strmov(proc_info, "Making temp file ");
4175
5442
slave_load_file_stem(fname, file_id, server_id, ".data");
4176
thd->set_proc_info(proc_info);
5443
thd_proc_info(thd, proc_info);
4177
5444
if (get_create_or_append())
4179
5446
my_delete(fname, MYF(0)); // old copy may exist already
4180
5447
if ((fd= my_create(fname, CREATE_MODE,
5448
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4182
5449
MYF(MY_WME))) < 0)
4184
5451
rli->report(ERROR_LEVEL, my_errno,
4185
_("Error in %s event: could not create file '%s'"),
5452
"Error in %s event: could not create file '%s'",
4186
5453
get_type_str(), fname);
4190
else if ((fd = my_open(fname, O_WRONLY | O_APPEND,
5457
else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW,
4191
5458
MYF(MY_WME))) < 0)
4193
5460
rli->report(ERROR_LEVEL, my_errno,
4194
_("Error in %s event: could not open file '%s'"),
5461
"Error in %s event: could not open file '%s'",
4195
5462
get_type_str(), fname);
4198
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5465
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4200
5467
rli->report(ERROR_LEVEL, my_errno,
4201
_("Error in %s event: write to '%s' failed"),
5468
"Error in %s event: write to '%s' failed",
4202
5469
get_type_str(), fname);
4246
5516
Delete_file_log_event::write()
5519
#ifndef MYSQL_CLIENT
4249
5520
bool Delete_file_log_event::write(IO_CACHE* file)
4251
unsigned char buf[DELETE_FILE_HEADER_LEN];
5522
uchar buf[DELETE_FILE_HEADER_LEN];
4252
5523
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4253
5524
return (write_header(file, sizeof(buf)) ||
4254
5525
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 */
4259
5548
Delete_file_log_event::pack_info()
5551
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4262
5552
void Delete_file_log_event::pack_info(Protocol *protocol)
4266
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4267
protocol->store(buf, (int32_t) length, &my_charset_bin);
5556
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5557
protocol->store(buf, (int32) length, &my_charset_bin);
4271
5562
Delete_file_log_event::do_apply_event()
4274
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5565
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5566
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli)
4276
5568
char fname[FN_REFLEN+10];
4277
5569
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4278
5570
(void) my_delete(fname, MYF(MY_WME));
4279
my_stpcpy(ext, ".info");
5571
strmov(ext, ".info");
4280
5572
(void) my_delete(fname, MYF(MY_WME));
5575
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4285
5578
/**************************************************************************
4318
5613
Execute_load_log_event::write()
5616
#ifndef MYSQL_CLIENT
4321
5617
bool Execute_load_log_event::write(IO_CACHE* file)
4323
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5619
uchar buf[EXEC_LOAD_HEADER_LEN];
4324
5620
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4325
5621
return (write_header(file, sizeof(buf)) ||
4326
5622
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",
4331
5646
Execute_load_log_event::pack_info()
5649
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4334
5650
void Execute_load_log_event::pack_info(Protocol *protocol)
4338
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4339
protocol->store(buf, (int32_t) length, &my_charset_bin);
5654
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5655
protocol->store(buf, (int32) length, &my_charset_bin);
5747
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4435
5750
/**************************************************************************
4436
5751
Begin_load_query_log_event methods
4437
5752
**************************************************************************/
5754
#ifndef MYSQL_CLIENT
4439
5755
Begin_load_query_log_event::
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)
5756
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5757
uint block_len_arg, bool using_trans)
4442
5758
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4445
5761
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4449
5766
Begin_load_query_log_event::
4450
Begin_load_query_log_event(const char* buf, uint32_t len,
5767
Begin_load_query_log_event(const char* buf, uint len,
4451
5768
const Format_description_log_event* desc_event)
4452
5769
:Append_block_log_event(buf, len, desc_event)
5774
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4457
5775
int Begin_load_query_log_event::get_create_or_append() const
4459
5777
return 1; /* create the file */
5779
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5782
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4463
5783
Log_event::enum_skip_reason
4464
5784
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5846
#ifndef MYSQL_CLIENT
4524
5848
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4526
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5850
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4527
5851
int4store(buf, file_id);
4528
5852
int4store(buf + 4, fn_pos_start);
4529
5853
int4store(buf + 4 + 4, fn_pos_end);
4530
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5854
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4531
5855
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)
4535
5903
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4537
5905
char *buf, *pos;
4781
6166
m_flags= uint2korr(post_start);
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;
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));
4787
6173
m_width = net_field_length(&ptr_after_width);
6174
DBUG_PRINT("debug", ("m_width=%lu", m_width));
4788
6175
/* if bitmap_init fails, catched in is_valid() */
4789
6176
if (likely(!bitmap_init(&m_cols,
4790
6177
m_width <= sizeof(m_bitbuf)*8 ? m_bitbuf : NULL,
6181
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
4794
6182
memcpy(m_cols.bitmap, ptr_after_width, (m_width + 7) / 8);
4795
6183
create_last_word_mask(&m_cols);
4796
6184
ptr_after_width+= (m_width + 7) / 8;
6185
DBUG_DUMP("m_cols", (uchar*) m_cols.bitmap, no_bytes_in_map(&m_cols));
4800
6189
// Needed because bitmap_init() does not set it to null on failure
4801
6190
m_cols.bitmap= NULL;
4805
6194
m_cols_ai.bitmap= m_cols.bitmap; /* See explanation in is_valid() */
4807
6196
if (event_type == UPDATE_ROWS_EVENT)
6198
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
4809
6200
/* if bitmap_init fails, caught in is_valid() */
4810
6201
if (likely(!bitmap_init(&m_cols_ai,
4811
6202
m_width <= sizeof(m_bitbuf_ai)*8 ? m_bitbuf_ai : NULL,
6206
DBUG_PRINT("debug", ("Reading from %p", ptr_after_width));
4815
6207
memcpy(m_cols_ai.bitmap, ptr_after_width, (m_width + 7) / 8);
4816
6208
create_last_word_mask(&m_cols_ai);
4817
6209
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));
4821
6215
// Needed because bitmap_init() does not set it to null on failure
4822
6216
m_cols_ai.bitmap= 0;
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));
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));
4832
6228
if (likely((bool)m_rows_buf))
6230
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4834
6231
m_curr_row= m_rows_buf;
4835
6233
m_rows_end= m_rows_buf + data_size;
4836
6234
m_rows_cur= m_rows_end;
4837
6235
memcpy(m_rows_buf, ptr_rows_data, data_size);
5434
6874
Note that this should be the number of *bits*, not the number of
5437
unsigned char sbuf[sizeof(m_width)];
6877
uchar sbuf[sizeof(m_width)];
5438
6878
my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf;
5439
6879
bool res= false;
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));
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));
6883
DBUG_DUMP("m_width", sbuf, (size_t) (sbuf_end - sbuf));
5443
6884
res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
5445
res= res || my_b_safe_write(file, (unsigned char*) m_cols.bitmap,
6886
DBUG_PRINT_BITSET("debug", "writing cols: %s", &m_cols);
6887
res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
5446
6888
no_bytes_in_map(&m_cols));
5448
6890
TODO[refactor write]: Remove the "down cast" here (and elsewhere).
5450
6892
if (get_type_code() == UPDATE_ROWS_EVENT)
5452
res= res || my_b_safe_write(file, (unsigned char*) m_cols_ai.bitmap,
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,
5453
6897
no_bytes_in_map(&m_cols_ai));
6899
DBUG_DUMP("rows", m_rows_buf, data_size);
5455
6900
res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
6907
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5462
6908
void Rows_log_event::pack_info(Protocol *protocol)
5465
6911
char const *const flagstr=
5466
6912
get_flags(STMT_END_F) ? " flags: STMT_END_F" : "";
5467
size_t bytes= snprintf(buf, sizeof(buf),
5468
"table_id: %lu%s", m_table_id, flagstr);
6913
size_t bytes= my_snprintf(buf, sizeof(buf),
6914
"table_id: %lu%s", m_table_id, flagstr);
5469
6915
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);
5473
6944
/**************************************************************************
5474
6945
Table_map_log_event member functions and support functions
5670
7159
const char *const vpart= buf + common_header_len + post_header_len;
5672
7161
/* Extract the length of the various parts from the buffer */
5673
unsigned char const *const ptr_dblen= (unsigned char const*)vpart + 0;
5674
m_dblen= *(unsigned char*) ptr_dblen;
7162
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
7163
m_dblen= *(uchar*) ptr_dblen;
5676
7165
/* Length of database name + counter + terminating null */
5677
unsigned char const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
5678
m_tbllen= *(unsigned char*) ptr_tbllen;
7166
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
7167
m_tbllen= *(uchar*) ptr_tbllen;
5680
7169
/* Length of table name + counter + terminating null */
5681
unsigned char const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
5682
unsigned char *ptr_after_colcnt= (unsigned char*) ptr_colcnt;
7170
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
7171
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5683
7172
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)));
5685
7179
/* Allocate mem for all fields in one go. If fails, caught in is_valid() */
5686
m_memory= (unsigned char*) my_multi_malloc(MYF(MY_WME),
7180
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5687
7181
&m_dbnam, (uint) m_dblen + 1,
5688
7182
&m_tblnam, (uint) m_tbllen + 1,
5689
7183
&m_coltype, (uint) m_colcnt,
5697
7191
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5699
7193
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5700
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
7194
bytes_read= ptr_after_colcnt - (uchar *)buf;
7195
DBUG_PRINT("info", ("Bytes read: %d.\n", bytes_read));
5701
7196
if (bytes_read < event_len)
5703
7198
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
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),
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),
5707
7202
&m_null_bits, num_null_bytes,
5708
7203
&m_field_metadata, m_field_metadata_size,
5710
7205
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5711
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
7206
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5712
7207
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5719
7215
Table_map_log_event::~Table_map_log_event()
5721
free(m_meta_memory);
7217
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
7218
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5747
7245
pthread_mutex_unlock(&LOCK_thread_count);
5749
7247
if (!(memory= my_multi_malloc(MYF(MY_WME),
5750
&table_list, (uint) sizeof(RPL_TableList),
7248
&table_list, (uint) sizeof(RPL_TABLE_LIST),
5751
7249
&db_mem, (uint) NAME_LEN + 1,
5752
7250
&tname_mem, (uint) NAME_LEN + 1,
5754
return(HA_ERR_OUT_OF_MEM);
7252
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
5756
memset(table_list, 0, sizeof(*table_list));
7254
bzero(table_list, sizeof(*table_list));
5757
7255
table_list->db = db_mem;
5758
7256
table_list->alias= table_list->table_name = tname_mem;
5759
7257
table_list->lock_type= TL_WRITE;
5760
7258
table_list->next_global= table_list->next_local= 0;
5761
7259
table_list->table_id= m_table_id;
5762
7260
table_list->updating= 1;
5763
my_stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
5764
my_stpcpy(table_list->table_name, m_tblnam);
7261
strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
7262
strmov(table_list->table_name, m_tblnam);
5768
7266
if (!rpl_filter->db_ok(table_list->db) ||
5769
7267
(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
5889
7388
bool Table_map_log_event::write_data_header(IO_CACHE *file)
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);
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);
5894
7399
int2store(buf + TM_FLAGS_OFFSET, m_flags);
5895
7400
return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
5898
7403
bool Table_map_log_event::write_data_body(IO_CACHE *file)
5900
assert(m_dbnam != NULL);
5901
assert(m_tblnam != NULL);
7405
DBUG_ASSERT(m_dbnam != NULL);
7406
DBUG_ASSERT(m_tblnam != NULL);
5902
7407
/* We use only one byte per length for storage in event: */
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));
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));
5914
7419
Store the size of the field metadata.
5916
unsigned char mbuf[sizeof(m_field_metadata_size)];
5917
unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
7421
uchar mbuf[sizeof(m_field_metadata_size)];
7422
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
5919
7424
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
5920
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7425
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
5921
7426
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
5922
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7427
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
5923
7428
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
5924
7429
my_b_safe_write(file, m_coltype, m_colcnt) ||
5925
7430
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
5926
7431
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
5927
7432
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7436
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5932
7439
Print some useful information for the SHOW BINARY LOG information
7443
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5936
7444
void Table_map_log_event::pack_info(Protocol *protocol)
5939
size_t bytes= snprintf(buf, sizeof(buf),
5940
"table_id: %lu (%s.%s)",
5941
m_table_id, m_dbnam, m_tblnam);
7447
size_t bytes= my_snprintf(buf, sizeof(buf),
7448
"table_id: %lu (%s.%s)",
7449
m_table_id, m_dbnam, m_tblnam);
5942
7450
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);
5946
7472
/**************************************************************************
5947
7473
Write_rows_log_event member functions
6262
7816
if (last_uniq_key(table, keynum) &&
6263
7817
!table->file->referenced_by_foreign_key())
7819
DBUG_PRINT("info",("Updating row using ha_update_row()"));
6265
7820
error=table->file->ha_update_row(table->record[1],
6266
7821
table->record[0]);
6267
7822
switch (error) {
6269
7824
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));
6276
7834
table->file->print_error(error, MYF(0));
7841
DBUG_PRINT("info",("Deleting offending row and trying to write new one again"));
6283
7842
if ((error= table->file->ha_delete_row(table->record[1])))
7844
DBUG_PRINT("info",("ha_delete_row() returns error %d",error));
6285
7845
table->file->print_error(error, MYF(0));
6288
7848
/* Will retry ha_write_row() with the offending row removed. */
6297
7858
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
6299
assert(m_table != NULL);
7860
DBUG_ASSERT(m_table != NULL);
6301
7862
write_row(rli, /* if 1 then overwrite */
6302
7863
bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1);
6304
7865
if (error && !thd->is_error())
6307
7868
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");
6314
7883
/**************************************************************************
6315
7884
Delete_rows_log_event member functions
6316
7885
**************************************************************************/
7887
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6319
7889
Compares table->record[0] and table->record[1]
6321
7891
Returns TRUE if different.
6323
static bool record_compare(Table *table)
7893
static bool record_compare(TABLE *table)
6326
7896
Need to set the X bit and the filler bits in both records since
6598
8211
Note: above record_compare will take into accout all record fields
6599
8212
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);
6601
8226
table->file->ha_rnd_end();
6603
assert(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
8228
DBUG_ASSERT(error == HA_ERR_END_OF_FILE || error == HA_ERR_RECORD_DELETED || error == 0);
6607
8232
table->default_column_bitmaps();
6610
8235
table->default_column_bitmaps();
6616
8242
Constructor used to build an event for writing to the binary log.
6619
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, Table *tbl_arg,
8245
#ifndef MYSQL_CLIENT
8246
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, TABLE *tbl_arg,
6621
8248
bool is_transactional)
6622
8249
: Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
8252
#endif /* #if !defined(MYSQL_CLIENT) */
6627
8255
Constructor used by slave to read the event from the binary log.
6629
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint32_t event_len,
8257
#ifdef HAVE_REPLICATION
8258
Delete_rows_log_event::Delete_rows_log_event(const char *buf, uint event_len,
6630
8259
const Format_description_log_event
6631
8260
*description_event)
6632
8261
: Rows_log_event(buf, event_len, DELETE_ROWS_EVENT, description_event)
8266
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
6638
8269
Delete_rows_log_event::do_before_row_operations(const Slave_reporting_capability *const)
6819
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
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,
6820
8485
const Format_description_log_event *descr_event)
6821
8486
: Log_event(buf, descr_event)
6823
uint8_t const common_header_len=
8488
DBUG_ENTER("Incident_log_event::Incident_log_event");
8489
uint8 const common_header_len=
6824
8490
descr_event->common_header_len;
6825
uint8_t const post_header_len=
8491
uint8 const post_header_len=
6826
8492
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));
6828
8497
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
6829
8498
char const *ptr= buf + common_header_len + post_header_len;
6830
8499
char const *const str_end= buf + event_len;
6831
uint8_t len= 0; // Assignment to keep compiler happy
8500
uint8 len= 0; // Assignment to keep compiler happy
6832
8501
const char *str= NULL; // Assignment to keep compiler happy
6833
8502
read_str(&ptr, str_end, &str, &len);
6834
8503
m_message.str= const_cast<char*>(str);
6835
8504
m_message.length= len;
8505
DBUG_PRINT("info", ("m_incident: %d", m_incident));
6853
assert(0 <= m_incident);
6854
assert((size_t) m_incident <= sizeof(description)/sizeof(*description));
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));
6856
8528
return description[m_incident];
8532
#ifndef MYSQL_CLIENT
6860
8533
void Incident_log_event::pack_info(Protocol *protocol)
6864
8537
if (m_message.length > 0)
6865
bytes= snprintf(buf, sizeof(buf), "#%d (%s)",
6866
m_incident, description());
8538
bytes= my_snprintf(buf, sizeof(buf), "#%d (%s)",
8539
m_incident, description());
6868
bytes= snprintf(buf, sizeof(buf), "#%d (%s): %s",
6869
m_incident, description(), m_message.str);
8541
bytes= my_snprintf(buf, sizeof(buf), "#%d (%s): %s",
8542
m_incident, description(), m_message.str);
6870
8543
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)
6875
8564
Incident_log_event::do_apply_event(Relay_log_info const *rli)
8566
DBUG_ENTER("Incident_log_event::do_apply_event");
6877
8567
rli->report(ERROR_LEVEL, ER_SLAVE_INCIDENT,
6878
8568
ER(ER_SLAVE_INCIDENT),
6880
8570
m_message.length > 0 ? m_message.str : "<none>");
6886
8576
Incident_log_event::write_data_header(IO_CACHE *file)
6888
unsigned char buf[sizeof(int16_t)];
6889
int2store(buf, (int16_t) m_incident);
6890
return(my_b_safe_write(file, buf, sizeof(buf)));
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)));
6894
8586
Incident_log_event::write_data_body(IO_CACHE *file)
6896
return(write_str(file, m_message.str, m_message.length));
8588
DBUG_ENTER("Incident_log_event::write_data_body");
8589
DBUG_RETURN(write_str(file, m_message.str, m_message.length));
6899
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
8592
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8593
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6900
8594
const Format_description_log_event* description_event)
6901
8595
:Log_event(buf, description_event)
6903
uint8_t header_size= description_event->common_header_len;
8597
uint8 header_size= description_event->common_header_len;
6904
8598
ident_len = event_len - header_size;
6905
8599
set_if_smaller(ident_len,FN_REFLEN-1);
6906
8600
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);