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
1033
1147
if (!ev || !ev->is_valid())
1151
if (!force_opt) /* then mysqlbinlog dies */
1153
*error= "Found invalid event in binary log";
1156
ev= new Unknown_log_event(buf, description_event);
1036
1158
*error= "Found invalid event in binary log";
1168
Log_event::print_header()
1171
void Log_event::print_header(IO_CACHE* file,
1172
PRINT_EVENT_INFO* print_event_info,
1173
bool is_more __attribute__((unused)))
1176
my_off_t hexdump_from= print_event_info->hexdump_from;
1178
my_b_printf(file, "#");
1179
print_timestamp(file);
1180
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1181
llstr(log_pos,llbuff));
1183
/* mysqlbinlog --hexdump */
1184
if (print_event_info->hexdump_from)
1186
my_b_printf(file, "\n");
1187
uchar *ptr= (uchar*)temp_buf;
1189
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1192
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1193
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1194
char *c, char_string[16+1]= {0};
1196
/* Pretty-print event common header if header is exactly 19 bytes */
1197
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1199
char emit_buf[256]; // Enough for storing one line
1200
my_b_printf(file, "# Position Timestamp Type Master ID "
1201
"Size Master Pos Flags \n");
1202
int const bytes_written=
1203
snprintf(emit_buf, sizeof(emit_buf),
1204
"# %8.8lx %02x %02x %02x %02x %02x "
1205
"%02x %02x %02x %02x %02x %02x %02x %02x "
1206
"%02x %02x %02x %02x %02x %02x\n",
1207
(unsigned long) hexdump_from,
1208
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1209
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1210
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1211
assert(bytes_written >= 0);
1212
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1213
my_b_write(file, (uchar*) emit_buf, bytes_written);
1214
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1215
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1218
/* Rest of event (without common header) */
1219
for (i= 0, c= char_string, h=hex_string;
1223
snprintf(h, 4, "%02x ", *ptr);
1226
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1231
my_b_printf() does not support full printf() formats, so we
1232
have to do it this way.
1234
TODO: Rewrite my_b_printf() to support full printf() syntax.
1237
int const bytes_written=
1238
snprintf(emit_buf, sizeof(emit_buf),
1239
"# %8.8lx %-48.48s |%16s|\n",
1240
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1241
hex_string, char_string);
1242
assert(bytes_written >= 0);
1243
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1244
my_b_write(file, (uchar*) emit_buf, bytes_written);
1250
else if (i % 8 == 7) *h++ = ' ';
1257
int const bytes_written=
1258
snprintf(emit_buf, sizeof(emit_buf),
1259
"# %8.8lx %-48.48s |%s|\n",
1260
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1261
hex_string, char_string);
1262
assert(bytes_written >= 0);
1263
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1264
my_b_write(file, (uchar*) emit_buf, bytes_written);
1267
need a # to prefix the rest of printouts for example those of
1268
Rows_log_event::print_helper().
1270
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1276
void Log_event::print_base64(IO_CACHE* file,
1277
PRINT_EVENT_INFO* print_event_info,
1280
const uchar *ptr= (const uchar *)temp_buf;
1281
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
1283
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1284
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1286
fprintf(stderr, "\nError: Out of memory. "
1287
"Could not print correct binlog event.\n");
1291
if (base64_encode(ptr, (size_t) size, tmp_str))
1296
if (my_b_tell(file) == 0)
1297
my_b_printf(file, "\nBINLOG '\n");
1299
my_b_printf(file, "%s\n", tmp_str);
1302
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1304
my_free(tmp_str, MYF(0));
1310
Log_event::print_timestamp()
1313
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1318
#ifdef MYSQL_SERVER // This is always false
1320
localtime_r(ts,(res= &tm_tmp));
1325
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1335
#endif /* MYSQL_CLIENT */
1338
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1042
1339
inline Log_event::enum_skip_reason
1043
1340
Log_event::continue_group(Relay_log_info *rli)
1457
1760
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,
1762
Query_log_event::Query_log_event(const char* buf, uint event_len,
1460
1763
const Format_description_log_event
1461
1764
*description_event,
1462
1765
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),
1766
:Log_event(buf, description_event), data_buf(0), query(NullS),
1767
db(NullS), catalog_len(0), status_vars_len(0),
1465
1768
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
1466
1769
auto_increment_increment(1), auto_increment_offset(1),
1467
1770
time_zone_len(0), lc_time_names_number(0), charset_database_number(0)
1471
uint8_t common_header_len, post_header_len;
1774
uint8 common_header_len, post_header_len;
1472
1775
Log_event::Byte *start;
1473
1776
const Log_event::Byte *end;
1474
1777
bool catalog_nz= 1;
1944
Query_log_event::print().
1947
print the catalog ??
1949
void Query_log_event::print_query_header(IO_CACHE* file,
1950
PRINT_EVENT_INFO* print_event_info)
1952
// TODO: print the catalog ??
1953
char buff[40],*end; // Enough for SET TIMESTAMP
1954
bool different_db= 1;
1957
if (!print_event_info->short_form)
1959
print_header(file, print_event_info, false);
1960
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
1961
get_type_str(), (ulong) thread_id, (ulong) exec_time,
1965
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
1967
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
1968
memcpy(print_event_info->db, db, db_len + 1);
1969
if (db[0] && different_db)
1970
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1973
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
1974
end= strmov(end, print_event_info->delimiter);
1976
my_b_write(file, (uchar*) buff, (uint) (end-buff));
1977
if ((!print_event_info->thread_id_printed ||
1978
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
1979
thread_id != print_event_info->thread_id)))
1981
// If --short-form, print deterministic value instead of pseudo_thread_id.
1982
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
1983
short_form ? 999999999 : (ulong)thread_id,
1984
print_event_info->delimiter);
1985
print_event_info->thread_id= thread_id;
1986
print_event_info->thread_id_printed= 1;
1990
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
1991
print (remember we don't produce mixed relay logs so there cannot be
1992
5.0 events before that one so there is nothing to reset).
1994
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
1996
/* tmp is a bitmask of bits which have changed. */
1997
if (likely(print_event_info->flags2_inited))
1998
/* All bits which have changed */
1999
tmp= (print_event_info->flags2) ^ flags2;
2000
else /* that's the first Query event we read */
2002
print_event_info->flags2_inited= 1;
2003
tmp= ~((uint32)0); /* all bits have changed */
2006
if (unlikely(tmp)) /* some bits have changed */
2009
my_b_printf(file, "SET ");
2010
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2011
"@@session.foreign_key_checks", &need_comma);
2012
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2013
"@@session.sql_auto_is_null", &need_comma);
2014
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2015
"@@session.unique_checks", &need_comma);
2016
my_b_printf(file,"%s\n", print_event_info->delimiter);
2017
print_event_info->flags2= flags2;
2022
Now the session variables;
2023
it's more efficient to pass SQL_MODE as a number instead of a
2024
comma-separated list.
2025
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2026
variables (they have no global version; they're not listed in
2027
sql_class.h), The tests below work for pure binlogs or pure relay
2028
logs. Won't work for mixed relay logs but we don't create mixed
2029
relay logs (that is, there is no relay log with a format change
2030
except within the 3 first events, which mysqlbinlog handles
2031
gracefully). So this code should always be good.
2034
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2035
print_event_info->auto_increment_offset != auto_increment_offset)
2037
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2038
auto_increment_increment,auto_increment_offset,
2039
print_event_info->delimiter);
2040
print_event_info->auto_increment_increment= auto_increment_increment;
2041
print_event_info->auto_increment_offset= auto_increment_offset;
2044
/* TODO: print the catalog when we feature SET CATALOG */
2046
if (likely(charset_inited) &&
2047
(unlikely(!print_event_info->charset_inited ||
2048
bcmp((uchar*) print_event_info->charset, (uchar*) charset, 6))))
2050
CHARSET_INFO *cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2053
/* for mysql client */
2054
my_b_printf(file, "/*!\\C %s */%s\n",
2055
cs_info->csname, print_event_info->delimiter);
2057
my_b_printf(file,"SET "
2058
"@@session.character_set_client=%d,"
2059
"@@session.collation_connection=%d,"
2060
"@@session.collation_server=%d"
2063
uint2korr(charset+2),
2064
uint2korr(charset+4),
2065
print_event_info->delimiter);
2066
memcpy(print_event_info->charset, charset, 6);
2067
print_event_info->charset_inited= 1;
2071
if (bcmp((uchar*) print_event_info->time_zone_str,
2072
(uchar*) time_zone_str, time_zone_len+1))
2074
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2075
time_zone_str, print_event_info->delimiter);
2076
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2079
if (lc_time_names_number != print_event_info->lc_time_names_number)
2081
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2082
lc_time_names_number, print_event_info->delimiter);
2083
print_event_info->lc_time_names_number= lc_time_names_number;
2085
if (charset_database_number != print_event_info->charset_database_number)
2087
if (charset_database_number)
2088
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2089
charset_database_number, print_event_info->delimiter);
2091
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2092
print_event_info->delimiter);
2093
print_event_info->charset_database_number= charset_database_number;
2098
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2100
Write_on_release_cache cache(&print_event_info->head_cache, file);
2102
print_query_header(&cache, print_event_info);
2103
my_b_write(&cache, (uchar*) query, q_len);
2104
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2106
#endif /* MYSQL_CLIENT */
1632
2110
Query_log_event::do_apply_event()
2113
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1634
2115
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1636
2117
return do_apply_event(rli, query, q_len);
1773
2283
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1776
rli->report(ERROR_LEVEL, expected_error,
1777
_("Query partially completed on the master "
1778
"(error on master: %d) and was aborted. There is a "
1779
"chance that your master is inconsistent at this "
1780
"point. If you are sure that your master is ok, run "
1781
"this query manually on the slave and then restart the "
1782
"slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; "
1783
"START SLAVE; . Query: '%s'"),
1784
expected_error, thd->query);
2286
rli->report(ERROR_LEVEL, expected_error,
2288
Query partially completed on the master (error on master: %d) \
2289
and was aborted. There is a chance that your master is inconsistent at this \
2290
point. If you are sure that your master is ok, run this query manually on the \
2291
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
2292
START SLAVE; . Query: '%s'", expected_error, thd->query);
1785
2293
thd->is_slave_error= 1;
2298
/* If the query was not ignored, it is printed to the general log */
2299
if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
2300
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
1790
2302
compare_errors:
1926
2439
return(Log_event::do_shall_skip(rli));
1930
2445
/**************************************************************************
1931
2446
Start_log_event_v3 methods
1932
2447
**************************************************************************/
2449
#ifndef MYSQL_CLIENT
1934
2450
Start_log_event_v3::Start_log_event_v3()
1935
2451
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1936
2452
artificial_event(0), dont_set_created(0)
1938
2454
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
1942
2459
Start_log_event_v3::pack_info()
2462
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1945
2463
void Start_log_event_v3::pack_info(Protocol *protocol)
1947
2465
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: ");
2466
pos= strmov(buf, "Server ver: ");
2467
pos= strmov(pos, server_version);
2468
pos= strmov(pos, ", Binlog ver: ");
1951
2469
pos= int10_to_str(binlog_version, pos, 10);
1952
2470
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2476
Start_log_event_v3::print()
2480
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2482
Write_on_release_cache cache(&print_event_info->head_cache, file,
2483
Write_on_release_cache::FLUSH_F);
2485
if (!print_event_info->short_form)
2487
print_header(&cache, print_event_info, false);
2488
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2489
binlog_version, server_version);
2490
print_timestamp(&cache);
2492
my_b_printf(&cache," at startup");
2493
my_b_printf(&cache, "\n");
2494
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2495
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2496
"Most probably mysqld crashed writing it.\n");
2498
if (!artificial_event && created)
2500
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2502
This is for mysqlbinlog: like in replication, we want to delete the stale
2503
tmp files left by an unclean shutdown of mysqld (temporary tables)
2504
and rollback unfinished transaction.
2505
Probably this can be done with RESET CONNECTION (syntax to be defined).
2507
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2509
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2513
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2514
!print_event_info->short_form)
2516
my_b_printf(&cache, "BINLOG '\n");
2517
print_base64(&cache, print_event_info, false);
2518
print_event_info->printed_fd_event= true;
2522
#endif /* MYSQL_CLIENT */
1957
2525
Start_log_event_v3::Start_log_event_v3()
2480
3058
if (need_db && db && db_len)
2482
pos= my_stpcpy(pos, "use `");
3060
pos= strmov(pos, "use `");
2483
3061
memcpy(pos, db, db_len);
2484
pos= my_stpcpy(pos+db_len, "`; ");
3062
pos= strmov(pos+db_len, "`; ");
2487
pos= my_stpcpy(pos, "LOAD DATA ");
3065
pos= strmov(pos, "LOAD DATA ");
2490
3068
*fn_start= pos;
2492
3070
if (check_fname_outside_temp_buf())
2493
pos= my_stpcpy(pos, "LOCAL ");
2494
pos= my_stpcpy(pos, "INFILE '");
3071
pos= strmov(pos, "LOCAL ");
3072
pos= strmov(pos, "INFILE '");
2495
3073
memcpy(pos, fname, fname_len);
2496
pos= my_stpcpy(pos+fname_len, "' ");
3074
pos= strmov(pos+fname_len, "' ");
2498
3076
if (sql_ex.opt_flags & REPLACE_FLAG)
2499
pos= my_stpcpy(pos, " REPLACE ");
3077
pos= strmov(pos, " REPLACE ");
2500
3078
else if (sql_ex.opt_flags & IGNORE_FLAG)
2501
pos= my_stpcpy(pos, " IGNORE ");
3079
pos= strmov(pos, " IGNORE ");
2503
pos= my_stpcpy(pos ,"INTO");
3081
pos= strmov(pos ,"INTO");
2508
pos= my_stpcpy(pos ," Table `");
3086
pos= strmov(pos ," TABLE `");
2509
3087
memcpy(pos, table_name, table_name_len);
2510
3088
pos+= table_name_len;
2512
3090
/* We have to create all optinal fields as the default is not empty */
2513
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3091
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2514
3092
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2515
3093
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2516
pos= my_stpcpy(pos, " OPTIONALLY ");
2517
pos= my_stpcpy(pos, " ENCLOSED BY ");
3094
pos= strmov(pos, " OPTIONALLY ");
3095
pos= strmov(pos, " ENCLOSED BY ");
2518
3096
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2520
pos= my_stpcpy(pos, " ESCAPED BY ");
3098
pos= strmov(pos, " ESCAPED BY ");
2521
3099
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2523
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3101
pos= strmov(pos, " LINES TERMINATED BY ");
2524
3102
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2525
3103
if (sql_ex.line_start_len)
2527
pos= my_stpcpy(pos, " STARTING BY ");
3105
pos= strmov(pos, " STARTING BY ");
2528
3106
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2531
3109
if ((long) skip_lines > 0)
2533
pos= my_stpcpy(pos, " IGNORE ");
3111
pos= strmov(pos, " IGNORE ");
2534
3112
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2535
pos= my_stpcpy(pos," LINES ");
3113
pos= strmov(pos," LINES ");
2538
3116
if (num_fields)
2541
3119
const char *field= fields;
2542
pos= my_stpcpy(pos, " (");
3120
pos= strmov(pos, " (");
2543
3121
for (i = 0; i < num_fields; i++)
3355
Load_log_event::print()
3359
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3361
print(file, print_event_info, 0);
3365
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3368
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3370
if (!print_event_info->short_form)
3372
print_header(&cache, print_event_info, false);
3373
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3374
thread_id, exec_time);
3377
bool different_db= 1;
3381
If the database is different from the one of the previous statement, we
3382
need to print the "use" command, and we update the last_db.
3383
But if commented, the "use" is going to be commented so we should not
3386
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3388
memcpy(print_event_info->db, db, db_len + 1);
3391
if (db && db[0] && different_db)
3392
my_b_printf(&cache, "%suse %s%s\n",
3393
commented ? "# " : "",
3394
db, print_event_info->delimiter);
3396
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3397
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3398
commented ? "# " : "", (ulong)thread_id,
3399
print_event_info->delimiter);
3400
my_b_printf(&cache, "%sLOAD DATA ",
3401
commented ? "# " : "");
3402
if (check_fname_outside_temp_buf())
3403
my_b_printf(&cache, "LOCAL ");
3404
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3406
if (sql_ex.opt_flags & REPLACE_FLAG)
3407
my_b_printf(&cache," REPLACE ");
3408
else if (sql_ex.opt_flags & IGNORE_FLAG)
3409
my_b_printf(&cache," IGNORE ");
3411
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3412
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3413
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3415
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3416
my_b_printf(&cache," OPTIONALLY ");
3417
my_b_printf(&cache, " ENCLOSED BY ");
3418
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3420
my_b_printf(&cache, " ESCAPED BY ");
3421
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3423
my_b_printf(&cache," LINES TERMINATED BY ");
3424
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3427
if (sql_ex.line_start)
3429
my_b_printf(&cache," STARTING BY ");
3430
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3432
if ((long) skip_lines > 0)
3433
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3438
const char* field = fields;
3439
my_b_printf(&cache, " (");
3440
for (i = 0; i < num_fields; i++)
3443
my_b_printf(&cache, ",");
3444
my_b_printf(&cache, field);
3446
field += field_lens[i] + 1;
3448
my_b_printf(&cache, ")");
3451
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3454
#endif /* MYSQL_CLIENT */
3456
#ifndef MYSQL_CLIENT
2773
3459
Load_log_event::set_fields()
3287
4012
Intvar_log_event::write()
4015
#ifndef MYSQL_CLIENT
3290
4016
bool Intvar_log_event::write(IO_CACHE* file)
3292
unsigned char buf[9];
3293
buf[I_TYPE_OFFSET]= (unsigned char) type;
4019
buf[I_TYPE_OFFSET]= (uchar) type;
3294
4020
int8store(buf + I_VAL_OFFSET, val);
3295
4021
return (write_header(file, sizeof(buf)) ||
3296
4022
my_b_safe_write(file, buf, sizeof(buf)));
3301
4028
Intvar_log_event::print()
4032
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4036
Write_on_release_cache cache(&print_event_info->head_cache, file,
4037
Write_on_release_cache::FLUSH_F);
4039
if (!print_event_info->short_form)
4041
print_header(&cache, print_event_info, false);
4042
my_b_printf(&cache, "\tIntvar\n");
4045
my_b_printf(&cache, "SET ");
4047
case LAST_INSERT_ID_EVENT:
4048
msg="LAST_INSERT_ID";
4050
case INSERT_ID_EVENT:
4053
case INVALID_INT_EVENT:
4054
default: // cannot happen
4058
my_b_printf(&cache, "%s=%s%s\n",
4059
msg, llstr(val,llbuff), print_event_info->delimiter);
3305
4065
Intvar_log_event::do_apply_event()
4068
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3308
4069
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4140
#ifndef MYSQL_CLIENT
3375
4141
bool Rand_log_event::write(IO_CACHE* file)
3377
unsigned char buf[16];
3378
4144
int8store(buf + RAND_SEED1_OFFSET, seed1);
3379
4145
int8store(buf + RAND_SEED2_OFFSET, seed2);
3380
4146
return (write_header(file, sizeof(buf)) ||
3381
4147
my_b_safe_write(file, buf, sizeof(buf)));
4153
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4155
Write_on_release_cache cache(&print_event_info->head_cache, file,
4156
Write_on_release_cache::FLUSH_F);
4158
char llbuff[22],llbuff2[22];
4159
if (!print_event_info->short_form)
4161
print_header(&cache, print_event_info, false);
4162
my_b_printf(&cache, "\tRand\n");
4164
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4165
llstr(seed1, llbuff),llstr(seed2, llbuff2),
4166
print_event_info->delimiter);
4168
#endif /* MYSQL_CLIENT */
4171
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3385
4172
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
3445
4236
:Log_event(buf, description_event)
3447
4238
buf+= description_event->common_header_len;
3448
memcpy(&xid, buf, sizeof(xid));
4239
memcpy((char*) &xid, buf, sizeof(xid));
4243
#ifndef MYSQL_CLIENT
3452
4244
bool Xid_log_event::write(IO_CACHE* file)
3454
4246
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)))
4247
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4253
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4255
Write_on_release_cache cache(&print_event_info->head_cache, file,
4256
Write_on_release_cache::FLUSH_F);
4258
if (!print_event_info->short_form)
4261
int64_t10_to_str(xid, buf, 10);
4263
print_header(&cache, print_event_info, false);
4264
my_b_printf(&cache, "\tXid = %s\n", buf);
4266
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4268
#endif /* MYSQL_CLIENT */
4271
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4272
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4274
/* For a slave Xid_log_event is COMMIT */
4275
general_log_print(thd, COM_QUERY,
4276
"COMMIT /* implicit, from Xid_log_event */");
3461
4277
return end_trans(thd, COMMIT);
3638
4458
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3640
4460
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) ||
4461
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4462
my_b_safe_write(file, (uchar*) name, name_len) ||
4463
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3644
4464
my_b_safe_write(file, pos, val_len));
4470
User_var_log_event::print()
4474
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4476
Write_on_release_cache cache(&print_event_info->head_cache, file,
4477
Write_on_release_cache::FLUSH_F);
4479
if (!print_event_info->short_form)
4481
print_header(&cache, print_event_info, false);
4482
my_b_printf(&cache, "\tUser_var\n");
4485
my_b_printf(&cache, "SET @`");
4486
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4487
my_b_printf(&cache, "`");
4491
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4498
char real_buf[FMT_G_BUFSIZE(14)];
4499
float8get(real_val, val);
4500
my_sprintf(real_buf, (real_buf, "%.14g", real_val));
4501
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4505
int64_t10_to_str(uint8korr(val), int_buf, -10);
4506
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4508
case DECIMAL_RESULT:
4511
int str_len= sizeof(str_buf) - 1;
4512
int precision= (int)val[0];
4513
int scale= (int)val[1];
4514
decimal_digit_t dec_buf[10];
4519
bin2decimal((uchar*) val+2, &dec, precision, scale);
4520
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4521
str_buf[str_len]= 0;
4522
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4528
Let's express the string in hex. That's the most robust way. If we
4529
print it in character form instead, we need to escape it with
4530
character_set_client which we don't know (we will know it in 5.0, but
4531
in 4.1 we don't know it easily when we are printing
4532
User_var_log_event). Explanation why we would need to bother with
4533
character_set_client (quoting Bar):
4534
> Note, the parser doesn't switch to another unescaping mode after
4535
> it has met a character set introducer.
4536
> For example, if an SJIS client says something like:
4537
> SET @a= _ucs2 \0a\0b'
4538
> the string constant is still unescaped according to SJIS, not
4539
> according to UCS2.
4544
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4545
break; // no error, as we are 'void'
4546
str_to_hex(hex_str, val, val_len);
4548
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4549
specify the variable's collation. It will however cause problems when
4550
people want to mysqlbinlog|mysql into another server not supporting the
4551
character set. But there's not much to do about this and it's unlikely.
4553
if (!(cs= get_charset(charset_number, MYF(0))))
4555
Generate an unusable command (=> syntax error) is probably the best
4556
thing we can do here.
4558
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4560
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4561
cs->csname, hex_str, cs->name,
4562
print_event_info->delimiter);
3650
4577
User_var_log_event::do_apply_event()
4580
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3653
4581
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3656
const CHARSET_INFO *charset;
4584
CHARSET_INFO *charset;
3657
4585
if (!(charset= get_charset(charset_number, MYF(MY_WME))))
3659
4587
LEX_STRING user_var_name;
3741
4669
return continue_group(rli);
4671
#endif /* !MYSQL_CLIENT */
3745
4674
/**************************************************************************
3746
4675
Slave_log_event methods
3747
4676
**************************************************************************/
4678
#ifdef HAVE_REPLICATION
4680
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4682
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4684
if (print_event_info->short_form)
4686
print_header(&cache, print_event_info, false);
4687
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4691
#ifndef MYSQL_CLIENT
3749
4692
void Slave_log_event::pack_info(Protocol *protocol)
3751
4694
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=");
4695
pos= strmov(buf, "host=");
4696
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4697
pos= strmov(pos, ",port=");
3755
4698
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=");
4699
pos= strmov(pos, ",log=");
4700
pos= strmov(pos, master_log);
4701
pos= strmov(pos, ",pos=");
3759
4702
pos= int64_t10_to_str(master_pos, pos, 10);
3760
4703
protocol->store(buf, pos-buf, &my_charset_bin);
4705
#endif /* !MYSQL_CLIENT */
4708
#ifndef MYSQL_CLIENT
3766
4711
re-write this better without holding both locks at the same time
3776
4721
// TODO: re-write this better without holding both locks at the same time
3777
4722
pthread_mutex_lock(&mi->data_lock);
3778
4723
pthread_mutex_lock(&rli->data_lock);
4724
master_host_len = strlen(mi->host);
4725
master_log_len = strlen(rli->group_master_log_name);
3779
4726
// on OOM, just do not initialize the structure and print the error
3780
4727
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();
4730
master_host = mem_pool + SL_MASTER_HOST_OFFSET ;
4731
memcpy(master_host, mi->host, master_host_len + 1);
4732
master_log = master_host + master_host_len + 1;
4733
memcpy(master_log, rli->group_master_log_name, master_log_len + 1);
4734
master_port = mi->port;
3786
4735
master_pos = rli->group_master_log_pos;
3789
sql_print_error(_("Out of memory while recording slave event"));
4738
sql_print_error("Out of memory while recording slave event");
3790
4739
pthread_mutex_unlock(&rli->data_lock);
3791
4740
pthread_mutex_unlock(&mi->data_lock);
4743
#endif /* !MYSQL_CLIENT */
3796
4746
Slave_log_event::~Slave_log_event()
4748
my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
4753
void Slave_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4755
Write_on_release_cache cache(&print_event_info->head_cache, file);
4758
if (print_event_info->short_form)
4760
print_header(&cache, print_event_info, false);
4761
my_b_printf(&cache, "\n\
4762
Slave: master_host: '%s' master_port: %d master_log: '%s' master_pos: %s\n",
4763
master_host, master_port, master_log, llstr(master_pos, llbuff));
4765
#endif /* MYSQL_CLIENT */
3802
4768
int Slave_log_event::get_data_size()
3804
return master_host.length() + master_log.length() + 1 + SL_MASTER_HOST_OFFSET;
4770
return master_host_len + master_log_len + 1 + SL_MASTER_HOST_OFFSET;
4774
#ifndef MYSQL_CLIENT
3808
4775
bool Slave_log_event::write(IO_CACHE* file)
3810
4777
ulong event_length= get_data_size();
3813
4780
// log and host are already there
3815
4782
return (write_header(file, event_length) ||
3816
my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
4783
my_b_safe_write(file, (uchar*) mem_pool, event_length));
3820
void Slave_log_event::init_from_mem_pool()
4788
void Slave_log_event::init_from_mem_pool(int data_size)
3822
4790
master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET);
3823
4791
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)))
4792
master_host = mem_pool + SL_MASTER_HOST_OFFSET;
4793
master_host_len = strlen(master_host);
4795
master_log = master_host + master_host_len + 1;
4796
if (master_log > mem_pool + data_size)
4801
master_log_len = strlen(master_log);
4805
/** This code is not used, so has not been updated to be format-tolerant. */
4806
Slave_log_event::Slave_log_event(const char* buf, uint event_len)
4807
:Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0)
4809
if (event_len < LOG_EVENT_HEADER_LEN)
4811
event_len -= LOG_EVENT_HEADER_LEN;
4812
if (!(mem_pool = (char*) my_malloc(event_len + 1, MYF(MY_WME))))
4814
memcpy(mem_pool, buf + LOG_EVENT_HEADER_LEN, event_len);
4815
mem_pool[event_len] = 0;
4816
init_from_mem_pool(event_len);
4820
#ifndef MYSQL_CLIENT
4821
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
3834
4823
if (mysql_bin_log.is_open())
3835
4824
mysql_bin_log.write(this);
4827
#endif /* !MYSQL_CLIENT */
3840
4830
/**************************************************************************
5012
Create_file_log_event::print()
5016
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5019
Write_on_release_cache cache(&print_event_info->head_cache, file);
5021
if (print_event_info->short_form)
5023
if (enable_local && check_fname_outside_temp_buf())
5024
Load_log_event::print(file, print_event_info);
5030
Load_log_event::print(file, print_event_info,
5031
!check_fname_outside_temp_buf());
5033
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5034
SHOW BINLOG EVENTS we don't.
5036
my_b_printf(&cache, "#");
5039
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5043
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5045
print(file, print_event_info, 0);
5047
#endif /* MYSQL_CLIENT */
3996
5051
Create_file_log_event::pack_info()
5054
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3999
5055
void Create_file_log_event::pack_info(Protocol *protocol)
4001
5057
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4002
pos= my_stpcpy(buf, "db=");
5058
pos= strmov(buf, "db=");
4003
5059
memcpy(pos, db, db_len);
4004
pos= my_stpcpy(pos + db_len, ";table=");
5060
pos= strmov(pos + db_len, ";table=");
4005
5061
memcpy(pos, table_name, table_name_len);
4006
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5062
pos= strmov(pos + table_name_len, ";file_id=");
4007
5063
pos= int10_to_str((long) file_id, pos, 10);
4008
pos= my_stpcpy(pos, ";block_len=");
5064
pos= strmov(pos, ";block_len=");
4009
5065
pos= int10_to_str((long) block_len, pos, 10);
4010
5066
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5068
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4015
5072
Create_file_log_event::do_apply_event()
5075
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4018
5076
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4020
5078
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 ");
5084
bzero((char*)&file, sizeof(file));
5085
fname_buf= strmov(proc_info, "Making temp file ");
4028
5086
ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4029
thd->set_proc_info(proc_info);
5087
thd_proc_info(thd, proc_info);
4030
5088
my_delete(fname_buf, MYF(0)); // old copy may exist already
4031
5089
if ((fd= my_create(fname_buf, CREATE_MODE,
5090
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4033
5091
MYF(MY_WME))) < 0 ||
4034
5092
init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0,
4035
5093
MYF(MY_WME|MY_NABP)))
4037
5095
rli->report(ERROR_LEVEL, my_errno,
4038
_("Error in Create_file event: could not open file '%s'"),
5096
"Error in Create_file event: could not open file '%s'",
4043
5101
// a trick to avoid allocating another buffer
4044
5102
fname= fname_buf;
4045
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5103
fname_len= (uint) (strmov(ext, ".data") - fname);
4046
5104
if (write_base(&file))
4048
my_stpcpy(ext, ".info"); // to have it right in the error message
5106
strmov(ext, ".info"); // to have it right in the error message
4049
5107
rli->report(ERROR_LEVEL, my_errno,
4050
_("Error in Create_file event: could not write to file '%s'"),
5108
"Error in Create_file event: could not write to file '%s'",
4054
5112
end_io_cache(&file);
4055
5113
my_close(fd, MYF(0));
4057
5115
// fname_buf now already has .data, not .info, because we did our trick
4058
5116
my_delete(fname_buf, MYF(0)); // old copy may exist already
4059
5117
if ((fd= my_create(fname_buf, CREATE_MODE,
5118
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4063
5121
rli->report(ERROR_LEVEL, my_errno,
4064
_("Error in Create_file event: could not open file '%s'"),
5122
"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)))
5126
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4070
5128
rli->report(ERROR_LEVEL, my_errno,
4071
_("Error in Create_file event: write to '%s' failed"),
5129
"Error in Create_file event: write to '%s' failed",
4092
5151
Append_block_log_event ctor
5154
#ifndef MYSQL_CLIENT
4095
5155
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4096
5156
const char *db_arg,
4097
unsigned char *block_arg,
4098
uint32_t block_len_arg,
4099
5159
bool using_trans)
4100
5160
:Log_event(thd_arg,0, using_trans), block(block_arg),
4101
5161
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4107
5168
Append_block_log_event ctor
4110
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5171
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4111
5172
const Format_description_log_event* description_event)
4112
5173
: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=
5175
uint8 common_header_len= description_event->common_header_len;
5176
uint8 append_block_header_len=
4116
5177
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4117
uint32_t total_header_len= common_header_len+append_block_header_len;
5178
uint total_header_len= common_header_len+append_block_header_len;
4118
5179
if (len < total_header_len)
4120
5181
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4121
block= (unsigned char*)buf + total_header_len;
5182
block= (uchar*)buf + total_header_len;
4122
5183
block_len= len - total_header_len;
4128
5189
Append_block_log_event::write()
5192
#ifndef MYSQL_CLIENT
4131
5193
bool Append_block_log_event::write(IO_CACHE* file)
4133
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5195
uchar buf[APPEND_BLOCK_HEADER_LEN];
4134
5196
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4135
5197
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4136
5198
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4137
my_b_safe_write(file, (unsigned char*) block, block_len));
5199
my_b_safe_write(file, (uchar*) block, block_len));
5205
Append_block_log_event::print()
5209
void Append_block_log_event::print(FILE* file,
5210
PRINT_EVENT_INFO* print_event_info)
5212
Write_on_release_cache cache(&print_event_info->head_cache, file);
5214
if (print_event_info->short_form)
5216
print_header(&cache, print_event_info, false);
5217
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5218
get_type_str(), file_id, block_len);
5220
#endif /* MYSQL_CLIENT */
4142
5224
Append_block_log_event::pack_info()
5227
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4145
5228
void Append_block_log_event::pack_info(Protocol *protocol)
4149
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
5232
length= (uint) my_sprintf(buf,
5233
(buf, ";file_id=%u;block_len=%u", file_id,
4151
5235
protocol->store(buf, length, &my_charset_bin);
4174
fname= my_stpcpy(proc_info, "Making temp file ");
5258
fname= strmov(proc_info, "Making temp file ");
4175
5259
slave_load_file_stem(fname, file_id, server_id, ".data");
4176
thd->set_proc_info(proc_info);
5260
thd_proc_info(thd, proc_info);
4177
5261
if (get_create_or_append())
4179
5263
my_delete(fname, MYF(0)); // old copy may exist already
4180
5264
if ((fd= my_create(fname, CREATE_MODE,
5265
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4182
5266
MYF(MY_WME))) < 0)
4184
5268
rli->report(ERROR_LEVEL, my_errno,
4185
_("Error in %s event: could not create file '%s'"),
5269
"Error in %s event: could not create file '%s'",
4186
5270
get_type_str(), fname);
4190
else if ((fd = my_open(fname, O_WRONLY | O_APPEND,
5274
else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW,
4191
5275
MYF(MY_WME))) < 0)
4193
5277
rli->report(ERROR_LEVEL, my_errno,
4194
_("Error in %s event: could not open file '%s'"),
5278
"Error in %s event: could not open file '%s'",
4195
5279
get_type_str(), fname);
4198
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5282
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4200
5284
rli->report(ERROR_LEVEL, my_errno,
4201
_("Error in %s event: write to '%s' failed"),
5285
"Error in %s event: write to '%s' failed",
4202
5286
get_type_str(), fname);
4246
5333
Delete_file_log_event::write()
5336
#ifndef MYSQL_CLIENT
4249
5337
bool Delete_file_log_event::write(IO_CACHE* file)
4251
unsigned char buf[DELETE_FILE_HEADER_LEN];
5339
uchar buf[DELETE_FILE_HEADER_LEN];
4252
5340
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4253
5341
return (write_header(file, sizeof(buf)) ||
4254
5342
my_b_safe_write(file, buf, sizeof(buf)));
5348
Delete_file_log_event::print()
5352
void Delete_file_log_event::print(FILE* file,
5353
PRINT_EVENT_INFO* print_event_info)
5355
Write_on_release_cache cache(&print_event_info->head_cache, file);
5357
if (print_event_info->short_form)
5359
print_header(&cache, print_event_info, false);
5360
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5362
#endif /* MYSQL_CLIENT */
4259
5365
Delete_file_log_event::pack_info()
5368
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4262
5369
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);
5373
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5374
protocol->store(buf, (int32) length, &my_charset_bin);
4271
5379
Delete_file_log_event::do_apply_event()
4274
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
5382
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5383
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((__unused__)))
4276
5385
char fname[FN_REFLEN+10];
4277
5386
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4278
5387
(void) my_delete(fname, MYF(MY_WME));
4279
my_stpcpy(ext, ".info");
5388
strmov(ext, ".info");
4280
5389
(void) my_delete(fname, MYF(MY_WME));
5392
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4285
5395
/**************************************************************************
4318
5430
Execute_load_log_event::write()
5433
#ifndef MYSQL_CLIENT
4321
5434
bool Execute_load_log_event::write(IO_CACHE* file)
4323
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5436
uchar buf[EXEC_LOAD_HEADER_LEN];
4324
5437
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4325
5438
return (write_header(file, sizeof(buf)) ||
4326
5439
my_b_safe_write(file, buf, sizeof(buf)));
5445
Execute_load_log_event::print()
5449
void Execute_load_log_event::print(FILE* file,
5450
PRINT_EVENT_INFO* print_event_info)
5452
Write_on_release_cache cache(&print_event_info->head_cache, file);
5454
if (print_event_info->short_form)
5456
print_header(&cache, print_event_info, false);
5457
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
4331
5463
Execute_load_log_event::pack_info()
5466
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4334
5467
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);
5471
length= (uint) my_sprintf(buf, (buf, ";file_id=%u", (uint) file_id));
5472
protocol->store(buf, (int32) length, &my_charset_bin);
5564
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4435
5567
/**************************************************************************
4436
5568
Begin_load_query_log_event methods
4437
5569
**************************************************************************/
5571
#ifndef MYSQL_CLIENT
4439
5572
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)
5573
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5574
uint block_len_arg, bool using_trans)
4442
5575
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4445
5578
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4449
5583
Begin_load_query_log_event::
4450
Begin_load_query_log_event(const char* buf, uint32_t len,
5584
Begin_load_query_log_event(const char* buf, uint len,
4451
5585
const Format_description_log_event* desc_event)
4452
5586
:Append_block_log_event(buf, len, desc_event)
5591
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4457
5592
int Begin_load_query_log_event::get_create_or_append() const
4459
5594
return 1; /* create the file */
5596
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5599
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4463
5600
Log_event::enum_skip_reason
4464
5601
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5663
#ifndef MYSQL_CLIENT
4524
5665
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4526
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5667
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4527
5668
int4store(buf, file_id);
4528
5669
int4store(buf + 4, fn_pos_start);
4529
5670
int4store(buf + 4 + 4, fn_pos_end);
4530
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5671
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4531
5672
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5678
void Execute_load_query_log_event::print(FILE* file,
5679
PRINT_EVENT_INFO* print_event_info)
5681
print(file, print_event_info, 0);
5685
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5687
void Execute_load_query_log_event::print(FILE* file,
5688
PRINT_EVENT_INFO* print_event_info,
5689
const char *local_fname)
5691
Write_on_release_cache cache(&print_event_info->head_cache, file);
5693
print_query_header(&cache, print_event_info);
5697
my_b_write(&cache, (uchar*) query, fn_pos_start);
5698
my_b_printf(&cache, " LOCAL INFILE \'");
5699
my_b_printf(&cache, local_fname);
5700
my_b_printf(&cache, "\'");
5701
if (dup_handling == LOAD_DUP_REPLACE)
5702
my_b_printf(&cache, " REPLACE");
5703
my_b_printf(&cache, " INTO");
5704
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5705
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5709
my_b_write(&cache, (uchar*) query, q_len);
5710
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5713
if (!print_event_info->short_form)
5714
my_b_printf(&cache, "# file_id: %d \n", file_id);
5719
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4535
5720
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4537
5722
char *buf, *pos;
5670
6900
const char *const vpart= buf + common_header_len + post_header_len;
5672
6902
/* 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;
6903
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
6904
m_dblen= *(uchar*) ptr_dblen;
5676
6906
/* 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;
6907
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
6908
m_tbllen= *(uchar*) ptr_tbllen;
5680
6910
/* 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;
6911
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
6912
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5683
6913
m_colcnt= net_field_length(&ptr_after_colcnt);
5685
6915
/* 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),
6916
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5687
6917
&m_dbnam, (uint) m_dblen + 1,
5688
6918
&m_tblnam, (uint) m_tbllen + 1,
5689
6919
&m_coltype, (uint) m_colcnt,
5697
6927
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5699
6929
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5700
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
6930
bytes_read= ptr_after_colcnt - (uchar *)buf;
5701
6931
if (bytes_read < event_len)
5703
6933
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5704
6934
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),
6935
uint num_null_bytes= (m_colcnt + 7) / 8;
6936
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5707
6937
&m_null_bits, num_null_bytes,
5708
6938
&m_field_metadata, m_field_metadata_size,
5710
6940
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5711
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
6941
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5712
6942
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5719
6950
Table_map_log_event::~Table_map_log_event()
5721
free(m_meta_memory);
6952
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
6953
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5747
6979
pthread_mutex_unlock(&LOCK_thread_count);
5749
6981
if (!(memory= my_multi_malloc(MYF(MY_WME),
5750
&table_list, (uint) sizeof(RPL_TableList),
6982
&table_list, (uint) sizeof(RPL_TABLE_LIST),
5751
6983
&db_mem, (uint) NAME_LEN + 1,
5752
6984
&tname_mem, (uint) NAME_LEN + 1,
5754
6986
return(HA_ERR_OUT_OF_MEM);
5756
memset(table_list, 0, sizeof(*table_list));
6988
bzero(table_list, sizeof(*table_list));
5757
6989
table_list->db = db_mem;
5758
6990
table_list->alias= table_list->table_name = tname_mem;
5759
6991
table_list->lock_type= TL_WRITE;
5760
6992
table_list->next_global= table_list->next_local= 0;
5761
6993
table_list->table_id= m_table_id;
5762
6994
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);
6995
strmov(table_list->db, rpl_filter->get_rewrite_db(m_dbnam, &dummy_len));
6996
strmov(table_list->table_name, m_tblnam);
5768
7000
if (!rpl_filter->db_ok(table_list->db) ||
5769
7001
(rpl_filter->is_on() && !rpl_filter->tables_ok("", table_list)))
7003
my_free(memory, MYF(MY_WME));
5903
7136
assert(m_dblen < 128);
5904
7137
assert(m_tbllen < 128);
5906
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5907
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
7139
uchar const dbuf[]= { (uchar) m_dblen };
7140
uchar const tbuf[]= { (uchar) m_tbllen };
5909
unsigned char cbuf[sizeof(m_colcnt)];
5910
unsigned char *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
7142
uchar cbuf[sizeof(m_colcnt)];
7143
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5911
7144
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
5914
7147
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);
7149
uchar mbuf[sizeof(m_field_metadata_size)];
7150
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
5919
7152
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
5920
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7153
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
5921
7154
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
5922
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7155
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
5923
7156
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
5924
7157
my_b_safe_write(file, m_coltype, m_colcnt) ||
5925
7158
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
5926
7159
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
5927
7160
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7164
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5932
7167
Print some useful information for the SHOW BINARY LOG information
7171
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5936
7172
void Table_map_log_event::pack_info(Protocol *protocol)
6819
Incident_log_event::Incident_log_event(const char *buf, uint32_t event_len,
8111
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
8114
void Update_rows_log_event::print(FILE *file,
8115
PRINT_EVENT_INFO* print_event_info)
8117
Rows_log_event::print_helper(file, print_event_info, "Update_rows");
8122
Incident_log_event::Incident_log_event(const char *buf, uint event_len,
6820
8123
const Format_description_log_event *descr_event)
6821
8124
: Log_event(buf, descr_event)
6823
uint8_t const common_header_len=
8126
uint8 const common_header_len=
6824
8127
descr_event->common_header_len;
6825
uint8_t const post_header_len=
8128
uint8 const post_header_len=
6826
8129
descr_event->post_header_len[INCIDENT_EVENT-1];
6828
8131
m_incident= static_cast<Incident>(uint2korr(buf + common_header_len));
6829
8132
char const *ptr= buf + common_header_len + post_header_len;
6830
8133
char const *const str_end= buf + event_len;
6831
uint8_t len= 0; // Assignment to keep compiler happy
8134
uint8 len= 0; // Assignment to keep compiler happy
6832
8135
const char *str= NULL; // Assignment to keep compiler happy
6833
8136
read_str(&ptr, str_end, &str, &len);
6834
8137
m_message.str= const_cast<char*>(str);
6896
8216
return(write_str(file, m_message.str, m_message.length));
6899
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint32_t event_len,
8219
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
8220
Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
6900
8221
const Format_description_log_event* description_event)
6901
8222
:Log_event(buf, description_event)
6903
uint8_t header_size= description_event->common_header_len;
8224
uint8 header_size= description_event->common_header_len;
6904
8225
ident_len = event_len - header_size;
6905
8226
set_if_smaller(ident_len,FN_REFLEN-1);
6906
8227
log_ident= buf + header_size;
8234
The default values for these variables should be values that are
8235
*incorrect*, i.e., values that cannot occur in an event. This way,
8236
they will always be printed for the first event.
8238
st_print_event_info::st_print_event_info()
8239
:flags2_inited(0), sql_mode_inited(0),
8240
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8241
lc_time_names_number(~0),
8242
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8243
thread_id(0), thread_id_printed(false),
8244
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8247
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8248
program's startup, but these explicit bzero() is for the day someone
8249
creates dynamic instances.
8251
bzero(db, sizeof(db));
8252
bzero(charset, sizeof(charset));
8253
bzero(time_zone_str, sizeof(time_zone_str));
8256
myf const flags = MYF(MY_WME | MY_NABP);
8257
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8258
open_cached_file(&body_cache, NULL, NULL, 0, flags);