Commit 67b8cb0d authored by Andrei Elkin's avatar Andrei Elkin

bug#47142

merging patches prepared for 5.0 to 5.1-bt. That caused a few changes in the test file
parents 60fc7967 f13ebe12
......@@ -240,3 +240,23 @@ one
1
drop table t1;
start slave;
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
drop table if exists t1;
Warnings:
Note 1051 Unknown table 't1'
flush logs;
stop slave;
reset slave;
start slave until master_log_file='master-bin.000001', master_log_pos=294 /* to stop right before DROP */;
show tables /* t1 must exist */;
Tables_in_test
t1
drop table t1;
stop slave;
reset slave;
reset master;
......@@ -161,4 +161,39 @@ connection slave;
start slave;
sync_with_master;
# Bug #47142 "slave start until" stops 1 event too late in 4.1 to 5.0 replication
#
# testing fixes that refine the start position of prior-5.0 master's event
# and by that provide correct execution of
# START SLAVE UNTIL ... master_log_pos= x;
# Keep the test at the end of the file because it manipulates with binlog files
# to substitute the genuine one with a prepared on 4.1 server.
#
--source include/master-slave-reset.inc
connection master;
drop table if exists t1; # there is create table t1 in bug47142_master-bin.000001
flush logs;
let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/master-bin.000001
--copy_file $MYSQL_TEST_DIR/std_data/bug47142_master-bin.000001 $MYSQLD_DATADIR/master-bin.000001
connection slave;
stop slave;
reset slave;
start slave until master_log_file='master-bin.000001', master_log_pos=294 /* to stop right before DROP */;
--source include/wait_for_slave_sql_to_stop.inc
show tables /* t1 must exist */;
# clean-up of Bug #47142 testing
drop table t1; # drop on slave only, master does not have t1.
stop slave;
reset slave;
connection master;
reset master;
# End of tests
......@@ -2295,10 +2295,22 @@ bool Query_log_event::write(IO_CACHE* file)
int8store(start, table_map_for_update);
start+= 8;
}
if (master_data_written != 0)
{
/*
Q_MASTER_DATA_WRITTEN_CODE only exists in relay logs where the master
has binlog_version<4 and the slave has binlog_version=4. See comment
for master_data_written in log_event.h for details.
*/
*start++= Q_MASTER_DATA_WRITTEN_CODE;
int4store(start, master_data_written);
start+= 4;
}
/*
NOTE: When adding new status vars, please don't forget to update
the MAX_SIZE_LOG_EVENT_STATUS in log_event.h and update function
code_name in this file.
the MAX_SIZE_LOG_EVENT_STATUS in log_event.h and update the function
code_name() in this file.
Here there could be code like
if (command-line-option-which-says-"log_this_variable" && inited)
......@@ -2374,6 +2386,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
auto_increment_offset(thd_arg->variables.auto_increment_offset),
lc_time_names_number(thd_arg->variables.lc_time_names->number),
charset_database_number(0),
master_data_written(0),
table_map_for_update((ulonglong)thd_arg->table_map_for_update)
{
time_t end_time;
......@@ -2498,6 +2511,7 @@ code_name(int code)
case Q_LC_TIME_NAMES_CODE: return "Q_LC_TIME_NAMES_CODE";
case Q_CHARSET_DATABASE_CODE: return "Q_CHARSET_DATABASE_CODE";
case Q_TABLE_MAP_FOR_UPDATE_CODE: return "Q_TABLE_MAP_FOR_UPDATE_CODE";
case Q_MASTER_DATA_WRITTEN_CODE: return "Q_MASTER_DATA_WRITTEN_CODE";
}
sprintf(buf, "CODE#%d", code);
return buf;
......@@ -2535,7 +2549,7 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
flags2_inited(0), sql_mode_inited(0), charset_inited(0),
auto_increment_increment(1), auto_increment_offset(1),
time_zone_len(0), lc_time_names_number(0), charset_database_number(0),
table_map_for_update(0)
table_map_for_update(0), master_data_written(0)
{
ulong data_len;
uint32 tmp;
......@@ -2591,6 +2605,18 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
DBUG_PRINT("info", ("Query_log_event has status_vars_len: %u",
(uint) status_vars_len));
tmp-= 2;
}
else
{
/*
server version < 5.0 / binlog_version < 4 master's event is
relay-logged with storing the original size of the event in
Q_MASTER_DATA_WRITTEN_CODE status variable.
The size is to be restored at reading Q_MASTER_DATA_WRITTEN_CODE-marked
event from the relay log.
*/
DBUG_ASSERT(description_event->binlog_version < 4);
master_data_written= data_written;
}
/*
We have parsed everything we know in the post header for QUERY_EVENT,
......@@ -2682,6 +2708,11 @@ Query_log_event::Query_log_event(const char* buf, uint event_len,
table_map_for_update= uint8korr(pos);
pos+= 8;
break;
case Q_MASTER_DATA_WRITTEN_CODE:
CHECK_SPACE(pos, end, 4);
data_written= master_data_written= uint4korr(pos);
pos+= 4;
break;
default:
/* That's why you must write status vars in growing order of code */
DBUG_PRINT("info",("Query_log_event has unknown status vars (first has\
......
......@@ -263,7 +263,8 @@ struct sql_ex_info
1 + 1 + 255 /* type, length, time_zone */ + \
1 + 2 /* type, lc_time_names_number */ + \
1 + 2 /* type, charset_database_number */ + \
1 + 8 /* type, table_map_for_update */)
1 + 8 /* type, table_map_for_update */ + \
1 + 4 /* type, master_data_written */)
#define MAX_LOG_EVENT_HEADER ( /* in order of Query_log_event::write */ \
LOG_EVENT_HEADER_LEN + /* write_header */ \
QUERY_HEADER_LEN + /* write_data */ \
......@@ -330,6 +331,10 @@ struct sql_ex_info
#define Q_TABLE_MAP_FOR_UPDATE_CODE 9
#define Q_MASTER_DATA_WRITTEN_CODE 10
/* Intvar event post-header */
/* Intvar event data */
#define I_TYPE_OFFSET 0
#define I_VAL_OFFSET 1
......@@ -1620,6 +1625,16 @@ class Query_log_event: public Log_event
statement, for other query statements, this will be zero.
*/
ulonglong table_map_for_update;
/*
Holds the original length of a Query_log_event that comes from a
master of version < 5.0 (i.e., binlog_version < 4). When the IO
thread writes the relay log, it augments the Query_log_event with a
Q_MASTER_DATA_WRITTEN_CODE status_var that holds the original event
length. This field is initialized to non-zero in the SQL thread when
it reads this augmented event. SQL thread does not write
Q_MASTER_DATA_WRITTEN_CODE to the slave's server binlog.
*/
uint32 master_data_written;
#ifndef MYSQL_CLIENT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment