| 1 |
--source include/have_binlog_format_mixed.inc |
| 2 |
|
| 3 |
SET GLOBAL binlog_gtid_index= 0; |
| 4 |
SET GLOBAL binlog_gtid_index= 1; |
| 5 |
|
| 6 |
--let $file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 7 |
--let $pos1= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 8 |
SET @gtid1= @@gtid_binlog_pos; |
| 9 |
CREATE TABLE t1 (a INT PRIMARY KEY); |
| 10 |
--let $pos2= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 11 |
SET @gtid2= @@gtid_binlog_pos; |
| 12 |
INSERT INTO t1 VALUES (1); |
| 13 |
--let $pos3= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 14 |
SET @gtid3= @@gtid_binlog_pos; |
| 15 |
INSERT INTO t1 VALUES (2); |
| 16 |
INSERT INTO t1 VALUES (3); |
| 17 |
INSERT INTO t1 VALUES (4); |
| 18 |
--let $pos4= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 19 |
SET @gtid4= @@gtid_binlog_pos; |
| 20 |
INSERT INTO t1 VALUES (5); |
| 21 |
--let $pos5= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 22 |
SET @gtid5= @@gtid_binlog_pos; |
| 23 |
|
| 24 |
--disable_query_log |
| 25 |
--let $i=0 |
| 26 |
while ($i < 100) { |
| 27 |
eval INSERT INTO t1 VALUES (6 + $i); |
| 28 |
inc $i; |
| 29 |
} |
| 30 |
--enable_query_log |
| 31 |
--let $pos6= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 32 |
SET @gtid6= @@gtid_binlog_pos; |
| 33 |
|
| 34 |
INSERT INTO t1 VALUES (106); |
| 35 |
INSERT INTO t1 VALUES (107); |
| 36 |
|
| 37 |
# Test first the hot and then the cold index. |
| 38 |
--let $i= 0 |
| 39 |
while ($i < 2) { |
| 40 |
--disable_query_log |
| 41 |
eval SELECT BINLOG_GTID_POS('$file', $pos1) = @gtid1 AS Ok; |
| 42 |
eval SELECT BINLOG_GTID_POS('$file', $pos2) = @gtid2 AS Ok; |
| 43 |
eval SELECT BINLOG_GTID_POS('$file', $pos3) = @gtid3 AS Ok; |
| 44 |
eval SELECT BINLOG_GTID_POS('$file', $pos4) = @gtid4 AS Ok; |
| 45 |
eval SELECT BINLOG_GTID_POS('$file', $pos5) = @gtid5 AS Ok; |
| 46 |
eval SELECT BINLOG_GTID_POS('$file', $pos6) = @gtid6 AS Ok; |
| 47 |
--enable_query_log |
| 48 |
|
| 49 |
inc $i; |
| 50 |
if ($i == 1) { |
| 51 |
FLUSH BINARY LOGS; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
--echo *** Test that purge deletes the gtid index files. *** |
| 56 |
FLUSH BINARY LOGS; |
| 57 |
INSERT INTO t1 VALUES (200); |
| 58 |
--let $file2= query_get_value(SHOW MASTER STATUS, File, 1) |
| 59 |
FLUSH BINARY LOGS; |
| 60 |
INSERT INTO t1 VALUES (201); |
| 61 |
--let $file3= query_get_value(SHOW MASTER STATUS, File, 1) |
| 62 |
FLUSH BINARY LOGS; |
| 63 |
INSERT INTO t1 VALUES (202); |
| 64 |
--let $file4= query_get_value(SHOW MASTER STATUS, File, 1) |
| 65 |
|
| 66 |
--replace_result $file3 FILE |
| 67 |
eval PURGE BINARY LOGS TO '$file3'; |
| 68 |
|
| 69 |
--let $MYSQLD_DATADIR= `select @@datadir` |
| 70 |
--error 1 |
| 71 |
--file_exists $MYSQLD_DATADIR/$file.idx |
| 72 |
--error 1 |
| 73 |
--file_exists $MYSQLD_DATADIR/$file2.idx |
| 74 |
--file_exists $MYSQLD_DATADIR/$file3.idx |
| 75 |
--file_exists $MYSQLD_DATADIR/$file4.idx |
| 76 |
|
| 77 |
--echo *** Test missed index lookup due to missing or corrupt index file. |
| 78 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 79 |
--let $file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 80 |
INSERT INTO t1 VALUES (301); |
| 81 |
INSERT INTO t1 VALUES (302); |
| 82 |
INSERT INTO t1 VALUES (303); |
| 83 |
--let $pos= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 84 |
SET @gtid_pos= @@GLOBAL.gtid_binlog_pos; |
| 85 |
INSERT INTO t1 VALUES (304); |
| 86 |
INSERT INTO t1 VALUES (305); |
| 87 |
|
| 88 |
# BINLOG_GTID_POS() has a side effect: it increments binlog_gtid_index_hit |
| 89 |
--disable_ps2_protocol |
| 90 |
FLUSH NO_WRITE_TO_BINLOG GLOBAL STATUS; |
| 91 |
--echo +++ Initial status: |
| 92 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 93 |
--echo +++ GTID Lookup in good index. |
| 94 |
--disable_query_log |
| 95 |
eval SELECT BINLOG_GTID_POS('$file', $pos) = @gtid_pos AS Gtid_Lookup_Ok; |
| 96 |
--enable_query_log |
| 97 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 98 |
--remove_file $MYSQLD_DATADIR/$file.idx |
| 99 |
--echo +++ GTID Lookup, index file is missing. |
| 100 |
--disable_query_log |
| 101 |
eval SELECT BINLOG_GTID_POS('$file', $pos) = @gtid_pos AS Gtid_Lookup_Ok; |
| 102 |
--enable_query_log |
| 103 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 104 |
|
| 105 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 106 |
--let $file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 107 |
INSERT INTO t1 VALUES (306); |
| 108 |
--let $pos= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 109 |
SET @gtid_pos= @@GLOBAL.gtid_binlog_pos; |
| 110 |
INSERT INTO t1 VALUES (307); |
| 111 |
INSERT INTO t1 VALUES (308); |
| 112 |
# Rotate again so we hit an on-disk index file, not the "hot" index. |
| 113 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 114 |
|
| 115 |
# Corrupt the flag byte of the first page with an unused bit. |
| 116 |
--let FILE_TO_CORRUPT= $MYSQLD_DATADIR/$file.idx |
| 117 |
--perl |
| 118 |
use strict; |
| 119 |
use warnings; |
| 120 |
use Fcntl qw(:DEFAULT :seek); |
| 121 |
sysopen F, $ENV{FILE_TO_CORRUPT}, O_RDWR |
| 122 |
or die "Cannot open file $ENV{FILE_TO_CORRUPT}: $!\n"; |
| 123 |
# Corrupt the flag byte with an unused flag. |
| 124 |
sysseek(F, 16, SEEK_SET) |
| 125 |
or die "Cannot seek file: $!\n"; |
| 126 |
my $buf; |
| 127 |
sysread(F, $buf, 1) |
| 128 |
or die "Cannot read file: $!\n"; |
| 129 |
$buf= chr(ord($buf) | 0x80); |
| 130 |
sysseek(F, 16, SEEK_SET) |
| 131 |
or die "Cannot seek file: $!\n"; |
| 132 |
syswrite(F, $buf, 1) == 1 |
| 133 |
or die "Cannot write file: $!\n"; |
| 134 |
close F; |
| 135 |
EOF |
| 136 |
|
| 137 |
--echo +++ GTID Lookup, first page of index is corrupt. |
| 138 |
--disable_query_log |
| 139 |
eval SELECT BINLOG_GTID_POS('$file', $pos) = @gtid_pos AS Gtid_Lookup_Ok; |
| 140 |
--enable_query_log |
| 141 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 142 |
|
| 143 |
# Corrupt the last byte of the root page. |
| 144 |
# Set a small page-size so we test corruption in something not the header page. |
| 145 |
SET @old_page_size= @@GLOBAL.binlog_gtid_index_page_size; |
| 146 |
SET @old_span_min= @@GLOBAL.binlog_gtid_index_span_min; |
| 147 |
SET GLOBAL binlog_gtid_index_page_size= 64; |
| 148 |
SET GLOBAL binlog_gtid_index_span_min= 1; |
| 149 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 150 |
--let $file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 151 |
INSERT INTO t1 VALUES (310); |
| 152 |
INSERT INTO t1 VALUES (311); |
| 153 |
INSERT INTO t1 VALUES (312); |
| 154 |
--let $pos= query_get_value(SHOW MASTER STATUS, Position, 1) |
| 155 |
SET @gtid_pos= @@GLOBAL.gtid_binlog_pos; |
| 156 |
INSERT INTO t1 VALUES (313); |
| 157 |
INSERT INTO t1 VALUES (314); |
| 158 |
INSERT INTO t1 VALUES (315); |
| 159 |
INSERT INTO t1 VALUES (316); |
| 160 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 161 |
SET GLOBAL binlog_gtid_index_page_size= @old_page_size; |
| 162 |
SET GLOBAL binlog_gtid_index_span_min= @old_span_min; |
| 163 |
|
| 164 |
--let FILE_TO_CORRUPT= $MYSQLD_DATADIR/$file.idx |
| 165 |
--perl |
| 166 |
use strict; |
| 167 |
use warnings; |
| 168 |
use Fcntl qw(:DEFAULT :seek); |
| 169 |
sysopen F, $ENV{FILE_TO_CORRUPT}, O_RDWR |
| 170 |
or die "Cannot open file $ENV{FILE_TO_CORRUPT}: $!\n"; |
| 171 |
# Tricky: The index is written asynchroneously, it may still be incomplete. |
| 172 |
# So wait for the file to be written completely with a root node at the end. |
| 173 |
my $count= 0; |
| 174 |
for (;;) { |
| 175 |
my $end= sysseek(F, 0, SEEK_END); |
| 176 |
if ($end > 0 && ($end % 64) == 0) { |
| 177 |
# The index file is non-empty with a full page at the end, test if the |
| 178 |
# root page has been fully written. This is seen as bit 2 (PAGE_FLAG_LAST) |
| 179 |
# and bit 3 (PAGE_FLAG_ROOT) being set (0xc). |
| 180 |
my $flag; |
| 181 |
if (sysseek(F, -64, SEEK_CUR) && |
| 182 |
sysread(F, $flag, 1) && |
| 183 |
(ord($flag) & 0xc) == 0xc) { |
| 184 |
last; |
| 185 |
} |
| 186 |
} |
| 187 |
die "Timeout waiting for GTID index to be non-empty\n" |
| 188 |
if ++$count >= 500; |
| 189 |
# Simple way to do sub-second sleep. |
| 190 |
select(undef, undef, undef, 0.050); |
| 191 |
} |
| 192 |
# Corrupt the flag byte with an unused flag. |
| 193 |
sysseek(F, -2, SEEK_END) |
| 194 |
or die "Cannot seek file: $!\n"; |
| 195 |
my $buf; |
| 196 |
sysread(F, $buf, 1) |
| 197 |
or die "Cannot read file: $!\n"; |
| 198 |
$buf= chr(ord($buf) ^ 0x4); |
| 199 |
sysseek(F, -2, SEEK_END) |
| 200 |
or die "Cannot seek file: $!\n"; |
| 201 |
syswrite(F, $buf, 1) == 1 |
| 202 |
or die "Cannot write file: $!\n"; |
| 203 |
close F; |
| 204 |
EOF |
| 205 |
|
| 206 |
--echo +++ GTID Lookup, root page of index is corrupt. |
| 207 |
--disable_query_log |
| 208 |
eval SELECT BINLOG_GTID_POS('$file', $pos) = @gtid_pos AS Gtid_Lookup_Ok; |
| 209 |
--enable_query_log |
| 210 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 211 |
|
| 212 |
--echo *** Test BINLOG_GTID_POS() with too-large offset. |
| 213 |
# New binlog to skip the now corrupted one. |
| 214 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 215 |
--let $file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 216 |
INSERT INTO t1 VALUES (401); |
| 217 |
INSERT INTO t1 VALUES (402); |
| 218 |
--echo +++ Test the hot index. |
| 219 |
--replace_result $file FILE |
| 220 |
eval SELECT BINLOG_GTID_POS('$file', 100000000); |
| 221 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 222 |
FLUSH NO_WRITE_TO_BINLOG BINARY LOGS; |
| 223 |
--echo +++ Test the cold index. |
| 224 |
--replace_result $file FILE |
| 225 |
eval SELECT BINLOG_GTID_POS('$file', 100000000); |
| 226 |
SHOW STATUS LIKE 'binlog_gtid_index_%'; |
| 227 |
--enable_ps2_protocol |
| 228 |
|
| 229 |
DROP TABLE t1; |