1033
1139
if (!ev || !ev->is_valid())
1143
if (!force_opt) /* then mysqlbinlog dies */
1145
*error= "Found invalid event in binary log";
1148
ev= new Unknown_log_event(buf, description_event);
1036
1150
*error= "Found invalid event in binary log";
1160
Log_event::print_header()
1163
void Log_event::print_header(IO_CACHE* file,
1164
PRINT_EVENT_INFO* print_event_info,
1165
bool is_more __attribute__((unused)))
1168
my_off_t hexdump_from= print_event_info->hexdump_from;
1170
my_b_printf(file, "#");
1171
print_timestamp(file);
1172
my_b_printf(file, " server id %d end_log_pos %s ", server_id,
1173
llstr(log_pos,llbuff));
1175
/* mysqlbinlog --hexdump */
1176
if (print_event_info->hexdump_from)
1178
my_b_printf(file, "\n");
1179
uchar *ptr= (uchar*)temp_buf;
1181
uint4korr(ptr + EVENT_LEN_OFFSET) - LOG_EVENT_MINIMAL_HEADER_LEN;
1184
/* Header len * 4 >= header len * (2 chars + space + extra space) */
1185
char *h, hex_string[LOG_EVENT_MINIMAL_HEADER_LEN*4]= {0};
1186
char *c, char_string[16+1]= {0};
1188
/* Pretty-print event common header if header is exactly 19 bytes */
1189
if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN)
1191
char emit_buf[256]; // Enough for storing one line
1192
my_b_printf(file, "# Position Timestamp Type Master ID "
1193
"Size Master Pos Flags \n");
1194
int const bytes_written=
1195
snprintf(emit_buf, sizeof(emit_buf),
1196
"# %8.8lx %02x %02x %02x %02x %02x "
1197
"%02x %02x %02x %02x %02x %02x %02x %02x "
1198
"%02x %02x %02x %02x %02x %02x\n",
1199
(unsigned long) hexdump_from,
1200
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6],
1201
ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13],
1202
ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]);
1203
assert(bytes_written >= 0);
1204
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1205
my_b_write(file, (uchar*) emit_buf, bytes_written);
1206
ptr += LOG_EVENT_MINIMAL_HEADER_LEN;
1207
hexdump_from += LOG_EVENT_MINIMAL_HEADER_LEN;
1210
/* Rest of event (without common header) */
1211
for (i= 0, c= char_string, h=hex_string;
1215
snprintf(h, 4, "%02x ", *ptr);
1218
*c++= my_isalnum(&my_charset_bin, *ptr) ? *ptr : '.';
1223
my_b_printf() does not support full printf() formats, so we
1224
have to do it this way.
1226
TODO: Rewrite my_b_printf() to support full printf() syntax.
1229
int const bytes_written=
1230
snprintf(emit_buf, sizeof(emit_buf),
1231
"# %8.8lx %-48.48s |%16s|\n",
1232
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1233
hex_string, char_string);
1234
assert(bytes_written >= 0);
1235
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1236
my_b_write(file, (uchar*) emit_buf, bytes_written);
1242
else if (i % 8 == 7) *h++ = ' ';
1249
int const bytes_written=
1250
snprintf(emit_buf, sizeof(emit_buf),
1251
"# %8.8lx %-48.48s |%s|\n",
1252
(unsigned long) (hexdump_from + (i & 0xfffffff0)),
1253
hex_string, char_string);
1254
assert(bytes_written >= 0);
1255
assert(static_cast<size_t>(bytes_written) < sizeof(emit_buf));
1256
my_b_write(file, (uchar*) emit_buf, bytes_written);
1259
need a # to prefix the rest of printouts for example those of
1260
Rows_log_event::print_helper().
1262
my_b_write(file, reinterpret_cast<const uchar*>("# "), 2);
1268
void Log_event::print_base64(IO_CACHE* file,
1269
PRINT_EVENT_INFO* print_event_info,
1272
const uchar *ptr= (const uchar *)temp_buf;
1273
uint32_t size= uint4korr(ptr + EVENT_LEN_OFFSET);
1275
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
1276
char *const tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME));
1278
fprintf(stderr, "\nError: Out of memory. "
1279
"Could not print correct binlog event.\n");
1283
if (base64_encode(ptr, (size_t) size, tmp_str))
1288
if (my_b_tell(file) == 0)
1289
my_b_printf(file, "\nBINLOG '\n");
1291
my_b_printf(file, "%s\n", tmp_str);
1294
my_b_printf(file, "'%s\n", print_event_info->delimiter);
1296
my_free(tmp_str, MYF(0));
1302
Log_event::print_timestamp()
1305
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
1310
#ifdef MYSQL_SERVER // This is always false
1312
localtime_r(ts,(res= &tm_tmp));
1317
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
1327
#endif /* MYSQL_CLIENT */
1330
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1042
1331
inline Log_event::enum_skip_reason
1043
1332
Log_event::continue_group(Relay_log_info *rli)
1936
Query_log_event::print().
1939
print the catalog ??
1941
void Query_log_event::print_query_header(IO_CACHE* file,
1942
PRINT_EVENT_INFO* print_event_info)
1944
// TODO: print the catalog ??
1945
char buff[40],*end; // Enough for SET TIMESTAMP
1946
bool different_db= 1;
1949
if (!print_event_info->short_form)
1951
print_header(file, print_event_info, false);
1952
my_b_printf(file, "\t%s\tthread_id=%lu\texec_time=%lu\terror_code=%d\n",
1953
get_type_str(), (ulong) thread_id, (ulong) exec_time,
1957
if (!(flags & LOG_EVENT_SUPPRESS_USE_F) && db)
1959
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)))
1960
memcpy(print_event_info->db, db, db_len + 1);
1961
if (db[0] && different_db)
1962
my_b_printf(file, "use %s%s\n", db, print_event_info->delimiter);
1965
end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10);
1966
end= strmov(end, print_event_info->delimiter);
1968
my_b_write(file, (uchar*) buff, (uint) (end-buff));
1969
if ((!print_event_info->thread_id_printed ||
1970
((flags & LOG_EVENT_THREAD_SPECIFIC_F) &&
1971
thread_id != print_event_info->thread_id)))
1973
// If --short-form, print deterministic value instead of pseudo_thread_id.
1974
my_b_printf(file,"SET @@session.pseudo_thread_id=%lu%s\n",
1975
short_form ? 999999999 : (ulong)thread_id,
1976
print_event_info->delimiter);
1977
print_event_info->thread_id= thread_id;
1978
print_event_info->thread_id_printed= 1;
1982
If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to
1983
print (remember we don't produce mixed relay logs so there cannot be
1984
5.0 events before that one so there is nothing to reset).
1986
if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */
1988
/* tmp is a bitmask of bits which have changed. */
1989
if (likely(print_event_info->flags2_inited))
1990
/* All bits which have changed */
1991
tmp= (print_event_info->flags2) ^ flags2;
1992
else /* that's the first Query event we read */
1994
print_event_info->flags2_inited= 1;
1995
tmp= ~((uint32_t)0); /* all bits have changed */
1998
if (unlikely(tmp)) /* some bits have changed */
2001
my_b_printf(file, "SET ");
2002
print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2,
2003
"@@session.foreign_key_checks", &need_comma);
2004
print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2,
2005
"@@session.sql_auto_is_null", &need_comma);
2006
print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2,
2007
"@@session.unique_checks", &need_comma);
2008
my_b_printf(file,"%s\n", print_event_info->delimiter);
2009
print_event_info->flags2= flags2;
2014
Now the session variables;
2015
it's more efficient to pass SQL_MODE as a number instead of a
2016
comma-separated list.
2017
FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only
2018
variables (they have no global version; they're not listed in
2019
sql_class.h), The tests below work for pure binlogs or pure relay
2020
logs. Won't work for mixed relay logs but we don't create mixed
2021
relay logs (that is, there is no relay log with a format change
2022
except within the 3 first events, which mysqlbinlog handles
2023
gracefully). So this code should always be good.
2026
if (print_event_info->auto_increment_increment != auto_increment_increment ||
2027
print_event_info->auto_increment_offset != auto_increment_offset)
2029
my_b_printf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu%s\n",
2030
auto_increment_increment,auto_increment_offset,
2031
print_event_info->delimiter);
2032
print_event_info->auto_increment_increment= auto_increment_increment;
2033
print_event_info->auto_increment_offset= auto_increment_offset;
2036
/* TODO: print the catalog when we feature SET CATALOG */
2038
if (likely(charset_inited) &&
2039
(unlikely(!print_event_info->charset_inited ||
2040
memcmp(print_event_info->charset, charset, 6))))
2042
const CHARSET_INFO * const cs_info= get_charset(uint2korr(charset), MYF(MY_WME));
2045
/* for mysql client */
2046
my_b_printf(file, "/*!\\C %s */%s\n",
2047
cs_info->csname, print_event_info->delimiter);
2049
my_b_printf(file,"SET "
2050
"@@session.character_set_client=%d,"
2051
"@@session.collation_connection=%d,"
2052
"@@session.collation_server=%d"
2055
uint2korr(charset+2),
2056
uint2korr(charset+4),
2057
print_event_info->delimiter);
2058
memcpy(print_event_info->charset, charset, 6);
2059
print_event_info->charset_inited= 1;
2063
if (memcmp(print_event_info->time_zone_str, time_zone_str, time_zone_len+1))
2065
my_b_printf(file,"SET @@session.time_zone='%s'%s\n",
2066
time_zone_str, print_event_info->delimiter);
2067
memcpy(print_event_info->time_zone_str, time_zone_str, time_zone_len+1);
2070
if (lc_time_names_number != print_event_info->lc_time_names_number)
2072
my_b_printf(file, "SET @@session.lc_time_names=%d%s\n",
2073
lc_time_names_number, print_event_info->delimiter);
2074
print_event_info->lc_time_names_number= lc_time_names_number;
2076
if (charset_database_number != print_event_info->charset_database_number)
2078
if (charset_database_number)
2079
my_b_printf(file, "SET @@session.collation_database=%d%s\n",
2080
charset_database_number, print_event_info->delimiter);
2082
my_b_printf(file, "SET @@session.collation_database=DEFAULT%s\n",
2083
print_event_info->delimiter);
2084
print_event_info->charset_database_number= charset_database_number;
2089
void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2091
Write_on_release_cache cache(&print_event_info->head_cache, file);
2093
print_query_header(&cache, print_event_info);
2094
my_b_write(&cache, (uchar*) query, q_len);
2095
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
2097
#endif /* MYSQL_CLIENT */
1632
2101
Query_log_event::do_apply_event()
2104
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1634
2106
int Query_log_event::do_apply_event(Relay_log_info const *rli)
1636
2108
return do_apply_event(rli, query, q_len);
1773
2274
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);
2277
rli->report(ERROR_LEVEL, expected_error,
2279
Query partially completed on the master (error on master: %d) \
2280
and was aborted. There is a chance that your master is inconsistent at this \
2281
point. If you are sure that your master is ok, run this query manually on the \
2282
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
2283
START SLAVE; . Query: '%s'", expected_error, thd->query);
1785
2284
thd->is_slave_error= 1;
2289
/* If the query was not ignored, it is printed to the general log */
2290
if (!thd->is_error() || thd->main_da.sql_errno() != ER_SLAVE_IGNORED_TABLE)
2291
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
1790
2293
compare_errors:
1926
2430
return(Log_event::do_shall_skip(rli));
1930
2436
/**************************************************************************
1931
2437
Start_log_event_v3 methods
1932
2438
**************************************************************************/
2440
#ifndef MYSQL_CLIENT
1934
2441
Start_log_event_v3::Start_log_event_v3()
1935
2442
:Log_event(), created(0), binlog_version(BINLOG_VERSION),
1936
2443
artificial_event(0), dont_set_created(0)
1938
2445
memcpy(server_version, ::server_version, ST_SERVER_VER_LEN);
1942
2450
Start_log_event_v3::pack_info()
2453
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
1945
2454
void Start_log_event_v3::pack_info(Protocol *protocol)
1947
2456
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: ");
2457
pos= strmov(buf, "Server ver: ");
2458
pos= strmov(pos, server_version);
2459
pos= strmov(pos, ", Binlog ver: ");
1951
2460
pos= int10_to_str(binlog_version, pos, 10);
1952
2461
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
2467
Start_log_event_v3::print()
2471
void Start_log_event_v3::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
2473
Write_on_release_cache cache(&print_event_info->head_cache, file,
2474
Write_on_release_cache::FLUSH_F);
2476
if (!print_event_info->short_form)
2478
print_header(&cache, print_event_info, false);
2479
my_b_printf(&cache, "\tStart: binlog v %d, server v %s created ",
2480
binlog_version, server_version);
2481
print_timestamp(&cache);
2483
my_b_printf(&cache," at startup");
2484
my_b_printf(&cache, "\n");
2485
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
2486
my_b_printf(&cache, "# Warning: this binlog was not closed properly. "
2487
"Most probably mysqld crashed writing it.\n");
2489
if (!artificial_event && created)
2491
#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND
2493
This is for mysqlbinlog: like in replication, we want to delete the stale
2494
tmp files left by an unclean shutdown of mysqld (temporary tables)
2495
and rollback unfinished transaction.
2496
Probably this can be done with RESET CONNECTION (syntax to be defined).
2498
my_b_printf(&cache,"RESET CONNECTION%s\n", print_event_info->delimiter);
2500
my_b_printf(&cache,"ROLLBACK%s\n", print_event_info->delimiter);
2504
print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER &&
2505
!print_event_info->short_form)
2507
my_b_printf(&cache, "BINLOG '\n");
2508
print_base64(&cache, print_event_info, false);
2509
print_event_info->printed_fd_event= true;
2513
#endif /* MYSQL_CLIENT */
1957
2516
Start_log_event_v3::Start_log_event_v3()
2480
3049
if (need_db && db && db_len)
2482
pos= my_stpcpy(pos, "use `");
3051
pos= strmov(pos, "use `");
2483
3052
memcpy(pos, db, db_len);
2484
pos= my_stpcpy(pos+db_len, "`; ");
3053
pos= strmov(pos+db_len, "`; ");
2487
pos= my_stpcpy(pos, "LOAD DATA ");
3056
pos= strmov(pos, "LOAD DATA ");
2490
3059
*fn_start= pos;
2492
3061
if (check_fname_outside_temp_buf())
2493
pos= my_stpcpy(pos, "LOCAL ");
2494
pos= my_stpcpy(pos, "INFILE '");
3062
pos= strmov(pos, "LOCAL ");
3063
pos= strmov(pos, "INFILE '");
2495
3064
memcpy(pos, fname, fname_len);
2496
pos= my_stpcpy(pos+fname_len, "' ");
3065
pos= strmov(pos+fname_len, "' ");
2498
3067
if (sql_ex.opt_flags & REPLACE_FLAG)
2499
pos= my_stpcpy(pos, " REPLACE ");
3068
pos= strmov(pos, " REPLACE ");
2500
3069
else if (sql_ex.opt_flags & IGNORE_FLAG)
2501
pos= my_stpcpy(pos, " IGNORE ");
3070
pos= strmov(pos, " IGNORE ");
2503
pos= my_stpcpy(pos ,"INTO");
3072
pos= strmov(pos ,"INTO");
2508
pos= my_stpcpy(pos ," Table `");
3077
pos= strmov(pos ," TABLE `");
2509
3078
memcpy(pos, table_name, table_name_len);
2510
3079
pos+= table_name_len;
2512
3081
/* We have to create all optinal fields as the default is not empty */
2513
pos= my_stpcpy(pos, "` FIELDS TERMINATED BY ");
3082
pos= strmov(pos, "` FIELDS TERMINATED BY ");
2514
3083
pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
2515
3084
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
2516
pos= my_stpcpy(pos, " OPTIONALLY ");
2517
pos= my_stpcpy(pos, " ENCLOSED BY ");
3085
pos= strmov(pos, " OPTIONALLY ");
3086
pos= strmov(pos, " ENCLOSED BY ");
2518
3087
pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
2520
pos= my_stpcpy(pos, " ESCAPED BY ");
3089
pos= strmov(pos, " ESCAPED BY ");
2521
3090
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
2523
pos= my_stpcpy(pos, " LINES TERMINATED BY ");
3092
pos= strmov(pos, " LINES TERMINATED BY ");
2524
3093
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
2525
3094
if (sql_ex.line_start_len)
2527
pos= my_stpcpy(pos, " STARTING BY ");
3096
pos= strmov(pos, " STARTING BY ");
2528
3097
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
2531
3100
if ((long) skip_lines > 0)
2533
pos= my_stpcpy(pos, " IGNORE ");
3102
pos= strmov(pos, " IGNORE ");
2534
3103
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2535
pos= my_stpcpy(pos," LINES ");
3104
pos= strmov(pos," LINES ");
2538
3107
if (num_fields)
2541
3110
const char *field= fields;
2542
pos= my_stpcpy(pos, " (");
3111
pos= strmov(pos, " (");
2543
3112
for (i = 0; i < num_fields; i++)
3346
Load_log_event::print()
3350
void Load_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
3352
print(file, print_event_info, 0);
3356
void Load_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info,
3359
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
3361
if (!print_event_info->short_form)
3363
print_header(&cache, print_event_info, false);
3364
my_b_printf(&cache, "\tQuery\tthread_id=%ld\texec_time=%ld\n",
3365
thread_id, exec_time);
3368
bool different_db= 1;
3372
If the database is different from the one of the previous statement, we
3373
need to print the "use" command, and we update the last_db.
3374
But if commented, the "use" is going to be commented so we should not
3377
if ((different_db= memcmp(print_event_info->db, db, db_len + 1)) &&
3379
memcpy(print_event_info->db, db, db_len + 1);
3382
if (db && db[0] && different_db)
3383
my_b_printf(&cache, "%suse %s%s\n",
3384
commented ? "# " : "",
3385
db, print_event_info->delimiter);
3387
if (flags & LOG_EVENT_THREAD_SPECIFIC_F)
3388
my_b_printf(&cache,"%sSET @@session.pseudo_thread_id=%lu%s\n",
3389
commented ? "# " : "", (ulong)thread_id,
3390
print_event_info->delimiter);
3391
my_b_printf(&cache, "%sLOAD DATA ",
3392
commented ? "# " : "");
3393
if (check_fname_outside_temp_buf())
3394
my_b_printf(&cache, "LOCAL ");
3395
my_b_printf(&cache, "INFILE '%-*s' ", fname_len, fname);
3397
if (sql_ex.opt_flags & REPLACE_FLAG)
3398
my_b_printf(&cache," REPLACE ");
3399
else if (sql_ex.opt_flags & IGNORE_FLAG)
3400
my_b_printf(&cache," IGNORE ");
3402
my_b_printf(&cache, "INTO TABLE `%s`", table_name);
3403
my_b_printf(&cache, " FIELDS TERMINATED BY ");
3404
pretty_print_str(&cache, sql_ex.field_term, sql_ex.field_term_len);
3406
if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
3407
my_b_printf(&cache," OPTIONALLY ");
3408
my_b_printf(&cache, " ENCLOSED BY ");
3409
pretty_print_str(&cache, sql_ex.enclosed, sql_ex.enclosed_len);
3411
my_b_printf(&cache, " ESCAPED BY ");
3412
pretty_print_str(&cache, sql_ex.escaped, sql_ex.escaped_len);
3414
my_b_printf(&cache," LINES TERMINATED BY ");
3415
pretty_print_str(&cache, sql_ex.line_term, sql_ex.line_term_len);
3418
if (sql_ex.line_start)
3420
my_b_printf(&cache," STARTING BY ");
3421
pretty_print_str(&cache, sql_ex.line_start, sql_ex.line_start_len);
3423
if ((long) skip_lines > 0)
3424
my_b_printf(&cache, " IGNORE %ld LINES", (long) skip_lines);
3429
const char* field = fields;
3430
my_b_printf(&cache, " (");
3431
for (i = 0; i < num_fields; i++)
3434
my_b_printf(&cache, ",");
3435
my_b_printf(&cache, field);
3437
field += field_lens[i] + 1;
3439
my_b_printf(&cache, ")");
3442
my_b_printf(&cache, "%s\n", print_event_info->delimiter);
3445
#endif /* MYSQL_CLIENT */
3447
#ifndef MYSQL_CLIENT
2773
3450
Load_log_event::set_fields()
3287
4003
Intvar_log_event::write()
4006
#ifndef MYSQL_CLIENT
3290
4007
bool Intvar_log_event::write(IO_CACHE* file)
3292
unsigned char buf[9];
3293
buf[I_TYPE_OFFSET]= (unsigned char) type;
4010
buf[I_TYPE_OFFSET]= (uchar) type;
3294
4011
int8store(buf + I_VAL_OFFSET, val);
3295
4012
return (write_header(file, sizeof(buf)) ||
3296
4013
my_b_safe_write(file, buf, sizeof(buf)));
3301
4019
Intvar_log_event::print()
4023
void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4027
Write_on_release_cache cache(&print_event_info->head_cache, file,
4028
Write_on_release_cache::FLUSH_F);
4030
if (!print_event_info->short_form)
4032
print_header(&cache, print_event_info, false);
4033
my_b_printf(&cache, "\tIntvar\n");
4036
my_b_printf(&cache, "SET ");
4038
case LAST_INSERT_ID_EVENT:
4039
msg="LAST_INSERT_ID";
4041
case INSERT_ID_EVENT:
4044
case INVALID_INT_EVENT:
4045
default: // cannot happen
4049
my_b_printf(&cache, "%s=%s%s\n",
4050
msg, llstr(val,llbuff), print_event_info->delimiter);
3305
4056
Intvar_log_event::do_apply_event()
4059
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
3308
4060
int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
4131
#ifndef MYSQL_CLIENT
3375
4132
bool Rand_log_event::write(IO_CACHE* file)
3377
unsigned char buf[16];
3378
4135
int8store(buf + RAND_SEED1_OFFSET, seed1);
3379
4136
int8store(buf + RAND_SEED2_OFFSET, seed2);
3380
4137
return (write_header(file, sizeof(buf)) ||
3381
4138
my_b_safe_write(file, buf, sizeof(buf)));
4144
void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4146
Write_on_release_cache cache(&print_event_info->head_cache, file,
4147
Write_on_release_cache::FLUSH_F);
4149
char llbuff[22],llbuff2[22];
4150
if (!print_event_info->short_form)
4152
print_header(&cache, print_event_info, false);
4153
my_b_printf(&cache, "\tRand\n");
4155
my_b_printf(&cache, "SET @@RAND_SEED1=%s, @@RAND_SEED2=%s%s\n",
4156
llstr(seed1, llbuff),llstr(seed2, llbuff2),
4157
print_event_info->delimiter);
4159
#endif /* MYSQL_CLIENT */
4162
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3385
4163
int Rand_log_event::do_apply_event(Relay_log_info const *rli)
4234
#ifndef MYSQL_CLIENT
3452
4235
bool Xid_log_event::write(IO_CACHE* file)
3454
4237
return write_header(file, sizeof(xid)) ||
3455
my_b_safe_write(file, (unsigned char*) &xid, sizeof(xid));
4238
my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
4244
void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4246
Write_on_release_cache cache(&print_event_info->head_cache, file,
4247
Write_on_release_cache::FLUSH_F);
4249
if (!print_event_info->short_form)
4252
int64_t10_to_str(xid, buf, 10);
4254
print_header(&cache, print_event_info, false);
4255
my_b_printf(&cache, "\tXid = %s\n", buf);
4257
my_b_printf(&cache, "COMMIT%s\n", print_event_info->delimiter);
4259
#endif /* MYSQL_CLIENT */
4262
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3459
4263
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4265
/* For a slave Xid_log_event is COMMIT */
4266
general_log_print(thd, COM_QUERY,
4267
"COMMIT /* implicit, from Xid_log_event */");
3461
4268
return end_trans(thd, COMMIT);
3638
4449
event_length= sizeof(buf)+ name_len + buf1_length + val_len;
3640
4451
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) ||
4452
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
4453
my_b_safe_write(file, (uchar*) name, name_len) ||
4454
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
3644
4455
my_b_safe_write(file, pos, val_len));
4461
User_var_log_event::print()
4465
void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4467
Write_on_release_cache cache(&print_event_info->head_cache, file,
4468
Write_on_release_cache::FLUSH_F);
4470
if (!print_event_info->short_form)
4472
print_header(&cache, print_event_info, false);
4473
my_b_printf(&cache, "\tUser_var\n");
4476
my_b_printf(&cache, "SET @`");
4477
my_b_write(&cache, (uchar*) name, (uint) (name_len));
4478
my_b_printf(&cache, "`");
4482
my_b_printf(&cache, ":=NULL%s\n", print_event_info->delimiter);
4489
char real_buf[FMT_G_BUFSIZE(14)];
4490
float8get(real_val, val);
4491
sprintf(real_buf, "%.14g", real_val);
4492
my_b_printf(&cache, ":=%s%s\n", real_buf, print_event_info->delimiter);
4496
int64_t10_to_str(uint8korr(val), int_buf, -10);
4497
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
4499
case DECIMAL_RESULT:
4502
int str_len= sizeof(str_buf) - 1;
4503
int precision= (int)val[0];
4504
int scale= (int)val[1];
4505
decimal_digit_t dec_buf[10];
4510
bin2decimal((uchar*) val+2, &dec, precision, scale);
4511
decimal2string(&dec, str_buf, &str_len, 0, 0, 0);
4512
str_buf[str_len]= 0;
4513
my_b_printf(&cache, ":=%s%s\n", str_buf, print_event_info->delimiter);
4519
Let's express the string in hex. That's the most robust way. If we
4520
print it in character form instead, we need to escape it with
4521
character_set_client which we don't know (we will know it in 5.0, but
4522
in 4.1 we don't know it easily when we are printing
4523
User_var_log_event). Explanation why we would need to bother with
4524
character_set_client (quoting Bar):
4525
> Note, the parser doesn't switch to another unescaping mode after
4526
> it has met a character set introducer.
4527
> For example, if an SJIS client says something like:
4528
> SET @a= _ucs2 \0a\0b'
4529
> the string constant is still unescaped according to SJIS, not
4530
> according to UCS2.
4533
const CHARSET_INFO *cs;
4535
if (!(hex_str= (char *)my_alloca(2*val_len+1+2))) // 2 hex digits / byte
4536
break; // no error, as we are 'void'
4537
str_to_hex(hex_str, val, val_len);
4539
For proper behaviour when mysqlbinlog|mysql, we need to explicitely
4540
specify the variable's collation. It will however cause problems when
4541
people want to mysqlbinlog|mysql into another server not supporting the
4542
character set. But there's not much to do about this and it's unlikely.
4544
if (!(cs= get_charset(charset_number, MYF(0))))
4546
Generate an unusable command (=> syntax error) is probably the best
4547
thing we can do here.
4549
my_b_printf(&cache, ":=???%s\n", print_event_info->delimiter);
4551
my_b_printf(&cache, ":=_%s %s COLLATE `%s`%s\n",
4552
cs->csname, hex_str, cs->name,
4553
print_event_info->delimiter);
3650
4568
User_var_log_event::do_apply_event()
4571
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3653
4572
int User_var_log_event::do_apply_event(Relay_log_info const *rli)
3741
4660
return continue_group(rli);
4662
#endif /* !MYSQL_CLIENT */
3745
4665
/**************************************************************************
3746
4666
Slave_log_event methods
3747
4667
**************************************************************************/
4669
#ifdef HAVE_REPLICATION
4671
void Unknown_log_event::print(FILE* file_arg, PRINT_EVENT_INFO* print_event_info)
4673
Write_on_release_cache cache(&print_event_info->head_cache, file_arg);
4675
if (print_event_info->short_form)
4677
print_header(&cache, print_event_info, false);
4678
my_b_printf(&cache, "\n# %s", "Unknown event\n");
4682
#ifndef MYSQL_CLIENT
3749
4683
void Slave_log_event::pack_info(Protocol *protocol)
3751
4685
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=");
4686
pos= strmov(buf, "host=");
4687
pos= strnmov(pos, master_host, HOSTNAME_LENGTH);
4688
pos= strmov(pos, ",port=");
3755
4689
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=");
4690
pos= strmov(pos, ",log=");
4691
pos= strmov(pos, master_log);
4692
pos= strmov(pos, ",pos=");
3759
4693
pos= int64_t10_to_str(master_pos, pos, 10);
3760
4694
protocol->store(buf, pos-buf, &my_charset_bin);
4696
#endif /* !MYSQL_CLIENT */
4699
#ifndef MYSQL_CLIENT
3766
4702
re-write this better without holding both locks at the same time
3776
4712
// TODO: re-write this better without holding both locks at the same time
3777
4713
pthread_mutex_lock(&mi->data_lock);
3778
4714
pthread_mutex_lock(&rli->data_lock);
4715
master_host_len = strlen(mi->host);
4716
master_log_len = strlen(rli->group_master_log_name);
3779
4717
// on OOM, just do not initialize the structure and print the error
3780
4718
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();
4721
master_host = mem_pool + SL_MASTER_HOST_OFFSET ;
4722
memcpy(master_host, mi->host, master_host_len + 1);
4723
master_log = master_host + master_host_len + 1;
4724
memcpy(master_log, rli->group_master_log_name, master_log_len + 1);
4725
master_port = mi->port;
3786
4726
master_pos = rli->group_master_log_pos;
3789
sql_print_error(_("Out of memory while recording slave event"));
4729
sql_print_error("Out of memory while recording slave event");
3790
4730
pthread_mutex_unlock(&rli->data_lock);
3791
4731
pthread_mutex_unlock(&mi->data_lock);
4734
#endif /* !MYSQL_CLIENT */
3796
4737
Slave_log_event::~Slave_log_event()
4739
my_free(mem_pool, MYF(MY_ALLOW_ZERO_PTR));
4744
void Slave_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
4746
Write_on_release_cache cache(&print_event_info->head_cache, file);
4749
if (print_event_info->short_form)
4751
print_header(&cache, print_event_info, false);
4752
my_b_printf(&cache, "\n\
4753
Slave: master_host: '%s' master_port: %d master_log: '%s' master_pos: %s\n",
4754
master_host, master_port, master_log, llstr(master_pos, llbuff));
4756
#endif /* MYSQL_CLIENT */
3802
4759
int Slave_log_event::get_data_size()
3804
return master_host.length() + master_log.length() + 1 + SL_MASTER_HOST_OFFSET;
4761
return master_host_len + master_log_len + 1 + SL_MASTER_HOST_OFFSET;
4765
#ifndef MYSQL_CLIENT
3808
4766
bool Slave_log_event::write(IO_CACHE* file)
3810
4768
ulong event_length= get_data_size();
3813
4771
// log and host are already there
3815
4773
return (write_header(file, event_length) ||
3816
my_b_safe_write(file, (unsigned char*) mem_pool, event_length));
4774
my_b_safe_write(file, (uchar*) mem_pool, event_length));
3820
void Slave_log_event::init_from_mem_pool()
4779
void Slave_log_event::init_from_mem_pool(int data_size)
3822
4781
master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET);
3823
4782
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();
4783
master_host = mem_pool + SL_MASTER_HOST_OFFSET;
4784
master_host_len = strlen(master_host);
4786
master_log = master_host + master_host_len + 1;
4787
if (master_log > mem_pool + data_size)
4792
master_log_len = strlen(master_log);
4796
/** This code is not used, so has not been updated to be format-tolerant. */
4797
Slave_log_event::Slave_log_event(const char* buf, uint event_len)
4798
:Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0)
4800
if (event_len < LOG_EVENT_HEADER_LEN)
4802
event_len -= LOG_EVENT_HEADER_LEN;
4803
if (!(mem_pool = (char*) my_malloc(event_len + 1, MYF(MY_WME))))
4805
memcpy(mem_pool, buf + LOG_EVENT_HEADER_LEN, event_len);
4806
mem_pool[event_len] = 0;
4807
init_from_mem_pool(event_len);
4811
#ifndef MYSQL_CLIENT
3832
4812
int Slave_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
3834
4814
if (mysql_bin_log.is_open())
3835
4815
mysql_bin_log.write(this);
4818
#endif /* !MYSQL_CLIENT */
3840
4821
/**************************************************************************
5003
Create_file_log_event::print()
5007
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info,
5010
Write_on_release_cache cache(&print_event_info->head_cache, file);
5012
if (print_event_info->short_form)
5014
if (enable_local && check_fname_outside_temp_buf())
5015
Load_log_event::print(file, print_event_info);
5021
Load_log_event::print(file, print_event_info,
5022
!check_fname_outside_temp_buf());
5024
That one is for "file_id: etc" below: in mysqlbinlog we want the #, in
5025
SHOW BINLOG EVENTS we don't.
5027
my_b_printf(&cache, "#");
5030
my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len);
5034
void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
5036
print(file, print_event_info, 0);
5038
#endif /* MYSQL_CLIENT */
3996
5042
Create_file_log_event::pack_info()
5045
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
3999
5046
void Create_file_log_event::pack_info(Protocol *protocol)
4001
5048
char buf[NAME_LEN*2 + 30 + 21*2], *pos;
4002
pos= my_stpcpy(buf, "db=");
5049
pos= strmov(buf, "db=");
4003
5050
memcpy(pos, db, db_len);
4004
pos= my_stpcpy(pos + db_len, ";table=");
5051
pos= strmov(pos + db_len, ";table=");
4005
5052
memcpy(pos, table_name, table_name_len);
4006
pos= my_stpcpy(pos + table_name_len, ";file_id=");
5053
pos= strmov(pos + table_name_len, ";file_id=");
4007
5054
pos= int10_to_str((long) file_id, pos, 10);
4008
pos= my_stpcpy(pos, ";block_len=");
5055
pos= strmov(pos, ";block_len=");
4009
5056
pos= int10_to_str((long) block_len, pos, 10);
4010
5057
protocol->store(buf, (uint) (pos-buf), &my_charset_bin);
5059
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4015
5063
Create_file_log_event::do_apply_event()
5066
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4018
5067
int Create_file_log_event::do_apply_event(Relay_log_info const *rli)
4020
5069
char proc_info[17+FN_REFLEN+10], *fname_buf;
4026
5075
memset(&file, 0, sizeof(file));
4027
fname_buf= my_stpcpy(proc_info, "Making temp file ");
5076
fname_buf= strmov(proc_info, "Making temp file ");
4028
5077
ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4029
thd->set_proc_info(proc_info);
5078
thd_proc_info(thd, proc_info);
4030
5079
my_delete(fname_buf, MYF(0)); // old copy may exist already
4031
5080
if ((fd= my_create(fname_buf, CREATE_MODE,
5081
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4033
5082
MYF(MY_WME))) < 0 ||
4034
5083
init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0,
4035
5084
MYF(MY_WME|MY_NABP)))
4037
5086
rli->report(ERROR_LEVEL, my_errno,
4038
_("Error in Create_file event: could not open file '%s'"),
5087
"Error in Create_file event: could not open file '%s'",
4043
5092
// a trick to avoid allocating another buffer
4044
5093
fname= fname_buf;
4045
fname_len= (uint) (my_stpcpy(ext, ".data") - fname);
5094
fname_len= (uint) (strmov(ext, ".data") - fname);
4046
5095
if (write_base(&file))
4048
my_stpcpy(ext, ".info"); // to have it right in the error message
5097
strmov(ext, ".info"); // to have it right in the error message
4049
5098
rli->report(ERROR_LEVEL, my_errno,
4050
_("Error in Create_file event: could not write to file '%s'"),
5099
"Error in Create_file event: could not write to file '%s'",
4054
5103
end_io_cache(&file);
4055
5104
my_close(fd, MYF(0));
4057
5106
// fname_buf now already has .data, not .info, because we did our trick
4058
5107
my_delete(fname_buf, MYF(0)); // old copy may exist already
4059
5108
if ((fd= my_create(fname_buf, CREATE_MODE,
5109
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4063
5112
rli->report(ERROR_LEVEL, my_errno,
4064
_("Error in Create_file event: could not open file '%s'"),
5113
"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)))
5117
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4070
5119
rli->report(ERROR_LEVEL, my_errno,
4071
_("Error in Create_file event: write to '%s' failed"),
5120
"Error in Create_file event: write to '%s' failed",
4092
5142
Append_block_log_event ctor
5145
#ifndef MYSQL_CLIENT
4095
5146
Append_block_log_event::Append_block_log_event(THD *thd_arg,
4096
5147
const char *db_arg,
4097
unsigned char *block_arg,
4098
uint32_t block_len_arg,
4099
5150
bool using_trans)
4100
5151
:Log_event(thd_arg,0, using_trans), block(block_arg),
4101
5152
block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
4107
5159
Append_block_log_event ctor
4110
Append_block_log_event::Append_block_log_event(const char* buf, uint32_t len,
5162
Append_block_log_event::Append_block_log_event(const char* buf, uint len,
4111
5163
const Format_description_log_event* description_event)
4112
5164
:Log_event(buf, description_event),block(0)
4114
5166
uint8_t common_header_len= description_event->common_header_len;
4115
5167
uint8_t append_block_header_len=
4116
5168
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
4117
uint32_t total_header_len= common_header_len+append_block_header_len;
5169
uint total_header_len= common_header_len+append_block_header_len;
4118
5170
if (len < total_header_len)
4120
5172
file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET);
4121
block= (unsigned char*)buf + total_header_len;
5173
block= (uchar*)buf + total_header_len;
4122
5174
block_len= len - total_header_len;
4128
5180
Append_block_log_event::write()
5183
#ifndef MYSQL_CLIENT
4131
5184
bool Append_block_log_event::write(IO_CACHE* file)
4133
unsigned char buf[APPEND_BLOCK_HEADER_LEN];
5186
uchar buf[APPEND_BLOCK_HEADER_LEN];
4134
5187
int4store(buf + AB_FILE_ID_OFFSET, file_id);
4135
5188
return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
4136
5189
my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
4137
my_b_safe_write(file, (unsigned char*) block, block_len));
5190
my_b_safe_write(file, (uchar*) block, block_len));
5196
Append_block_log_event::print()
5200
void Append_block_log_event::print(FILE* file,
5201
PRINT_EVENT_INFO* print_event_info)
5203
Write_on_release_cache cache(&print_event_info->head_cache, file);
5205
if (print_event_info->short_form)
5207
print_header(&cache, print_event_info, false);
5208
my_b_printf(&cache, "\n#%s: file_id: %d block_len: %d\n",
5209
get_type_str(), file_id, block_len);
5211
#endif /* MYSQL_CLIENT */
4142
5215
Append_block_log_event::pack_info()
5218
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4145
5219
void Append_block_log_event::pack_info(Protocol *protocol)
4149
5223
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id,
4151
5225
protocol->store(buf, length, &my_charset_bin);
4174
fname= my_stpcpy(proc_info, "Making temp file ");
5248
fname= strmov(proc_info, "Making temp file ");
4175
5249
slave_load_file_stem(fname, file_id, server_id, ".data");
4176
thd->set_proc_info(proc_info);
5250
thd_proc_info(thd, proc_info);
4177
5251
if (get_create_or_append())
4179
5253
my_delete(fname, MYF(0)); // old copy may exist already
4180
5254
if ((fd= my_create(fname, CREATE_MODE,
5255
O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW,
4182
5256
MYF(MY_WME))) < 0)
4184
5258
rli->report(ERROR_LEVEL, my_errno,
4185
_("Error in %s event: could not create file '%s'"),
5259
"Error in %s event: could not create file '%s'",
4186
5260
get_type_str(), fname);
4190
else if ((fd = my_open(fname, O_WRONLY | O_APPEND,
5264
else if ((fd = my_open(fname, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW,
4191
5265
MYF(MY_WME))) < 0)
4193
5267
rli->report(ERROR_LEVEL, my_errno,
4194
_("Error in %s event: could not open file '%s'"),
5268
"Error in %s event: could not open file '%s'",
4195
5269
get_type_str(), fname);
4198
if (my_write(fd, (unsigned char*) block, block_len, MYF(MY_WME+MY_NABP)))
5272
if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
4200
5274
rli->report(ERROR_LEVEL, my_errno,
4201
_("Error in %s event: write to '%s' failed"),
5275
"Error in %s event: write to '%s' failed",
4202
5276
get_type_str(), fname);
4246
5323
Delete_file_log_event::write()
5326
#ifndef MYSQL_CLIENT
4249
5327
bool Delete_file_log_event::write(IO_CACHE* file)
4251
unsigned char buf[DELETE_FILE_HEADER_LEN];
5329
uchar buf[DELETE_FILE_HEADER_LEN];
4252
5330
int4store(buf + DF_FILE_ID_OFFSET, file_id);
4253
5331
return (write_header(file, sizeof(buf)) ||
4254
5332
my_b_safe_write(file, buf, sizeof(buf)));
5338
Delete_file_log_event::print()
5342
void Delete_file_log_event::print(FILE* file,
5343
PRINT_EVENT_INFO* print_event_info)
5345
Write_on_release_cache cache(&print_event_info->head_cache, file);
5347
if (print_event_info->short_form)
5349
print_header(&cache, print_event_info, false);
5350
my_b_printf(&cache, "\n#Delete_file: file_id=%u\n", file_id);
5352
#endif /* MYSQL_CLIENT */
4259
5355
Delete_file_log_event::pack_info()
5358
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4262
5359
void Delete_file_log_event::pack_info(Protocol *protocol)
4266
5363
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4267
5364
protocol->store(buf, (int32_t) length, &my_charset_bin);
4271
5369
Delete_file_log_event::do_apply_event()
5372
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4274
5373
int Delete_file_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
4276
5375
char fname[FN_REFLEN+10];
4277
5376
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
4278
5377
(void) my_delete(fname, MYF(MY_WME));
4279
my_stpcpy(ext, ".info");
5378
strmov(ext, ".info");
4280
5379
(void) my_delete(fname, MYF(MY_WME));
5382
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4285
5385
/**************************************************************************
4318
5420
Execute_load_log_event::write()
5423
#ifndef MYSQL_CLIENT
4321
5424
bool Execute_load_log_event::write(IO_CACHE* file)
4323
unsigned char buf[EXEC_LOAD_HEADER_LEN];
5426
uchar buf[EXEC_LOAD_HEADER_LEN];
4324
5427
int4store(buf + EL_FILE_ID_OFFSET, file_id);
4325
5428
return (write_header(file, sizeof(buf)) ||
4326
5429
my_b_safe_write(file, buf, sizeof(buf)));
5435
Execute_load_log_event::print()
5439
void Execute_load_log_event::print(FILE* file,
5440
PRINT_EVENT_INFO* print_event_info)
5442
Write_on_release_cache cache(&print_event_info->head_cache, file);
5444
if (print_event_info->short_form)
5446
print_header(&cache, print_event_info, false);
5447
my_b_printf(&cache, "\n#Exec_load: file_id=%d\n",
4331
5453
Execute_load_log_event::pack_info()
5456
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4334
5457
void Execute_load_log_event::pack_info(Protocol *protocol)
4338
5461
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
4339
5462
protocol->store(buf, (int32_t) length, &my_charset_bin);
5554
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
4435
5557
/**************************************************************************
4436
5558
Begin_load_query_log_event methods
4437
5559
**************************************************************************/
5561
#ifndef MYSQL_CLIENT
4439
5562
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)
5563
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, uchar* block_arg,
5564
uint block_len_arg, bool using_trans)
4442
5565
:Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
4445
5568
file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
4449
5573
Begin_load_query_log_event::
4450
Begin_load_query_log_event(const char* buf, uint32_t len,
5574
Begin_load_query_log_event(const char* buf, uint len,
4451
5575
const Format_description_log_event* desc_event)
4452
5576
:Append_block_log_event(buf, len, desc_event)
5581
#if defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4457
5582
int Begin_load_query_log_event::get_create_or_append() const
4459
5584
return 1; /* create the file */
5586
#endif /* defined( HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
5589
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
4463
5590
Log_event::enum_skip_reason
4464
5591
Begin_load_query_log_event::do_shall_skip(Relay_log_info *rli)
5653
#ifndef MYSQL_CLIENT
4524
5655
Execute_load_query_log_event::write_post_header_for_derived(IO_CACHE* file)
4526
unsigned char buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
5657
uchar buf[EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN];
4527
5658
int4store(buf, file_id);
4528
5659
int4store(buf + 4, fn_pos_start);
4529
5660
int4store(buf + 4 + 4, fn_pos_end);
4530
*(buf + 4 + 4 + 4)= (unsigned char) dup_handling;
5661
*(buf + 4 + 4 + 4)= (uchar) dup_handling;
4531
5662
return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
5668
void Execute_load_query_log_event::print(FILE* file,
5669
PRINT_EVENT_INFO* print_event_info)
5671
print(file, print_event_info, 0);
5675
Prints the query as LOAD DATA LOCAL and with rewritten filename.
5677
void Execute_load_query_log_event::print(FILE* file,
5678
PRINT_EVENT_INFO* print_event_info,
5679
const char *local_fname)
5681
Write_on_release_cache cache(&print_event_info->head_cache, file);
5683
print_query_header(&cache, print_event_info);
5687
my_b_write(&cache, (uchar*) query, fn_pos_start);
5688
my_b_printf(&cache, " LOCAL INFILE \'");
5689
my_b_printf(&cache, local_fname);
5690
my_b_printf(&cache, "\'");
5691
if (dup_handling == LOAD_DUP_REPLACE)
5692
my_b_printf(&cache, " REPLACE");
5693
my_b_printf(&cache, " INTO");
5694
my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end);
5695
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5699
my_b_write(&cache, (uchar*) query, q_len);
5700
my_b_printf(&cache, "\n%s\n", print_event_info->delimiter);
5703
if (!print_event_info->short_form)
5704
my_b_printf(&cache, "# file_id: %d \n", file_id);
5709
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
4535
5710
void Execute_load_query_log_event::pack_info(Protocol *protocol)
4537
5712
char *buf, *pos;
5670
6890
const char *const vpart= buf + common_header_len + post_header_len;
5672
6892
/* 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;
6893
uchar const *const ptr_dblen= (uchar const*)vpart + 0;
6894
m_dblen= *(uchar*) ptr_dblen;
5676
6896
/* 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;
6897
uchar const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
6898
m_tbllen= *(uchar*) ptr_tbllen;
5680
6900
/* 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;
6901
uchar const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
6902
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
5683
6903
m_colcnt= net_field_length(&ptr_after_colcnt);
5685
6905
/* 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),
6906
m_memory= (uchar*) my_multi_malloc(MYF(MY_WME),
5687
6907
&m_dbnam, (uint) m_dblen + 1,
5688
6908
&m_tblnam, (uint) m_tbllen + 1,
5689
6909
&m_coltype, (uint) m_colcnt,
5697
6917
memcpy(m_coltype, ptr_after_colcnt, m_colcnt);
5699
6919
ptr_after_colcnt= ptr_after_colcnt + m_colcnt;
5700
bytes_read= ptr_after_colcnt - (unsigned char *)buf;
6920
bytes_read= ptr_after_colcnt - (uchar *)buf;
5701
6921
if (bytes_read < event_len)
5703
6923
m_field_metadata_size= net_field_length(&ptr_after_colcnt);
5704
6924
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),
6925
uint num_null_bytes= (m_colcnt + 7) / 8;
6926
m_meta_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
5707
6927
&m_null_bits, num_null_bytes,
5708
6928
&m_field_metadata, m_field_metadata_size,
5710
6930
memcpy(m_field_metadata, ptr_after_colcnt, m_field_metadata_size);
5711
ptr_after_colcnt= (unsigned char*)ptr_after_colcnt + m_field_metadata_size;
6931
ptr_after_colcnt= (uchar*)ptr_after_colcnt + m_field_metadata_size;
5712
6932
memcpy(m_null_bits, ptr_after_colcnt, num_null_bytes);
5719
6940
Table_map_log_event::~Table_map_log_event()
5721
free(m_meta_memory);
6942
my_free(m_meta_memory, MYF(MY_ALLOW_ZERO_PTR));
6943
my_free(m_memory, MYF(MY_ALLOW_ZERO_PTR));
5903
7126
assert(m_dblen < 128);
5904
7127
assert(m_tbllen < 128);
5906
unsigned char const dbuf[]= { (unsigned char) m_dblen };
5907
unsigned char const tbuf[]= { (unsigned char) m_tbllen };
7129
uchar const dbuf[]= { (uchar) m_dblen };
7130
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);
7132
uchar cbuf[sizeof(m_colcnt)];
7133
uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt);
5911
7134
assert(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf));
5914
7137
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);
7139
uchar mbuf[sizeof(m_field_metadata_size)];
7140
uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
5919
7142
return (my_b_safe_write(file, dbuf, sizeof(dbuf)) ||
5920
my_b_safe_write(file, (const unsigned char*)m_dbnam, m_dblen+1) ||
7143
my_b_safe_write(file, (const uchar*)m_dbnam, m_dblen+1) ||
5921
7144
my_b_safe_write(file, tbuf, sizeof(tbuf)) ||
5922
my_b_safe_write(file, (const unsigned char*)m_tblnam, m_tbllen+1) ||
7145
my_b_safe_write(file, (const uchar*)m_tblnam, m_tbllen+1) ||
5923
7146
my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
5924
7147
my_b_safe_write(file, m_coltype, m_colcnt) ||
5925
7148
my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
5926
7149
my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
5927
7150
my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
7154
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5932
7157
Print some useful information for the SHOW BINARY LOG information
7161
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
5936
7162
void Table_map_log_event::pack_info(Protocol *protocol)
6905
8215
set_if_smaller(ident_len,FN_REFLEN-1);
6906
8216
log_ident= buf + header_size;
8223
The default values for these variables should be values that are
8224
*incorrect*, i.e., values that cannot occur in an event. This way,
8225
they will always be printed for the first event.
8227
st_print_event_info::st_print_event_info()
8228
:flags2_inited(0), sql_mode_inited(0),
8229
auto_increment_increment(0),auto_increment_offset(0), charset_inited(0),
8230
lc_time_names_number(~0),
8231
charset_database_number(ILLEGAL_CHARSET_INFO_NUMBER),
8232
thread_id(0), thread_id_printed(false),
8233
base64_output_mode(BASE64_OUTPUT_UNSPEC), printed_fd_event(false)
8236
Currently we only use static PRINT_EVENT_INFO objects, so zeroed at
8237
program's startup, but these explicit memset() is for the day someone
8238
creates dynamic instances.
8240
memset(db, 0, sizeof(db));
8241
memset(charset, 0, sizeof(charset));
8242
memset(time_zone_str, 0, sizeof(time_zone_str));
8245
myf const flags = MYF(MY_WME | MY_NABP);
8246
open_cached_file(&head_cache, NULL, NULL, 0, flags);
8247
open_cached_file(&body_cache, NULL, NULL, 0, flags);