Debian Codegraph @

mysql-test/suite/rpl_nogtid/t/rpl_mysqlbinlog_relay_start_position.test

raw
1 # ==== Purpose ====
2 #
3 # When mysqlbinlog prints a relay log containing multiple FD events,
4 # it should print BINLOG statement for the last one (because that is
5 # the master FD event which may be needed to decode subsequent
6 # events), even when a --start-position specifies a position
7 # after this event.
8 #
9 # ==== Implementation ====
10 #
11 # On master, generate a CREATE TABLE and a DML transaction.
12 #
13 # On slave, find the offset of the DML transaction and the offset of
14 # the last Format_description_log_event. Run mysqlbinlog using this
15 # offset with --start-position. Check that the output contains
16 # '#at <offset-of-last-FD-event>', followed by exactly one BINLOG
17 # statement.
18 #
19 # ==== Related Bugs ====
20 #
21 # BUG#20980932: MYSQLBINLOG GENERATES 'ROLLBACK' AFTER FD EVENT CAUSING
22 # 1782 ERROR
23 #
24 # - Relay logs contain first a slave FD event, then a master FD event.
25 # Between these there is a Previous_gtids_log_event.
26 # When mysqlbinlog uses the --start-position flag, it prints the
27 # FD events appearing in the header.
28 # Before this bugfix, mysqlbinlog stopped printing such header events
29 # when it reached a Previous_gtids_log_event. Therefore, the master FD
30 # event was not printed.
31 # This bugfix ensures that mysqlbinlog does not stop after reaching a
32 # Previous_gtids_log_event. So therefore the master FD event is always
33 # printed.
34 #
35 # Test is binlog_format-agnostic. STATEMENT is simpler here since we
36 # are parsing mysqlbinlog output for BINLOG statements, so if we used
37 # binlog_format='ROW' we might get confused by row events.
38 --source include/have_binlog_format_statement.inc
39 --source include/master-slave.inc
40
41 --echo ==== Initialize ====
42
43 CREATE TABLE t1 (a INT);
44 --source include/sync_slave_sql_with_master.inc
45
46 # Record relay log's position, mysqlbinlog's start-position will be set this
47 # value.
48 --let $relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1)
49 --let $relay_log_pos= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1)
50
51 --source include/rpl_connection_master.inc
52 INSERT INTO t1 VALUES (1);
53 --source include/sync_slave_sql_with_master.inc
54
55 --echo ==== Generate mysqlbinlog output ====
56
57 --let $mysqlbinlog_out= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.out
58 --exec $MYSQL_BINLOG --start-position=$relay_log_pos $server_2_datadir/$relay_log_file > $mysqlbinlog_out
59
60 --echo ==== Test that mysqlbinlog output looks correct ====
61
62 # master's FD is the 4th event.
63 --let $master_fd_offset= query_get_value("SHOW RELAYLOG EVENTS IN '$relay_log_file' LIMIT 3, 1", Pos, 1)
64 --let $assert_text= One BINLOG statement printed after the '#at' for the last FD event
65 --let $assert_file= $mysqlbinlog_out
66 --let $assert_select= ^BINLOG
67 --let $assert_only_after= ^# at $master_fd_offset
68 --let $assert_count= 1
69 --source include/assert_grep.inc
70
71 --echo ==== Test that mysqlbinlog output is processed correctly ====
72
73 # Execute the output using GTID_MODE=ON_PERMISSIVE. If the bug is
74 # there, no Format_description_log_event is printed, and therefore
75 # GTID_NEXT remains AUTOMATIC, so then a GTID is (wrongly)
76 # generated. After the bugfix the Format_description_log_event sets
77 # GTID_NEXT to NOT_YET_DETERMINED, which will switch to Anonymous.
78
79 # If slave threads run while changing GTID_MODE, GTID_MODE causes
80 # binlog rotations which cause slave to rotate relay logs, which may
81 # cause slave to purge the relay log that we are going to process. So
82 # we stop slave threads while changing GTID_MODE and running
83 # mysqlbinlog.
84 --source include/stop_slave.inc
85
86 --source include/rpl_connection_master.inc
87
88 --let $gtid_executed_before= `SELECT @@GLOBAL.GTID_EXECUTED`
89 --let $rpl_gtid_mode= ON_PERMISSIVE
90 --let $rpl_skip_sync= 1
91 --source include/rpl_set_gtid_mode.inc
92
93 --exec $MYSQL_BINLOG --start-position=$relay_log_pos $server_2_datadir/$relay_log_file | $MYSQL
94 --let $assert_text= t1 should has two rows
95 --let $assert_cond= count(*) = 2 FROM t1
96 --source include/assert.inc
97
98 --let $gtid_executed_after= `SELECT @@GLOBAL.GTID_EXECUTED`
99 --let $assert_text= GTID_EXECUTED should not change
100 --let $assert_cond= "$gtid_executed_after" = "$gtid_executed_before"
101 --source include/assert.inc
102
103 --echo ==== Clean up ====
104
105 --source include/rpl_connection_slave.inc
106 --source include/start_slave.inc
107 --source include/rpl_connection_master.inc
108 DROP TABLE t1;
109 --source include/sync_slave_sql_with_master.inc
110
111 --echo # restore gtid_mode
112 --let $include_silent= 1
113 --let $rpl_gtid_mode= $gtid_mode
114 --source include/rpl_set_gtid_mode.inc
115 --let $include_silent= 0
116 --remove_file $mysqlbinlog_out
117
118 --source include/rpl_end.inc