File: rpl_mysqlbinlog_relay_start_position.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (118 lines) | stat: -rw-r--r-- 4,545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# ==== Purpose ====
#
# When mysqlbinlog prints a relay log containing multiple FD events,
# it should print BINLOG statement for the last one (because that is
# the master FD event which may be needed to decode subsequent
# events), even when a --start-position specifies a position
# after this event.
#
# ==== Implementation ====
#
# On master, generate a CREATE TABLE and a DML transaction.
#
# On slave, find the offset of the DML transaction and the offset of
# the last Format_description_log_event.  Run mysqlbinlog using this
# offset with --start-position.  Check that the output contains
# '#at <offset-of-last-FD-event>', followed by exactly one BINLOG
# statement.
#
# ==== Related Bugs ====
#
# BUG#20980932: MYSQLBINLOG GENERATES 'ROLLBACK' AFTER FD EVENT CAUSING
#               1782 ERROR
#
# - Relay logs contain first a slave FD event, then a master FD event.
#   Between these there is a Previous_gtids_log_event.
#   When mysqlbinlog uses the --start-position flag, it prints the
#   FD events appearing in the header.
#   Before this bugfix, mysqlbinlog stopped printing such header events
#   when it reached a Previous_gtids_log_event. Therefore, the master FD
#   event was not printed.
#   This bugfix ensures that mysqlbinlog does not stop after reaching a
#   Previous_gtids_log_event. So therefore the master FD event is always
#   printed.
#
# Test is binlog_format-agnostic. STATEMENT is simpler here since we
# are parsing mysqlbinlog output for BINLOG statements, so if we used
# binlog_format='ROW' we might get confused by row events.
--source include/have_binlog_format_statement.inc
--source include/master-slave.inc

--echo ==== Initialize ====

CREATE TABLE t1 (a INT);
--source include/sync_slave_sql_with_master.inc

# Record relay log's position, mysqlbinlog's start-position will be set this
# value.
--let $relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1)
--let $relay_log_pos= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1)

--source include/rpl_connection_master.inc
INSERT INTO t1 VALUES (1);
--source include/sync_slave_sql_with_master.inc

--echo ==== Generate mysqlbinlog output ====

--let $mysqlbinlog_out= $MYSQLTEST_VARDIR/tmp/mysqlbinlog.out
--exec $MYSQL_BINLOG --start-position=$relay_log_pos $server_2_datadir/$relay_log_file > $mysqlbinlog_out

--echo ==== Test that mysqlbinlog output looks correct ====

# master's FD is the 4th event.
--let $master_fd_offset= query_get_value("SHOW RELAYLOG EVENTS IN '$relay_log_file' LIMIT 3, 1", Pos, 1)
--let $assert_text= One BINLOG statement printed after the '#at' for the last FD event
--let $assert_file= $mysqlbinlog_out
--let $assert_select= ^BINLOG
--let $assert_only_after= ^# at $master_fd_offset
--let $assert_count= 1
--source include/assert_grep.inc

--echo ==== Test that mysqlbinlog output is processed correctly ====

# Execute the output using GTID_MODE=ON_PERMISSIVE. If the bug is
# there, no Format_description_log_event is printed, and therefore
# GTID_NEXT remains AUTOMATIC, so then a GTID is (wrongly)
# generated. After the bugfix the Format_description_log_event sets
# GTID_NEXT to NOT_YET_DETERMINED, which will switch to Anonymous.

# If slave threads run while changing GTID_MODE, GTID_MODE causes
# binlog rotations which cause slave to rotate relay logs, which may
# cause slave to purge the relay log that we are going to process. So
# we stop slave threads while changing GTID_MODE and running
# mysqlbinlog.
--source include/stop_slave.inc

--source include/rpl_connection_master.inc

--let $gtid_executed_before= `SELECT @@GLOBAL.GTID_EXECUTED`
--let $rpl_gtid_mode= ON_PERMISSIVE
--let $rpl_skip_sync= 1
--source include/rpl_set_gtid_mode.inc

--exec $MYSQL_BINLOG --start-position=$relay_log_pos $server_2_datadir/$relay_log_file | $MYSQL
--let $assert_text= t1 should has two rows
--let $assert_cond= count(*) = 2 FROM t1
--source include/assert.inc

--let $gtid_executed_after= `SELECT @@GLOBAL.GTID_EXECUTED`
--let $assert_text= GTID_EXECUTED should not change
--let $assert_cond= "$gtid_executed_after" = "$gtid_executed_before"
--source include/assert.inc

--echo ==== Clean up ====

--source include/rpl_connection_slave.inc
--source include/start_slave.inc
--source include/rpl_connection_master.inc
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc

--echo # restore gtid_mode
--let $include_silent= 1
--let $rpl_gtid_mode= $gtid_mode
--source include/rpl_set_gtid_mode.inc
--let $include_silent= 0
--remove_file $mysqlbinlog_out

--source include/rpl_end.inc