Debian Codegraph @

mysql-test/suite/binlog/t/binlog_mysqlbinlog_4g_start_position.test

raw
1 ###############################################################################
2 # === Purpose ===
3 #
4 # The pupose of this test is to accept a value for --start position in mysqlbinlog greater than
5 # 4GiB when reading a file and generate error for the same when reading from remote
6 # server.
7 #
8 # === Requirements ===
9 #
10 # 1. mysqlbinlog should accept a value for --start-position greater than 4 GiB
11 # when reading a local file.
12 # 2. mysqlbinlog should generate an error when --start-position is greater
13 # than 4 GiB and it is reading from a remote server
14 #
15 # === Implementation ===
16 #
17 # 1) Prepare a sample table and insert values.
18 # 2) Prepare a similar table like before created.
19 # 3) Flushing logs to start a new fresh log.
20 # 4) Get the name of binary log.
21 # 5) Run a query to get events greater than 4GB.
22 # 6) Get the start position of the 14th event.
23 # 7) Verify that the position is actually bigger than 4 GiB.
24 # 8) Run mysqlbinlog.
25 # 9) Checking the error message that will be generated when it is connected to remote.
26 # 10) Cleanup.
27 #
28 # === Reference ===
29 #
30 # Bug#21498994: mysqlbinlog is unable to read events when --start-position
31 # value is greater than 4GB
32 #
33 ###############################################################################
34
35 # Bug #34847851
36 --source include/not_windows.inc
37 --source include/big_test.inc
38 --source include/have_binlog_format_row.inc
39
40 --echo #
41 --echo # 1) Prepare a sample table and insert values.
42 --echo #
43 CREATE TABLE t1(f1 LONGTEXT);
44 INSERT INTO t1 VALUES (REPEAT('a', 1073741824/2));
45
46 --echo #
47 --echo # 2) Prepare a similar table like before created.
48 --echo #
49 CREATE TABLE t2 LIKE t1;
50
51 --echo #
52 --echo # 3) Flushing logs to start a new fresh log.
53 --echo #
54 FLUSH LOGS;
55
56 --echo #
57 --echo # 4) Get the filename of the binary log.
58 --echo #
59 --source include/save_binlog_position.inc
60
61 --echo #
62 --echo # 5) Run a query to get events in mysqlbinlog greater than 4GB.
63 --echo #
64 INSERT INTO t2 SELECT f1 FROM t1 UNION ALL SELECT f1 FROM t1 UNION ALL SELECT
65 f1 FROM t1 UNION ALL SELECT f1 FROM t1 UNION ALL SELECT f1 FROM t1 UNION ALL
66 SELECT f1 FROM t1 UNION ALL SELECT f1 FROM t1 UNION ALL SELECT f1 FROM t1;
67
68 --echo #
69 --echo # 6) Get the start position of the 14'th event.
70 --echo #
71 --let $event_position = query_get_value(SHOW BINLOG EVENTS IN '$binlog_file', Pos, 14)
72
73 --echo #
74 --echo # 7)Verify that the position is actually bigger than 4 GiB.
75 --echo #
76 --let $assert_text = The position of the 14th event should be bigger than 4 GiB
77 --let $assert_cond = $event_position > 1 << 32
78 --source include/assert.inc
79
80 # Use UUID to ensure the name is unique even when running parallel tests.
81 --let $uuid = `SELECT UUID()`
82 --let $output_file = $MYSQLTEST_VARDIR/tmp/$uuid
83
84 --echo #
85 --echo # 8)Run mysqlbinlog, find only the lines beginning with '# at',
86 --echo # select the last of those lines,select only the number from that line,
87 --echo # and write that to the file.
88 --echo #
89
90 # The following perl script extracts "N" from the last line on the form
91 # "# at N", where N is a number, and stores it in the output file.
92 # It is equivalent to the following pipe, but more portable since "tail"
93 # doesn't exist on all our platforms:
94 # $MYSQLBINLOG_PIPE
95 # | grep '^# at'
96 # | tail -n 1
97 # | sed 's/[^0-9]//g'
98 # > $output_file
99 --let MYSQLBINLOG_PIPE = $MYSQL_BINLOG --force-if-open $binlog_fullpath |
100 --let OUTPUT_FILE_ENV = $output_file
101 perl END_OF_PERL;
102 my $output_file = $ENV{'OUTPUT_FILE_ENV'};
103 my $mysqlbinlog_pipe = $ENV{'MYSQLBINLOG_PIPE'};
104 open(MYSQLBINLOG_OUTPUT, $mysqlbinlog_pipe)
105 or die "Error $? opening '$mysqlbinlog_pipe': $!";
106 my $last_match = '';
107 for my $line (<MYSQLBINLOG_OUTPUT>) {
108 if ($line =~ /^# at (\d+)/) {
109 $last_match = $1;
110 }
111 }
112 close(MYSQLBINLOG_OUTPUT)
113 or die "Error $? closing '$mysqlbinlog_pipe': $!";
114 if ($last_match) {
115 open(RESULT, "> $output_file")
116 or die "Error $? opening '$output_file': $!";
117 print RESULT ($last_match)
118 or die "Error $? printing to '$output_file': $!";
119 close(RESULT)
120 or die "Error $? closing '$output_file': $!";
121 } else {
122 die("Not found");
123 }
124 END_OF_PERL
125
126 # Read the file into the variable $result.
127 --let $read_from_file = $output_file
128 --source include/read_file_to_var.inc
129 # Check that it is greater than 4 GiB.
130 --let $assert_text = The position should be greater than 4 GiB
131 --let $assert_cond = $result > 1 << 32
132 --source include/assert.inc
133
134
135 --echo #
136 --echo # 9)Checking the error message that will be generated when it is connected to remote.
137 --echo #
138 # Read over a connection
139 --let $mysqlbinlog_parameters = --read-from-remote-source=BINLOG-DUMP-NON-GTID --user=root --host=127.0.0.1 --port=$MASTER_MYPORT $binlog_file
140 # Do not fail the test when mysqlbinlog fails
141 --error 1
142 --exec $MYSQL_BINLOG --start-position=$event_position $mysqlbinlog_parameters 2>&1
143
144 --echo #
145 --echo # 10) Cleanup.
146 --echo #
147 DROP TABLE t2;
148 DROP TABLE t1;
149 --remove_file $output_file