| 1 |
################################################################################ |
| 2 |
# MDEV-32014 Rename binlog cache to binlog file |
| 3 |
# |
| 4 |
# It verifies that the binlog caches which are larger |
| 5 |
# than binlog_large_commit_threshold can be move to a binlog file |
| 6 |
# successfully. With a successful rename, |
| 7 |
# - it rotates the binlog and the cache is renamed to the new binlog file |
| 8 |
# - an ignorable event is generated just after the Gtid_log_event of the |
| 9 |
# transaction to take the reserved spaces which is unused. |
| 10 |
# |
| 11 |
# It also verifies that rename is not supported in below cases |
| 12 |
# though the cache is larger than the threshold |
| 13 |
# - both statement and transaction cache should be flushed. |
| 14 |
# - the cache's checksum option is not same to binlog_checksum |
| 15 |
# - binlog_legacy_event_pos is enabled. |
| 16 |
################################################################################ |
| 17 |
--source include/have_binlog_format_row.inc |
| 18 |
--source include/have_innodb.inc |
| 19 |
--source include/master-slave.inc |
| 20 |
|
| 21 |
--echo # Prepare |
| 22 |
SET @saved_binlog_large_commit_threshold= @@GLOBAL.binlog_large_commit_threshold; |
| 23 |
SET @saved_binlog_checksum= @@GLOBAL.binlog_checksum; |
| 24 |
|
| 25 |
SET GLOBAL binlog_checksum = "NONE"; |
| 26 |
|
| 27 |
CREATE TABLE t1 (c1 LONGTEXT) ENGINE = InnoDB; |
| 28 |
CREATE TABLE t2 (c1 LONGTEXT) ENGINE = MyISAM; |
| 29 |
|
| 30 |
INSERT INTO t1 values(repeat("1", 5242880)); |
| 31 |
INSERT INTO t1 values(repeat("1", 5242880)); |
| 32 |
INSERT INTO t2 values(repeat("1", 5242880)); |
| 33 |
INSERT INTO t2 values(repeat("1", 5242880)); |
| 34 |
|
| 35 |
FLUSH BINARY LOGS; |
| 36 |
|
| 37 |
--echo # Not renamed to binlog, since the binlog cache is not larger than the |
| 38 |
--echo # threshold. And it should works well after ROLLBACK TO SAVEPOINT |
| 39 |
BEGIN; |
| 40 |
SAVEPOINT s1; |
| 41 |
UPDATE t1 SET c1 = repeat('1', 5242880); |
| 42 |
ROLLBACK TO SAVEPOINT s1; |
| 43 |
UPDATE t1 SET c1 = repeat('2', 5242880); |
| 44 |
SAVEPOINT s2; |
| 45 |
UPDATE t1 SET c1 = repeat('3', 5242880); |
| 46 |
UPDATE t1 SET c1 = repeat('4', 5242880); |
| 47 |
ROLLBACK TO SAVEPOINT s2; |
| 48 |
COMMIT; |
| 49 |
|
| 50 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 51 |
--let $assert_cond= "$binlog_file" = "master-bin.000003" |
| 52 |
--let $assert_text= Binlog is not rotated |
| 53 |
--source include/assert.inc |
| 54 |
|
| 55 |
--echo # |
| 56 |
--echo # Test binlog cache rename to binlog file with checksum off |
| 57 |
--echo # |
| 58 |
--source include/sync_slave_sql_with_master.inc |
| 59 |
--source include/stop_slave.inc |
| 60 |
|
| 61 |
SET @saved_binlog_large_commit_threshold = @@GLOBAL.binlog_large_commit_threshold; |
| 62 |
SET @saved_slave_parallel_workers = @@GLOBAL.slave_parallel_workers; |
| 63 |
SET @saved_slave_parallel_mode = @@GLOBAL.slave_parallel_mode; |
| 64 |
SET @saved_slave_parallel_max_queued = @@GLOBAL.slave_parallel_max_queued; |
| 65 |
|
| 66 |
SET GLOBAL binlog_large_commit_threshold = 10 * 1024 * 1024; |
| 67 |
SET GLOBAL slave_parallel_max_queued = 100 * 1024 * 1024; |
| 68 |
SET GLOBAL slave_parallel_workers = 4; |
| 69 |
SET GLOBAL slave_parallel_mode = "aggressive"; |
| 70 |
--source include/start_slave.inc |
| 71 |
# Block all DML on slave |
| 72 |
BEGIN; |
| 73 |
DELETE FROM t1; |
| 74 |
|
| 75 |
--connection master |
| 76 |
SET GLOBAL binlog_large_commit_threshold = 10 * 1024 * 1024; |
| 77 |
|
| 78 |
--echo # Transaction cache can be renamed and works well with ROLLBACK TO SAVEPOINT |
| 79 |
BEGIN; |
| 80 |
SAVEPOINT s1; |
| 81 |
UPDATE t1 SET c1 = repeat('2', 5242880); |
| 82 |
ROLLBACK TO s1; |
| 83 |
UPDATE t1 SET c1 = repeat('3', 5242880); |
| 84 |
SAVEPOINT s2; |
| 85 |
UPDATE t1 SET c1 = repeat('4', 5242880); |
| 86 |
UPDATE t1 SET c1 = repeat('5', 5242880); |
| 87 |
UPDATE t1 SET c1 = repeat('6', 5242880); |
| 88 |
ROLLBACK TO SAVEPOINT s2; |
| 89 |
COMMIT; |
| 90 |
INSERT INTO t1 VALUES("after_update_t1"); |
| 91 |
|
| 92 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000004' LIMIT 4, End_log_pos, 4) |
| 93 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 94 |
--let $assert_text= Rename is executed. |
| 95 |
--source include/assert.inc |
| 96 |
|
| 97 |
--echo # statement cache can be renamed |
| 98 |
--connection master |
| 99 |
BEGIN; |
| 100 |
UPDATE t2 SET c1 = repeat('4', 5242880); |
| 101 |
INSERT INTO t1 VALUES("after_update_t2"); |
| 102 |
COMMIT; |
| 103 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000005' LIMIT 4, End_log_pos, 4) |
| 104 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 105 |
--let $assert_text= Rename is executed. |
| 106 |
--source include/assert.inc |
| 107 |
|
| 108 |
--connection slave |
| 109 |
# UPDATE t2 should be waiting for prior transactions to commit. |
| 110 |
let $wait_condition= |
| 111 |
SELECT count(*) = 1 FROM information_schema.processlist |
| 112 |
WHERE State = "Waiting for prior transaction to commit"; |
| 113 |
--source include/wait_condition.inc |
| 114 |
ROLLBACK; |
| 115 |
|
| 116 |
--connection master |
| 117 |
--source include/sync_slave_sql_with_master.inc |
| 118 |
|
| 119 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'slave-bin.000002' LIMIT 4, End_log_pos, 4) |
| 120 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 121 |
--let $assert_text= Rename is executed. |
| 122 |
--source include/assert.inc |
| 123 |
|
| 124 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'slave-bin.000003' LIMIT 4, End_log_pos, 4) |
| 125 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 126 |
--let $assert_text= Rename is executed. |
| 127 |
--source include/assert.inc |
| 128 |
|
| 129 |
--let $binlog_file= slave-bin.000002 |
| 130 |
--let $skip_checkpoint_events= 1 |
| 131 |
--source include/show_binlog_events.inc |
| 132 |
--let $binlog_file= slave-bin.000003 |
| 133 |
--source include/show_binlog_events.inc |
| 134 |
|
| 135 |
--source include/stop_slave.inc |
| 136 |
SET GLOBAL binlog_large_commit_threshold = @saved_binlog_large_commit_threshold; |
| 137 |
SET GLOBAL slave_parallel_workers = @saved_slave_parallel_workers; |
| 138 |
SET GLOBAL slave_parallel_max_queued = @saved_slave_parallel_max_queued; |
| 139 |
SET GLOBAL slave_parallel_mode = @saved_slave_parallel_mode; |
| 140 |
--source include/start_slave.inc |
| 141 |
|
| 142 |
--echo # CREATE SELECT works well |
| 143 |
--connection master |
| 144 |
CREATE TABLE t3 SELECT * FROM t1; |
| 145 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000006' LIMIT 4, End_log_pos, 4) |
| 146 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 147 |
--let $assert_text= Rename is executed. |
| 148 |
--source include/assert.inc |
| 149 |
|
| 150 |
CREATE TABLE t4 SELECT * FROM t2; |
| 151 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000007' LIMIT 4, End_log_pos, 4) |
| 152 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 153 |
--let $assert_text= Rename is executed. |
| 154 |
--source include/assert.inc |
| 155 |
|
| 156 |
--echo # XA statement works well |
| 157 |
XA START "test-a-long-xid========================================"; |
| 158 |
UPDATE t1 SET c1 = repeat('1', 5242880); |
| 159 |
XA END "test-a-long-xid========================================"; |
| 160 |
XA PREPARE "test-a-long-xid========================================"; |
| 161 |
XA COMMIT "test-a-long-xid========================================"; |
| 162 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000008' LIMIT 4, End_log_pos, 4) |
| 163 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 164 |
--let $assert_text= Rename is executed. |
| 165 |
--source include/assert.inc |
| 166 |
|
| 167 |
XA START "test-xid"; |
| 168 |
UPDATE t1 SET c1 = repeat('2', 5242880); |
| 169 |
XA END "test-xid"; |
| 170 |
XA COMMIT "test-xid" ONE PHASE; |
| 171 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000009' LIMIT 4, End_log_pos, 4) |
| 172 |
--let $assert_cond= $gtid_end_pos = 4096 |
| 173 |
--let $assert_text= Rename is executed. |
| 174 |
--source include/assert.inc |
| 175 |
|
| 176 |
--echo # |
| 177 |
--echo # It works well in the situation that binlog header is larger than |
| 178 |
--echo # IO_SIZE and binlog file's buffer. |
| 179 |
--echo # |
| 180 |
--disable_query_log |
| 181 |
|
| 182 |
# make Gtid_list_event larger than 64K(binlog file's buffer) |
| 183 |
--let $server_id= 100000 |
| 184 |
while ($server_id < 104096) |
| 185 |
{ |
| 186 |
eval SET SESSION server_id = $server_id; |
| 187 |
eval UPDATE t1 SET c1 = "$server_id" LIMIT 1; |
| 188 |
--inc $server_id |
| 189 |
} |
| 190 |
|
| 191 |
--enable_query_log |
| 192 |
|
| 193 |
# After flush, reserved space should be updated. |
| 194 |
FLUSH BINARY LOGS; |
| 195 |
|
| 196 |
SET SESSION server_id = 1; |
| 197 |
UPDATE t1 SET c1 = repeat('3', 5242880); |
| 198 |
|
| 199 |
--let $gtid_end_pos= query_get_value(SHOW BINLOG EVENTS IN 'master-bin.000011' LIMIT 4, End_log_pos, 4) |
| 200 |
# 69632 is 65K which is larger, binlog's buffer is 64K |
| 201 |
--let $assert_cond= $gtid_end_pos = 69632 |
| 202 |
--let $assert_text= Rename is executed. |
| 203 |
--source include/assert.inc |
| 204 |
|
| 205 |
--echo # |
| 206 |
--echo # RESET MASTER should work well. It also verifies binlog checksum mechanism. |
| 207 |
--echo # |
| 208 |
--source include/rpl_reset.inc |
| 209 |
|
| 210 |
--echo # |
| 211 |
--echo # Test binlog cache rename to binlog file with checksum on |
| 212 |
--echo # |
| 213 |
SET GLOBAL binlog_checksum = "CRC32"; |
| 214 |
|
| 215 |
--echo # It will not rename the cache to file, since the cache's checksum was |
| 216 |
--echo # initialized when reset the cache at the end of previous transaction. |
| 217 |
UPDATE t1 SET c1 = repeat('5', 5242880); |
| 218 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 219 |
--let $assert_cond= "$binlog_file" = "master-bin.000002" |
| 220 |
--let $assert_text= Binlog is not rotated |
| 221 |
--source include/assert.inc |
| 222 |
|
| 223 |
--echo # |
| 224 |
--echo # Not rename to binlog file If the cache's checksum is not same |
| 225 |
--echo # to binlog_checksum |
| 226 |
--echo # |
| 227 |
BEGIN; |
| 228 |
UPDATE t1 SET c1 = repeat('6', 5242880); |
| 229 |
SET GLOBAL binlog_checksum = "NONE"; |
| 230 |
COMMIT; |
| 231 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 232 |
--let $assert_cond= "$binlog_file" = "master-bin.000003" |
| 233 |
--let $assert_text= Binlog is not rotated |
| 234 |
--source include/assert.inc |
| 235 |
|
| 236 |
BEGIN; |
| 237 |
UPDATE t1 SET c1 = repeat('7', 5242880); |
| 238 |
SET GLOBAL binlog_checksum = "CRC32"; |
| 239 |
COMMIT; |
| 240 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 241 |
--let $assert_cond= "$binlog_file" = "master-bin.000004" |
| 242 |
--let $assert_text= Binlog is not rotated |
| 243 |
--source include/assert.inc |
| 244 |
|
| 245 |
--echo # |
| 246 |
--echo # Not rename to binlog file If both stmt and trx cache are not empty |
| 247 |
--echo # |
| 248 |
UPDATE t1, t2 SET t1.c1 = repeat('8', 5242880), t2.c1 = repeat('7', 5242880); |
| 249 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 250 |
--let $assert_cond= "$binlog_file" = "master-bin.000004" |
| 251 |
--let $assert_text= Binlog is not rotated |
| 252 |
--source include/assert.inc |
| 253 |
|
| 254 |
--echo # |
| 255 |
--echo # Not rename to binlog file If binlog_legacy_event_pos is on |
| 256 |
--echo # |
| 257 |
SET GLOBAL binlog_legacy_event_pos = ON; |
| 258 |
UPDATE t1 SET c1 = repeat('9', 5242880); |
| 259 |
SET GLOBAL binlog_legacy_event_pos = OFF; |
| 260 |
--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 261 |
--let $assert_cond= "$binlog_file" = "master-bin.000004" |
| 262 |
--let $assert_text= Binlog is not rotated |
| 263 |
--source include/assert.inc |
| 264 |
|
| 265 |
# cleanup |
| 266 |
DROP TABLE t1, t2, t3, t4; |
| 267 |
SET GLOBAL binlog_large_commit_threshold = @saved_binlog_large_commit_threshold; |
| 268 |
SET GLOBAL binlog_checksum = @saved_binlog_checksum; |
| 269 |
--let $binlog_file= |
| 270 |
--let $skip_checkpoint_events=0 |
| 271 |
--source include/rpl_end.inc |