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
142
len= snprintf(slider, buff_end - slider,
135
_(" %s, Error_code: %d;"), err->msg, err->code);
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
1058
1152
if (!ev || !ev->is_valid())
1156
if (!force_opt) /* then mysqlbinlog dies */
1158
*error= "Found invalid event in binary log";
1161
ev= new Unknown_log_event(buf, description_event);
1061
1163
*error= "Found invalid event in binary log";
1173
Log_event::print_header()
1176
void Log_event::print_header(IO_CACHE* file,
1177
PRINT_EVENT_INFO* print_event_info,
1178
bool is_more __attribute__((unused)))
1181
my_off_t hexdump_from= print_event_info->hexdump_from;
1183
my_b_printf(file, "#");
1184
print_timestamp(file);
1185
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1186
llstr(log_pos,llbuff));
1188
/* mysqlbinlog --hexdump */
1189
if (print_event_info->hexdump_from)
1191
my_b_printf(file, "\n");
1192
uchar *ptr= (uchar*)temp_buf;
1194
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1197
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1198
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1199
char *c, char_string[16+1]= {0};
1201
/* Pretty-print event common header if header is exactly 19 bytes */
1202
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1204
char emit_buf[256]; // Enough for storing one line
1205
my_b_printf(file, "# Position Timestamp Type Master ID "
1206
"Size Master Pos Flags \n");
1207
int const bytes_written=
1208
snprintf(emit_buf, sizeof(emit_buf),
1209
"# %8.8lx %02x %02x %02x %02x %02x "
1210
"%02x %02x %02x %02x %02x %02x %02x %02x "
1211
"%02x %02x %02x %02x %02x %02x\n",
1212
(unsigned long) hexdump_from,
1213
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1214
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1215
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1216
assert(bytes_written >= 0);
1217
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1218
my_b_write(file, (uchar*) emit_buf, bytes_written);
1219
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1220
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1223
/* Rest of event (without common header) */
1224
for (i= 0, c= char_string, h=hex_string;
1228
snprintf(h, 4, "%02x ", *ptr);
1231
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1236
my_b_printf() does not support full printf() formats, so we
1237
have to do it this way.
1239
TODO: Rewrite my_b_printf() to support full printf() syntax.
1242
int const bytes_written=
1243
snprintf(emit_buf, sizeof(emit_buf),
1244
"# %8.8lx %-48.48s |%16s|\n",
1245
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1246
hex_string, char_string);
1247
assert(bytes_written >= 0);
1248
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1249
my_b_write(file, (uchar*) emit_buf, bytes_written);
1255
else if (i % 8 == 7) *h++ = ' ';
1262
int const bytes_written=
1263
snprintf(emit_buf, sizeof(emit_buf),
1264
"# %8.8lx %-48.48s |%s|\n",
1265
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1266
hex_string, char_string);
1267
assert(bytes_written >= 0);
1268
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1269
my_b_write(file, (uchar*) emit_buf, bytes_written);
1272
need a # to prefix the rest of printouts for example those of
1273
Rows_log_event::print_helper().
1275
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1281
void Log_event::print_base64(IO_CACHE* file,
1282
PRINT_EVENT_INFO* print_event_info,
1285
const uchar *ptr= (const uchar *)temp_buf;
1286
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
1288
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1289
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1291
fprintf(stderr, "\nError: Out of memory. "
1292
"Could not print correct binlog event.\n");
1296
if (base64_encode(ptr, (size_t) size, tmp_str))
1301
if (my_b_tell(file) == 0)
1302
my_b_printf(file, "\nBINLOG '\n");
1304
my_b_printf(file, "%s\n", tmp_str);
1307
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1309
my_free(tmp_str, MYF(0));
1315
Log_event::print_timestamp()
1318
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1323
#ifdef MYSQL_SERVER // This is always false
1325
localtime_r(ts,(res= &tm_tmp));
1330
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1340
#endif /* MYSQL_CLIENT */
1343
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1067
1344
inline Log_event::enum_skip_reason
1068
1345
Log_event::continue_group(Relay_log_info *rli)
1482
1784
This is used by the SQL slave thread to prepare the event before execution.
1484
Query_log_event::Query_log_event(const char* buf, uint32_t event_len,
1786
Query_log_event::Query_log_event(const char* buf, uint event_len,
1485
1787
const Format_description_log_event
1486
1788
*description_event,
1487
1789
Log_event_type event_type)
1488
:Log_event(buf, description_event), data_buf(0), query(NULL),
1489
db(NULL), catalog_len(0), status_vars_len(0),
1790
:Log_event(buf, description_event), data_buf(0), query(NullS),
1791
db(NullS), catalog_len(0), status_vars_len(0),
1490
1792
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1491
1793
auto_increment_increment(1), auto_increment_offset(1),
1492
1794
time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1496
uint8_t common_header_len, post_header_len;
1798
uint8 common_header_len, post_header_len;
1497
1799
Log_event::Byte *start;
1498
1800
const Log_event::Byte *end;
1499
1801
bool catalog_nz= 1;
1969
Query_log_event::print().
1972
print the catalog ??
1974
void Query_log_event::print_query_header(IO_CACHE* file,
1975
PRINT_EVENT_INFO* print_event_info)
1977
// TODO: print the catalog ??
1978
char buff[40],*end; // Enough for SET TIMESTAMP
1979
bool different_db= 1;
1982
if (!print_event_info->short_form)
1984
print_header(file, print_event_info, false);
1985
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
1986
get_type_str(), (ulong) thread_id, (ulong) exec_time,
1990
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
1992
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
1993
memcpy(print_event_info->db, db, db_len + 1);
1994
if (db[0] && different_db)
1995
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1998
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
1999
end= strmov(end, print_event_info->delimiter);
2001
my_b_write(file, (uchar*) buff, (uint) (end-buff));
2002
if ((!print_event_info->thread_id_printed ||
2003
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
2004
thread_id != print_event_info->thread_id)))
2006
// If --short-form, print deterministic value instead of pseudo_thread_id.
2007
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
2008
short_form ? 999999999 : (ulong)thread_id,
2009
print_event_info->delimiter);
2010
print_event_info->thread_id= thread_id;
2011
print_event_info->thread_id_printed= 1;
2015
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
2016
print (remember we don't produce mixed relay logs so there cannot be
2017
5.0 events before that one so there is nothing to reset).
2019
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
2021
/* tmp is a bitmask of bits which have changed. */
2022
if (likely(print_event_info->flags2_inited))
2023
/* All bits which have changed */
2024
tmp= (print_event_info->flags2) ^ flags2;
2025
else /* that's the first Query event we read */
2027
print_event_info->flags2_inited= 1;
2028
tmp= ~((uint32)0); /* all bits have changed */
2031
if (unlikely(tmp)) /* some bits have changed */
2034
my_b_printf(file, "SET ");
2035
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2036
"@@session.foreign_key_checks", &need_comma);
2037
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2038
"@@session.sql_auto_is_null", &need_comma);
2039
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2040
"@@session.unique_checks", &need_comma);
2041
my_b_printf(file,"%s\n", print_event_info->delimiter);
2042
print_event_info->flags2= flags2;
2047
Now the session variables;
2048
it's more efficient to pass SQL_MODE as a number instead of a
2049
comma-separated list.
2050
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2051
variables (they have no global version; they're not listed in
2052
sql_class.h), The tests below work for pure binlogs or pure relay
2053
logs. Won't work for mixed relay logs but we don't create mixed
2054
relay logs (that is, there is no relay log with a format change
2055
except within the 3 first events, which mysqlbinlog handles
2056
gracefully). So this code should always be good.
2059
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2060
print_event_info->auto_increment_offset != auto_increment_offset)
2062
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2063
auto_increment_increment,auto_increment_offset,
2064
print_event_info->delimiter);
2065
print_event_info->auto_increment_increment= auto_increment_increment;
2066
print_event_info->auto_increment_offset= auto_increment_offset;
2069
/* TODO: print the catalog when we feature SET CATALOG */
2071
if (likely(charset_inited) &&
2072
(unlikely(!print_event_info->charset_inited ||
2073
bcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
2075
CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2078
/* for mysql client */
2079
my_b_printf(file, "/*!\\C %s */%s\n",
2080
cs_info->csname, print_event_info->delimiter);
2082
my_b_printf(file,"SET "
2083
"@@session.character_set_client=%d,"
2084
"@@session.collation_connection=%d,"
2085
"@@session.collation_server=%d"
2088
uint2korr(charset+2),
2089
uint2korr(charset+4),
2090
print_event_info->delimiter);
2091
memcpy(print_event_info->charset, charset, 6);
2092
print_event_info->charset_inited= 1;
2096
if (bcmp((uchar*) print_event_info->time_zone_str,
2097
(uchar*) time_zone_str, time_zone_len+1))
2099
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2100
time_zone_str, print_event_info->delimiter);
2101
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2104
if (lc_time_names_number != print_event_info->lc_time_names_number)
2106
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2107
lc_time_names_number, print_event_info->delimiter);
2108
print_event_info->lc_time_names_number= lc_time_names_number;
2110
if (charset_database_number != print_event_info->charset_database_number)
2112
if (charset_database_number)
2113
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2114
charset_database_number, print_event_info->delimiter);
2116
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2117
print_event_info->delimiter);
2118
print_event_info->charset_database_number= charset_database_number;
2123
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2125
Write_on_release_cache cache(&print_event_info->head_cache, file);
2127
print_query_header(&cache, print_event_info);
2128
my_b_write(&cache, (uchar*) query, q_len);
2129
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2131
#endif /* MYSQL_CLIENT */
1665
2135
Query_log_event::do_apply_event()
2138
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1667
2140
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1669
2142
return do_apply_event(rli, query, q_len);
1835
2308
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1838
rli->report(ERROR_LEVEL, expected_error,
1839
_("Query partially completed on the master "
1840
"(error on master: %d) and was aborted. There is a "
1841
"chance that your master is inconsistent at this "
1842
"point. If you are sure that your master is ok, run "
1843
"this query manually on the slave and then restart the "
1844
"slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; "
1845
"START SLAVE; . Query: '%s'"),
1846
expected_error, thd->query);
2311
rli->report(ERROR_LEVEL, expected_error,
2313
Query partially completed on the master (error on master: %d) \
2314
and was aborted. There is a chance that your master is inconsistent at this \
2315
point. If you are sure that your master is ok, run this query manually on the \
2316
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
2317
START SLAVE; . Query: '%s'", expected_error, thd->query);
1847
2318
thd->is_slave_error= 1;
2323
/* If the query was not ignored, it is printed to the general log */
2324
if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
2325
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
1852
2327
compare_errors:
1988
2464
return(Log_event::do_shall_skip(rli));
1992
2470
/**************************************************************************
1993
2471
Start_log_event_v3 methods
1994
2472
**************************************************************************/
2474
#ifndef MYSQL_CLIENT
1996
2475
Start_log_event_v3::Start_log_event_v3()
1997
2476
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1998
2477
artificial_event(0), dont_set_created(0)
2000
2479
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
2004
2484
Start_log_event_v3::pack_info()
2487
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
2007
2488
void Start_log_event_v3::pack_info(Protocol *protocol)
2009
2490
char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos;
2010
pos= my_stpcpy(buf, "Server ver: ");
2011
pos= my_stpcpy(pos, server_version);
2012
pos= my_stpcpy(pos, ", Binlog ver: ");
2491
pos= strmov(buf, "Server ver: ");
2492
pos= strmov(pos, server_version);
2493
pos= strmov(pos, ", Binlog ver: ");
2013
2494
pos= int10_to_str(binlog_version, pos, 10);
2014
2495
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2501
Start_log_event_v3::print()
2505
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2507
Write_on_release_cache cache(&print_event_info->head_cache, file,
2508
Write_on_release_cache::FLUSH_F);
2510
if (!print_event_info->short_form)
2512
print_header(&cache, print_event_info, false);
2513
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2514
binlog_version, server_version);
2515
print_timestamp(&cache);
2517
my_b_printf(&cache," at startup");
2518
my_b_printf(&cache, "\n");
2519
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2520
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2521
"Most probably mysqld crashed writing it.\n");
2523
if (!artificial_event && created)
2525
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2527
This is for mysqlbinlog: like in replication, we want to delete the stale
2528
tmp files left by an unclean shutdown of mysqld (temporary tables)
2529
and rollback unfinished transaction.
2530
Probably this can be done with RESET CONNECTION (syntax to be defined).
2532
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2534
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2538
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2539
!print_event_info->short_form)
2541
my_b_printf(&cache, "BINLOG '\n");
2542
print_base64(&cache, print_event_info, false);
2543
print_event_info->printed_fd_event= true;
2547
#endif /* MYSQL_CLIENT */
2019
2550
Start_log_event_v3::Start_log_event_v3()
2542
3083
if (need_db && db && db_len)
2544
pos= my_stpcpy(pos, "use `");
3085
pos= strmov(pos, "use `");
2545
3086
memcpy(pos, db, db_len);
2546
pos= my_stpcpy(pos+db_len, "`; ");
3087
pos= strmov(pos+db_len, "`; ");
2549
pos= my_stpcpy(pos, "LOAD DATA ");
3090
pos= strmov(pos, "LOAD DATA ");
2552
3093
*fn_start= pos;
2554
3095
if (check_fname_outside_temp_buf())
2555
pos= my_stpcpy(pos, "LOCAL ");
2556
pos= my_stpcpy(pos, "INFILE '");
3096
pos= strmov(pos, "LOCAL ");
3097
pos= strmov(pos, "INFILE '");
2557
3098
memcpy(pos, fname, fname_len);
2558
pos= my_stpcpy(pos+fname_len, "' ");
3099
pos= strmov(pos+fname_len, "' ");
2560
3101
if (sql_ex.opt_flags & REPLACE_FLAG)
2561
pos= my_stpcpy(pos, " REPLACE ");
3102
pos= strmov(pos, " REPLACE ");
2562
3103
else if (sql_ex.opt_flags & IGNORE_FLAG)
2563
pos= my_stpcpy(pos, " IGNORE ");
3104
pos= strmov(pos, " IGNORE ");
2565
pos= my_stpcpy(pos ,"INTO");
3106
pos= strmov(pos ,"INTO");
2570
pos= my_stpcpy(pos ," Table `");
3111
pos= strmov(pos ," TABLE `");
2571
3112
memcpy(pos, table_name, table_name_len);
2572
3113
pos+= table_name_len;
2574
3115
/* We have to create all optinal fields as the default is not empty */
2575
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3116
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2576
3117
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2577
3118
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2578
pos= my_stpcpy(pos, " OPTIONALLY ");
2579
pos= my_stpcpy(pos, " ENCLOSED BY ");
3119
pos= strmov(pos, " OPTIONALLY ");
3120
pos= strmov(pos, " ENCLOSED BY ");
2580
3121
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2582
pos= my_stpcpy(pos, " ESCAPED BY ");
3123
pos= strmov(pos, " ESCAPED BY ");
2583
3124
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2585
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3126
pos= strmov(pos, " LINES TERMINATED BY ");
2586
3127
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2587
3128
if (sql_ex.line_start_len)
2589
pos= my_stpcpy(pos, " STARTING BY ");
3130
pos= strmov(pos, " STARTING BY ");
2590
3131
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2593
3134
if ((long) skip_lines > 0)
2595
pos= my_stpcpy(pos, " IGNORE ");
2596
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2597
pos= my_stpcpy(pos," LINES ");
3136
pos= strmov(pos, " IGNORE ");
3137
pos= longlong10_to_str((longlong) skip_lines, pos, 10);
3138
pos= strmov(pos," LINES ");
2600
3141
if (num_fields)
2603
3144
const char *field= fields;
2604
pos= my_stpcpy(pos, " (");
3145
pos= strmov(pos, " (");
2605
3146
for (i = 0; i < num_fields; i++)
3380
Load_log_event::print()
3384
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3386
print(file, print_event_info, 0);
3390
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3393
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3395
if (!print_event_info->short_form)
3397
print_header(&cache, print_event_info, false);
3398
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3399
thread_id, exec_time);
3402
bool different_db= 1;
3406
If the database is different from the one of the previous statement, we
3407
need to print the "use" command, and we update the last_db.
3408
But if commented, the "use" is going to be commented so we should not
3411
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3413
memcpy(print_event_info->db, db, db_len + 1);
3416
if (db && db[0] && different_db)
3417
my_b_printf(&cache, "%suse %s%s\n",
3418
commented ? "# " : "",
3419
db, print_event_info->delimiter);
3421
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3422
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3423
commented ? "# " : "", (ulong)thread_id,
3424
print_event_info->delimiter);
3425
my_b_printf(&cache, "%sLOAD DATA ",
3426
commented ? "# " : "");
3427
if (check_fname_outside_temp_buf())
3428
my_b_printf(&cache, "LOCAL ");
3429
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3431
if (sql_ex.opt_flags & REPLACE_FLAG)
3432
my_b_printf(&cache," REPLACE ");
3433
else if (sql_ex.opt_flags & IGNORE_FLAG)
3434
my_b_printf(&cache," IGNORE ");
3436
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3437
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3438
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3440
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3441
my_b_printf(&cache," OPTIONALLY ");
3442
my_b_printf(&cache, " ENCLOSED BY ");
3443
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3445
my_b_printf(&cache, " ESCAPED BY ");
3446
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3448
my_b_printf(&cache," LINES TERMINATED BY ");
3449
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3452
if (sql_ex.line_start)
3454
my_b_printf(&cache," STARTING BY ");
3455
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3457
if ((long) skip_lines > 0)
3458
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3463
const char* field = fields;
3464
my_b_printf(&cache, " (");
3465
for (i = 0; i < num_fields; i++)
3468
my_b_printf(&cache, ",");
3469
my_b_printf(&cache, field);
3471
field += field_lens[i] + 1;
3473
my_b_printf(&cache, ")");
3476
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3479
#endif /* MYSQL_CLIENT */
3481
#ifndef MYSQL_CLIENT
2835
3484
Load_log_event::set_fields()
3851
#ifndef MYSQL_CLIENT
3175
3852
Rotate_log_event::Rotate_log_event(const char* new_log_ident_arg,
3176
uint32_t ident_len_arg, uint64_t pos_arg,
3853
uint ident_len_arg, ulonglong pos_arg,
3178
3855
:Log_event(), new_log_ident(new_log_ident_arg),
3179
3856
pos(pos_arg),ident_len(ident_len_arg ? ident_len_arg :
3180
3857
(uint) strlen(new_log_ident_arg)), flags(flags_arg)
3182
3860
if (flags & DUP_NAME)
3183
3861
new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
3188
Rotate_log_event::Rotate_log_event(const char* buf, uint32_t event_len,
3867
Rotate_log_event::Rotate_log_event(const char* buf, uint event_len,
3189
3868
const Format_description_log_event* description_event)
3190
3869
:Log_event(buf, description_event) ,new_log_ident(0), flags(DUP_NAME)
3192
3871
// The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
3193
uint8_t header_size= description_event->common_header_len;
3194
uint8_t post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3195
uint32_t ident_offset;
3872
uint8 header_size= description_event->common_header_len;
3873
uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1];
3196
3875
if (event_len < header_size)
3198
3877
buf += header_size;
3351
4040
Intvar_log_event::write()
4043
#ifndef MYSQL_CLIENT
3354
4044
bool Intvar_log_event::write(IO_CACHE* file)
3356
unsigned char buf[9];
3357
buf[I_TYPE_OFFSET]= (unsigned char) type;
4047
buf[I_TYPE_OFFSET]= (uchar) type;
3358
4048
int8store(buf + I_VAL_OFFSET, val);
3359
4049
return (write_header(file, sizeof(buf)) ||
3360
4050
my_b_safe_write(file, buf, sizeof(buf)));
3365
4056
Intvar_log_event::print()
4060
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4064
Write_on_release_cache cache(&print_event_info->head_cache, file,
4065
Write_on_release_cache::FLUSH_F);
4067
if (!print_event_info->short_form)
4069
print_header(&cache, print_event_info, false);
4070
my_b_printf(&cache, "\tIntvar\n");
4073
my_b_printf(&cache, "SET ");
4075
case LAST_INSERT_ID_EVENT:
4076
msg="LAST_INSERT_ID";
4078
case INSERT_ID_EVENT:
4081
case INVALID_INT_EVENT:
4082
default: // cannot happen
4086
my_b_printf(&cache, "%s=%s%s\n",
4087
msg, llstr(val,llbuff), print_event_info->delimiter);
3369
4093
Intvar_log_event::do_apply_event()
4096
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3372
4097
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4168
#ifndef MYSQL_CLIENT
3439
4169
bool Rand_log_event::write(IO_CACHE* file)
3441
unsigned char buf[16];
3442
4172
int8store(buf + RAND_SEED1_OFFSET, seed1);
3443
4173
int8store(buf + RAND_SEED2_OFFSET, seed2);
3444
4174
return (write_header(file, sizeof(buf)) ||
3445
4175
my_b_safe_write(file, buf, sizeof(buf)));
4181
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4183
Write_on_release_cache cache(&print_event_info->head_cache, file,
4184
Write_on_release_cache::FLUSH_F);
4186
char llbuff[22],llbuff2[22];
4187
if (!print_event_info->short_form)
4189
print_header(&cache, print_event_info, false);
4190
my_b_printf(&cache, "\tRand\n");
4192
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4193
llstr(seed1, llbuff),llstr(seed2, llbuff2),
4194
print_event_info->delimiter);
4196
#endif /* MYSQL_CLIENT */
4199
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3449
4200
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3509
4264
:Log_event(buf, description_event)
3511
4266
buf+= description_event->common_header_len;
3512
memcpy(&xid, buf, sizeof(xid));
4267
memcpy((char*) &xid, buf, sizeof(xid));
4271
#ifndef MYSQL_CLIENT
3516
4272
bool Xid_log_event::write(IO_CACHE* file)
3518
4274
return write_header(file, sizeof(xid)) ||
3519
my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
3523
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4275
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4281
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4283
Write_on_release_cache cache(&print_event_info->head_cache, file,
4284
Write_on_release_cache::FLUSH_F);
4286
if (!print_event_info->short_form)
4289
longlong10_to_str(xid, buf, 10);
4291
print_header(&cache, print_event_info, false);
4292
my_b_printf(&cache, "\tXid = %s\n", buf);
4294
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4296
#endif /* MYSQL_CLIENT */
4299
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4300
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4302
/* For a slave Xid_log_event is COMMIT */
4303
general_log_print(thd, COM_QUERY,
4304
"COMMIT /* implicit, from Xid_log_event */");
3525
4305
return end_trans(thd, COMMIT);
3702
4486
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3704
4488
return (write_header(file, event_length) ||
3705
my_b_safe_write(file, (unsigned char*) buf, sizeof(buf)) ||
3706
my_b_safe_write(file, (unsigned char*) name, name_len) ||
3707
my_b_safe_write(file, (unsigned char*) buf1, buf1_length) ||
4489
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4490
my_b_safe_write(file, (uchar*) name, name_len) ||
4491
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3708
4492
my_b_safe_write(file, pos, val_len));
4498
User_var_log_event::print()
4502
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4504
Write_on_release_cache cache(&print_event_info->head_cache, file,
4505
Write_on_release_cache::FLUSH_F);
4507
if (!print_event_info->short_form)
4509
print_header(&cache, print_event_info, false);
4510
my_b_printf(&cache, "\tUser_var\n");
4513
my_b_printf(&cache, "SET @`");
4514
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4515
my_b_printf(&cache, "`");
4519
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4526
char real_buf[FMT_G_BUFSIZE(14)];
4527
float8get(real_val, val);
4528
my_sprintf(real_buf, (real_buf, "%.14g", real_val));
4529
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4533
longlong10_to_str(uint8korr(val), int_buf, -10);
4534
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4536
case DECIMAL_RESULT:
4539
int str_len= sizeof(str_buf) - 1;
4540
int precision= (int)val[0];
4541
int scale= (int)val[1];
4542
decimal_digit_t dec_buf[10];
4547
bin2decimal((uchar*) val+2, &dec, precision, scale);
4548
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4549
str_buf[str_len]= 0;
4550
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4556
Let's express the string in hex. That's the most robust way. If we
4557
print it in character form instead, we need to escape it with
4558
character_set_client which we don't know (we will know it in 5.0, but
4559
in 4.1 we don't know it easily when we are printing
4560
User_var_log_event). Explanation why we would need to bother with
4561
character_set_client (quoting Bar):
4562
> Note, the parser doesn't switch to another unescaping mode after
4563
> it has met a character set introducer.
4564
> For example, if an SJIS client says something like:
4565
> SET @a= _ucs2 \0a\0b'
4566
> the string constant is still unescaped according to SJIS, not
4567
> according to UCS2.
4572
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4573
break; // no error, as we are 'void'
4574
str_to_hex(hex_str, val, val_len);
4576
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4577
specify the variable's collation. It will however cause problems when
4578
people want to mysqlbinlog|mysql into another server not supporting the
4579
character set. But there's not much to do about this and it's unlikely.
4581
if (!(cs= get_charset(charset_number, MYF(0))))
4583
Generate an unusable command (=> syntax error) is probably the best
4584
thing we can do here.
4586
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4588
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4589
cs->csname, hex_str, cs->name,
4590
print_event_info->delimiter);
3714
4605
User_var_log_event::do_apply_event()
4608
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3717
4609
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3720
const CHARSET_INFO *charset;
4612
CHARSET_INFO *charset;
3721
4613
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3723
4615
LEX_STRING user_var_name;
3724
4616
user_var_name.str= name;
3725
4617
user_var_name.length= name_len;
3726
4618
double real_val;
3730
4622
We are now in a statement until the associated query log event has
3805
4697
return continue_group(rli);
4699
#endif /* !MYSQL_CLIENT */
3809
4702
/**************************************************************************
3810
4703
Slave_log_event methods
3811
4704
**************************************************************************/
4706
#ifdef HAVE_REPLICATION
4708
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4710
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4712
if (print_event_info->short_form)
4714
print_header(&cache, print_event_info, false);
4715
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4719
#ifndef MYSQL_CLIENT
3813
4720
void Slave_log_event::pack_info(Protocol *protocol)
3815
4722
char buf[256+HOSTNAME_LENGTH], *pos;
3816
pos= my_stpcpy(buf, "host=");
3817
pos= my_stpncpy(pos, master_host, HOSTNAME_LENGTH);
3818
pos= my_stpcpy(pos, ",port=");
4723
pos= strmov(buf, "host=");
4724
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4725
pos= strmov(pos, ",port=");
3819
4726
pos= int10_to_str((long) master_port, pos, 10);
3820
pos= my_stpcpy(pos, ",log=");
3821
pos= my_stpcpy(pos, master_log);
3822
pos= my_stpcpy(pos, ",pos=");
3823
pos= int64_t10_to_str(master_pos, pos, 10);
4727
pos= strmov(pos, ",log=");
4728
pos= strmov(pos, master_log);
4729
pos= strmov(pos, ",pos=");
4730
pos= longlong10_to_str(master_pos, pos, 10);
3824
4731
protocol->store(buf, pos-buf, &my_charset_bin);
4733
#endif /* !MYSQL_CLIENT */
4736
#ifndef MYSQL_CLIENT
3830
4739
re-write this better without holding both locks at the same time
5040
Create_file_log_event::print()
5044
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5047
Write_on_release_cache cache(&print_event_info->head_cache, file);
5049
if (print_event_info->short_form)
5051
if (enable_local && check_fname_outside_temp_buf())
5052
Load_log_event::print(file, print_event_info);
5058
Load_log_event::print(file, print_event_info,
5059
!check_fname_outside_temp_buf());
5061
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5062
SHOW BINLOG EVENTS we don't.
5064
my_b_printf(&cache, "#");
5067
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5071
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5073
print(file, print_event_info, 0);
5075
#endif /* MYSQL_CLIENT */
4084
5079
Create_file_log_event::pack_info()
5082
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4087
5083
void Create_file_log_event::pack_info(Protocol *protocol)
4089
5085
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4090
pos= my_stpcpy(buf, "db=");
5086
pos= strmov(buf, "db=");
4091
5087
memcpy(pos, db, db_len);
4092
pos= my_stpcpy(pos + db_len, ";table=");
5088
pos= strmov(pos + db_len, ";table=");
4093
5089
memcpy(pos, table_name, table_name_len);
4094
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5090
pos= strmov(pos + table_name_len, ";file_id=");
4095
5091
pos= int10_to_str((long) file_id, pos, 10);
4096
pos= my_stpcpy(pos, ";block_len=");
5092
pos= strmov(pos, ";block_len=");
4097
5093
pos= int10_to_str((long) block_len, pos, 10);
4098
5094
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5096
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4103
5100
Create_file_log_event::do_apply_event()
5103
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4106
5104
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4108
5106
char proc_info[17+FN_REFLEN+10], *fname_buf;
4123
5121
MYF(MY_WME|MY_NABP)))
4125
5123
rli->report(ERROR_LEVEL, my_errno,
4126
_("Error in Create_file event: could not open file '%s'"),
5124
"Error in Create_file event: could not open file '%s'",
4131
5129
// a trick to avoid allocating another buffer
4132
5130
fname= fname_buf;
4133
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5131
fname_len= (uint) (strmov(ext, ".data") - fname);
4134
5132
if (write_base(&file))
4136
my_stpcpy(ext, ".info"); // to have it right in the error message
5134
strmov(ext, ".info"); // to have it right in the error message
4137
5135
rli->report(ERROR_LEVEL, my_errno,
4138
_("Error in Create_file event: could not write to file '%s'"),
5136
"Error in Create_file event: could not write to file '%s'",
4142
5140
end_io_cache(&file);
4143
5141
my_close(fd, MYF(0));
4145
5143
// fname_buf now already has .data, not .info, because we did our trick
4146
5144
my_delete(fname_buf, MYF(0)); // old copy may exist already
4147
5145
if ((fd= my_create(fname_buf, CREATE_MODE,
4148
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
5146
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4151
5149
rli->report(ERROR_LEVEL, my_errno,
4152
_("Error in Create_file event: could not open file '%s'"),
5150
"Error in Create_file event: could not open file '%s'",
4156
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5154
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4158
5156
rli->report(ERROR_LEVEL, my_errno,
4159
_("Error in Create_file event: write to '%s' failed"),
5157
"Error in Create_file event: write to '%s' failed",
4180
5179
Append_block_log_event ctor
5182
#ifndef MYSQL_CLIENT
4183
5183
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4184
5184
const char *db_arg,
4185
unsigned char *block_arg,
4186
uint32_t block_len_arg,
4187
5187
bool using_trans)
4188
5188
:Log_event(thd_arg,0, using_trans), block(block_arg),
4189
5189
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4195
5196
Append_block_log_event ctor
4198
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5199
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4199
5200
const Format_description_log_event* description_event)
4200
5201
:Log_event(buf, description_event),block(0)
4202
uint8_t common_header_len= description_event->common_header_len;
4203
uint8_t append_block_header_len=
5203
uint8 common_header_len= description_event->common_header_len;
5204
uint8 append_block_header_len=
4204
5205
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4205
uint32_t total_header_len= common_header_len+append_block_header_len;
5206
uint total_header_len= common_header_len+append_block_header_len;
4206
5207
if (len < total_header_len)
4208
5209
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4209
block= (unsigned char*)buf + total_header_len;
5210
block= (uchar*)buf + total_header_len;
4210
5211
block_len= len - total_header_len;
4216
5217
Append_block_log_event::write()
5220
#ifndef MYSQL_CLIENT
4219
5221
bool Append_block_log_event::write(IO_CACHE* file)
4221
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5223
uchar buf[APPEND_BLOCK_HEADER_LEN];
4222
5224
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4223
5225
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4224
5226
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4225
my_b_safe_write(file, (unsigned char*) block, block_len));
5227
my_b_safe_write(file, (uchar*) block, block_len));
5233
Append_block_log_event::print()
5237
void Append_block_log_event::print(FILE* file,
5238
PRINT_EVENT_INFO* print_event_info)
5240
Write_on_release_cache cache(&print_event_info->head_cache, file);
5242
if (print_event_info->short_form)
5244
print_header(&cache, print_event_info, false);
5245
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5246
get_type_str(), file_id, block_len);
5248
#endif /* MYSQL_CLIENT */
4230
5252
Append_block_log_event::pack_info()
5255
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4233
5256
void Append_block_log_event::pack_info(Protocol *protocol)
4237
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
5260
length= (uint) my_sprintf(buf,
5261
(buf, ";file_id=%u;block_len=%u", file_id,
4239
5263
protocol->store(buf, length, &my_charset_bin);
4334
5361
Delete_file_log_event::write()
5364
#ifndef MYSQL_CLIENT
4337
5365
bool Delete_file_log_event::write(IO_CACHE* file)
4339
unsigned char buf[DELETE_FILE_HEADER_LEN];
5367
uchar buf[DELETE_FILE_HEADER_LEN];
4340
5368
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4341
5369
return (write_header(file, sizeof(buf)) ||
4342
5370
my_b_safe_write(file, buf, sizeof(buf)));
5376
Delete_file_log_event::print()
5380
void Delete_file_log_event::print(FILE* file,
5381
PRINT_EVENT_INFO* print_event_info)
5383
Write_on_release_cache cache(&print_event_info->head_cache, file);
5385
if (print_event_info->short_form)
5387
print_header(&cache, print_event_info, false);
5388
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5390
#endif /* MYSQL_CLIENT */
4347
5393
Delete_file_log_event::pack_info()
5396
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4350
5397
void Delete_file_log_event::pack_info(Protocol *protocol)
4354
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4355
protocol->store(buf, (int32_t) length, &my_charset_bin);
5401
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5402
protocol->store(buf, (int32) length, &my_charset_bin);
4359
5407
Delete_file_log_event::do_apply_event()
4362
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5410
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5411
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4364
5413
char fname[FN_REFLEN+10];
4365
5414
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4366
5415
(void) my_delete(fname, MYF(MY_WME));
4367
my_stpcpy(ext, ".info");
5416
strmov(ext, ".info");
4368
5417
(void) my_delete(fname, MYF(MY_WME));
5420
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4373
5423
/**************************************************************************
4406
5458
Execute_load_log_event::write()
5461
#ifndef MYSQL_CLIENT
4409
5462
bool Execute_load_log_event::write(IO_CACHE* file)
4411
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5464
uchar buf[EXEC_LOAD_HEADER_LEN];
4412
5465
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4413
5466
return (write_header(file, sizeof(buf)) ||
4414
5467
my_b_safe_write(file, buf, sizeof(buf)));
5473
Execute_load_log_event::print()
5477
void Execute_load_log_event::print(FILE* file,
5478
PRINT_EVENT_INFO* print_event_info)
5480
Write_on_release_cache cache(&print_event_info->head_cache, file);
5482
if (print_event_info->short_form)
5484
print_header(&cache, print_event_info, false);
5485
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
4419
5491
Execute_load_log_event::pack_info()
5494
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4422
5495
void Execute_load_log_event::pack_info(Protocol *protocol)
4426
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4427
protocol->store(buf, (int32_t) length, &my_charset_bin);
5499
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5500
protocol->store(buf, (int32) length, &my_charset_bin);
5592
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4523
5595
/**************************************************************************
4524
5596
Begin_load_query_log_event methods
4525
5597
**************************************************************************/
5599
#ifndef MYSQL_CLIENT
4527
5600
Begin_load_query_log_event::
4528
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, unsigned char* block_arg,
4529
uint32_t block_len_arg, bool using_trans)
5601
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5602
uint block_len_arg, bool using_trans)
4530
5603
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4533
5606
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4537
5611
Begin_load_query_log_event::
4538
Begin_load_query_log_event(const char* buf, uint32_t len,
5612
Begin_load_query_log_event(const char* buf, uint len,
4539
5613
const Format_description_log_event* desc_event)
4540
5614
:Append_block_log_event(buf, len, desc_event)
5619
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4545
5620
int Begin_load_query_log_event::get_create_or_append() const
4547
5622
return 1; /* create the file */
5624
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5627
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4551
5628
Log_event::enum_skip_reason
4552
5629
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5691
#ifndef MYSQL_CLIENT
4612
5693
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4614
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5695
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4615
5696
int4store(buf, file_id);
4616
5697
int4store(buf + 4, fn_pos_start);
4617
5698
int4store(buf + 4 + 4, fn_pos_end);
4618
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5699
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4619
5700
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5706
void Execute_load_query_log_event::print(FILE* file,
5707
PRINT_EVENT_INFO* print_event_info)
5709
print(file, print_event_info, 0);
5713
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5715
void Execute_load_query_log_event::print(FILE* file,
5716
PRINT_EVENT_INFO* print_event_info,
5717
const char *local_fname)
5719
Write_on_release_cache cache(&print_event_info->head_cache, file);
5721
print_query_header(&cache, print_event_info);
5725
my_b_write(&cache, (uchar*) query, fn_pos_start);
5726
my_b_printf(&cache, " LOCAL INFILE \'");
5727
my_b_printf(&cache, local_fname);
5728
my_b_printf(&cache, "\'");
5729
if (dup_handling == LOAD_DUP_REPLACE)
5730
my_b_printf(&cache, " REPLACE");
5731
my_b_printf(&cache, " INTO");
5732
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5733
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5737
my_b_write(&cache, (uchar*) query, q_len);
5738
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5741
if (!print_event_info->short_form)
5742
my_b_printf(&cache, "# file_id: %d \n", file_id);
5747
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4623
5748
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4625
5750
char *buf, *pos;
5758
6929
const char *const vpart= buf + common_header_len + post_header_len;
5760
6931
/* Extract the length of the various parts from the buffer */
5761
unsigned char const *const ptr_dblen= (unsigned char const*)vpart + 0;
5762
m_dblen= *(unsigned char*) ptr_dblen;
6932
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
6933
m_dblen= *(uchar*) ptr_dblen;
5764
6935
/* Length of database name + counter + terminating null */
5765
unsigned char const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
5766
m_tbllen= *(unsigned char*) ptr_tbllen;
6936
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
6937
m_tbllen= *(uchar*) ptr_tbllen;
5768
6939
/* Length of table name + counter + terminating null */
5769
unsigned char const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
5770
unsigned char *ptr_after_colcnt= (unsigned char*) ptr_colcnt;
6940
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
6941
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5771
6942
m_colcnt= net_field_length(&ptr_after_colcnt);
5773
6944
/* Allocate mem for all fields in one go. If fails, caught in is_valid() */
5774
m_memory= (unsigned char*) my_multi_malloc(MYF(MY_WME),
6945
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5775
6946
&m_dbnam, (uint) m_dblen + 1,
5776
6947
&m_tblnam, (uint) m_tbllen + 1,
5777
6948
&m_coltype, (uint) m_colcnt,
5785
6956
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5787
6958
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5788
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
6959
bytes_read= ptr_after_colcnt - (uchar *)buf;
5789
6960
if (bytes_read < event_len)
5791
6962
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5792
6963
assert(m_field_metadata_size <= (m_colcnt * 2));
5793
uint32_t num_null_bytes= (m_colcnt + 7) / 8;
5794
m_meta_memory= (unsigned char *)my_multi_malloc(MYF(MY_WME),
6964
uint num_null_bytes= (m_colcnt + 7) / 8;
6965
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5795
6966
&m_null_bits, num_null_bytes,
5796
6967
&m_field_metadata, m_field_metadata_size,
5798
6969
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5799
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
6970
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5800
6971
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5807
6979
Table_map_log_event::~Table_map_log_event()
5809
free(m_meta_memory);
6981
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
6982
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5835
7008
pthread_mutex_unlock(&LOCK_thread_count);
5837
7010
if (!(memory= my_multi_malloc(MYF(MY_WME),
5838
&table_list, (uint) sizeof(RPL_TableList),
7011
&table_list, (uint) sizeof(RPL_TABLE_LIST),
5839
7012
&db_mem, (uint) NAME_LEN + 1,
5840
7013
&tname_mem, (uint) NAME_LEN + 1,
5842
7015
return(HA_ERR_OUT_OF_MEM);
5844
memset(table_list, 0, sizeof(*table_list));
7017
bzero(table_list, sizeof(*table_list));
5845
7018
table_list->db = db_mem;
5846
7019
table_list->alias= table_list->table_name = tname_mem;
5847
7020
table_list->lock_type= TL_WRITE;
5848
7021
table_list->next_global= table_list->next_local= 0;
5849
7022
table_list->table_id= m_table_id;
5850
7023
table_list->updating= 1;
5851
my_stpcpy(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
5852
my_stpcpy(table_list->table_name, m_tblnam);
7024
strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
7025
strmov(table_list->table_name, m_tblnam);
5856
7029
if (!rpl_filter->db_ok(table_list->db) ||
5857
7030
(rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
7032
my_free(memory, MYF(MY_WME));
5991
7165
assert(m_dblen < 128);
5992
7166
assert(m_tbllen < 128);
5994
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5995
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
7168
uchar const dbuf[]= { (uchar) m_dblen };
7169
uchar const tbuf[]= { (uchar) m_tbllen };
5997
unsigned char cbuf[sizeof(m_colcnt)];
5998
unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
7171
uchar cbuf[sizeof(m_colcnt)];
7172
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5999
7173
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
6002
7176
Store the size of the field metadata.
6004
unsigned char mbuf[sizeof(m_field_metadata_size)];
6005
unsigned char *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
7178
uchar mbuf[sizeof(m_field_metadata_size)];
7179
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
6007
7181
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
6008
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7182
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
6009
7183
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
6010
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7184
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
6011
7185
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
6012
7186
my_b_safe_write(file, m_coltype, m_colcnt) ||
6013
7187
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
6014
7188
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
6015
7189
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7193
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6020
7196
Print some useful information for the SHOW BINARY LOG information
7200
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
6024
7201
void Table_map_log_event::pack_info(Protocol *protocol)
6907
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
8140
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
8143
void Update_rows_log_event::print(FILE *file,
8144
PRINT_EVENT_INFO* print_event_info)
8146
Rows_log_event::print_helper(file, print_event_info, "Update_rows");
8151
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6908
8152
const Format_description_log_event *descr_event)
6909
8153
: Log_event(buf, descr_event)
6911
uint8_t const common_header_len=
8155
uint8 const common_header_len=
6912
8156
descr_event->common_header_len;
6913
uint8_t const post_header_len=
8157
uint8 const post_header_len=
6914
8158
descr_event->post_header_len[INCIDENT_EVENT-1];
6916
8160
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
6917
8161
char const *ptr= buf + common_header_len + post_header_len;
6918
8162
char const *const str_end= buf + event_len;
6919
uint8_t len= 0; // Assignment to keep compiler happy
8163
uint8 len= 0; // Assignment to keep compiler happy
6920
8164
const char *str= NULL; // Assignment to keep compiler happy
6921
8165
read_str(&ptr, str_end, &str, &len);
6922
8166
m_message.str= const_cast<char*>(str);
6984
8245
return(write_str(file, m_message.str, m_message.length));
6987
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
8248
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8249
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6988
8250
const Format_description_log_event* description_event)
6989
8251
:Log_event(buf, description_event)
6991
uint8_t header_size= description_event->common_header_len;
8253
uint8 header_size= description_event->common_header_len;
6992
8254
ident_len = event_len - header_size;
6993
8255
set_if_smaller(ident_len,FN_REFLEN-1);
6994
8256
log_ident= buf + header_size;
8263
The default values for these variables should be values that are
8264
*incorrect*, i.e., values that cannot occur in an event. This way,
8265
they will always be printed for the first event.
8267
st_print_event_info::st_print_event_info()
8268
:flags2_inited(0), sql_mode_inited(0),
8269
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8270
lc_time_names_number(~0),
8271
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8272
thread_id(0), thread_id_printed(false),
8273
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8276
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8277
program's startup, but these explicit bzero() is for the day someone
8278
creates dynamic instances.
8280
bzero(db, sizeof(db));
8281
bzero(charset, sizeof(charset));
8282
bzero(time_zone_str, sizeof(time_zone_str));
8285
myf const flags = MYF(MY_WME | MY_NABP);
8286
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8287
open_cached_file(&body_cache, NULL, NULL, 0, flags);