1# Requires statement logging
2
3# Clean up old slave's binlogs.
4# The slave is started with --log-slave-updates
5# and this test does SHOW BINLOG EVENTS on the slave's
6# binlog. But previous tests can influence the current test's
7# binlog (e.g. a temporary table in the previous test has not
8# been explicitly deleted, and at the beginning of the current
9# test the slave immediately writes DROP TEMPORARY TABLE this_old_table).
10# We wait for the slave to have written all he wants to the binlog
11# (otherwise RESET MASTER may come too early).
12--source include/sync_slave_sql_with_master.inc
13source include/stop_slave.inc;
14--source include/wait_for_slave_to_stop.inc
15reset master;
16reset slave;
17start slave;
18--source include/wait_for_slave_to_start.inc
19
20let $VERSION=`select version()`;
21
22connection master;
23eval create table t1(n int not null auto_increment primary key)ENGINE=$engine_type;
24insert into t1 values (NULL);
25drop table t1;
26let $LOAD_FILE= ../../std_data/words.dat;
27if (!`SELECT length(load_file('$LOAD_FILE'))`){
28  let $LOAD_FILE= ../$LOAD_FILE;
29}
30eval create table t1 (word char(20) not null)ENGINE=$engine_type;
31--replace_result $LOAD_FILE LOAD_FILE
32eval load data infile '$LOAD_FILE' into table t1 ignore 1 lines;
33select count(*) from t1;
34source include/show_binlog_events.inc;
35
36let $binlog_limit= 1;
37if (!`SELECT COUNT(*) = 0 OR VARIABLE_VALUE != 'ON' FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'GTID_MODE'`)
38{
39  # if GTID_MODE=ON, there is the extra event entry the binary log: Gtid_log_event
40  --let $binlog_limit= 2,1
41}
42
43source include/show_binlog_events.inc;
44--let $from_event= 1
45--let $number_of_events= 4
46if (!`SELECT COUNT(*) = 0 OR VARIABLE_VALUE != 'ON' FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'GTID_MODE'`)
47{
48  # if GTID_MODE=ON, there is the extra event entry the binary log: Gtid_log_event
49  --let $from_event= `SELECT $from_event * 2 + 1`
50  --let $number_of_events= `SELECT $number_of_events * 2 - 2`
51}
52let $binlog_limit= $from_event,$number_of_events;
53source include/show_binlog_events.inc;
54let $binlog_limit=;
55flush logs;
56
57# We need an extra update before doing save_master_pos.
58# Otherwise, an unlikely scenario may occur:
59# * When the master's binlog_dump thread reads the end of master-bin.001,
60# it send the rotate event which is at this end, plus a fake rotate event
61# because it's starting to read a new binlog.
62# save_master_pos will record the position of the first of the two rotate
63# (because the fake one is not in the master's binlog anyway).
64# * Later the slave waits for the position of the first rotate event,
65# and it may quickly stop (in 'slave stop') without having received the fake
66# one.
67# So, depending on a few milliseconds, we end up with 2 rotate events in the
68# relay log or one, which influences the output of SHOW SLAVE STATUS, making
69# it not predictable and causing random test failures.
70# To make it predictable, we do a useless update now, but which has the
71# interest of making the slave catch both rotate events.
72
73eval create table t3 (a int)ENGINE=$engine_type;
74
75# Sync slave and force it to start on another binary log
76
77#show rows of t1 on master
78connection master;
79select * from t1 order by 1 asc;
80
81--source include/sync_slave_sql_with_master.inc
82
83#check t1 on slave to ensure whether it's identical with on master
84select * from t1 order by 1 asc;
85flush logs;
86source include/stop_slave.inc;
87source include/start_slave.inc;
88connection master;
89
90# Create some entries for second log
91
92eval create table t2 (n int)ENGINE=$engine_type;
93insert into t2 values (1);
94source include/show_binlog_events.inc;
95
96let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
97source include/show_binlog_events.inc;
98
99--replace_column 2 #
100show binary logs;
101--source include/sync_slave_sql_with_master.inc
102--replace_column 2 #
103show binary logs;
104
105let $binlog_file=;
106source include/show_binlog_events.inc;
107
108let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
109source include/show_binlog_events.inc;
110let $binlog_file=;
111
112source include/check_slave_is_running.inc;
113
114# Need to recode the following
115
116#show new master for slave with master_log_file='master-bin.000001' and master_log_pos=4 and  master_server_id=1;
117#show new master for slave with master_log_file='master-bin.000001' and master_log_pos=79 and master_server_id=1;
118#show new master for slave with master_log_file='master-bin.000001' and master_log_pos=311 and master_server_id=1;
119#show new master for slave with master_log_file='master-bin.000002' and master_log_pos=4 and master_server_id=1;
120#show new master for slave with master_log_file='master-bin.000002' and master_log_pos=122 and master_server_id=1;
121
122--error 1220
123show binlog events in 'slave-bin.000005' from 4;
124
125connection master;
126
127# The table drops caused Cluster Replication wrapper to fail as event ID would never be the same.# Moving drops here.
128
129DROP TABLE t1;
130DROP TABLE t2;
131DROP TABLE t3;
132
133#
134# Bug #6880: LAST_INSERT_ID() within a statement
135#
136
137# Reset binlog so that show binlog events will not show the tests
138# above.
139source include/rpl_reset.inc;
140connection master;
141
142create table t1(a int auto_increment primary key, b int);
143insert into t1 values (NULL, 1);
144set insert_id=5;
145insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id());
146source include/show_binlog_events.inc;
147select * from t1;
148drop table t1;
149
150# End of 4.1 tests
151
152--source include/sync_slave_sql_with_master.inc
153