| 1 |
--source include/have_ndb.inc |
| 2 |
--source include/have_binlog_format_mixed_or_row.inc |
| 3 |
# |
| 4 |
# The applier will write to binlog directly when applying DDL and |
| 5 |
# as part of that the binlog might rotate and purge. |
| 6 |
# This is a special case and contrasts itself to how DML's are |
| 7 |
# handle by just writing the change to NDB, those changes will then |
| 8 |
# be picked up by the binlog MySQL servers which will write the change to |
| 9 |
# binlog asynchrounously. |
| 10 |
# |
| 11 |
# This test configures the replica with small binlog size and thresholds |
| 12 |
# for purge, then perform a number of DDL's in order for the applier |
| 13 |
# to trigger rotate and purge. After test there should be no |
| 14 |
# rows without corresponding binlog files (ie. orphan) in |
| 15 |
# the ndb_binlog_index table. |
| 16 |
# |
| 17 |
|
| 18 |
|
| 19 |
# Configure replication and start replicating |
| 20 |
--source suite/ndb_rpl/ndb_master-slave.inc |
| 21 |
|
| 22 |
CREATE TABLE t1 ( |
| 23 |
a INT PRIMARY KEY |
| 24 |
) engine=ndb; |
| 25 |
|
| 26 |
|
| 27 |
# Run DDL and DML on the source, do a large number of DDL to make it very likely |
| 28 |
# that the binlog will rotate and purge when replica applies the DDL. |
| 29 |
# The DML are there to make sure that rows are inserted into ndb_binlog_index |
| 30 |
# as such rows are only written when when a change is written by the |
| 31 |
# binlog thread. |
| 32 |
let $i = 0; |
| 33 |
let $COLUMNS = 100; |
| 34 |
while($i < $COLUMNS) |
| 35 |
{ |
| 36 |
eval INSERT INTO t1 (a) VALUES ($i); |
| 37 |
--eval ALTER TABLE t1 ADD COLUMN c$i INT COLUMN_FORMAT DYNAMIC |
| 38 |
inc $i; |
| 39 |
} |
| 40 |
|
| 41 |
--source include/sync_slave_sql_with_master.inc |
| 42 |
|
| 43 |
--echo # Show replica settings |
| 44 |
--echo # - small binlog, auto purge on and purge after one second |
| 45 |
let $max_binlog_size= |
| 46 |
`SELECT VARIABLE_VALUE |
| 47 |
FROM performance_schema.global_variables |
| 48 |
WHERE VARIABLE_NAME = 'max_binlog_size'`; |
| 49 |
echo max_binlog_size: $max_binlog_size; |
| 50 |
|
| 51 |
let $auto_purge= |
| 52 |
`SELECT VARIABLE_VALUE |
| 53 |
FROM performance_schema.global_variables |
| 54 |
WHERE VARIABLE_NAME = 'binlog_expire_logs_auto_purge'`; |
| 55 |
echo auto_purge: $auto_purge; |
| 56 |
|
| 57 |
let $expire_seconds= |
| 58 |
`SELECT VARIABLE_VALUE |
| 59 |
FROM performance_schema.global_variables |
| 60 |
WHERE VARIABLE_NAME = 'binlog_expire_logs_seconds'`; |
| 61 |
echo expire_seconds: $expire_seconds; |
| 62 |
|
| 63 |
|
| 64 |
--echo # Check that there are no rows in ndb_binlog_index without |
| 65 |
--echo # corresponding binlog, this is in two steps by first building a |
| 66 |
--echo # table from the output of SHOW BINARY LOGS and then comparing |
| 67 |
--echo # that table with ndb_binlog_index |
| 68 |
# Basically these two queries should match |
| 69 |
# SELECT File, COUNT(*) FROM mysql.ndb_binlog_index GROUP BY File; |
| 70 |
# SHOW BINARY LOGS; |
| 71 |
|
| 72 |
--echo # 1. Build binlogs table from output of SHOW BINARY LOGS |
| 73 |
CREATE TEMPORARY TABLE binlogs( |
| 74 |
num INT PRIMARY KEY AUTO_INCREMENT, |
| 75 |
name varchar(512) NOT NULL |
| 76 |
); |
| 77 |
--let $row = 1 |
| 78 |
--let $file = query_get_value(SHOW BINARY LOGS, Log_name, $row) |
| 79 |
while ($file != 'No such row') |
| 80 |
{ |
| 81 |
--disable_query_log ONCE |
| 82 |
eval INSERT INTO binlogs VALUES($row, '$file'); |
| 83 |
--inc $row |
| 84 |
--let $file = query_get_value(SHOW BINARY LOGS, Log_name, $row) |
| 85 |
} |
| 86 |
--echo # 2. Compare binlogs table with ndb_binlog_index to check |
| 87 |
--echo # that no orphan rows exist, the query should return no rows. |
| 88 |
if (`SELECT COUNT(*) FROM mysql.ndb_binlog_index |
| 89 |
WHERE SUBSTRING(File, LOCATE('slave-bin', File)) |
| 90 |
NOT IN (SELECT name FROM binlogs)`) |
| 91 |
{ |
| 92 |
--echo # Found orphan rows, dumping content of tables |
| 93 |
SHOW BINARY LOGS; |
| 94 |
SELECT name FROM binlogs; |
| 95 |
SELECT * FROM mysql.ndb_binlog_index; |
| 96 |
SELECT File, |
| 97 |
LOCATE('slave-bin', File), |
| 98 |
SUBSTRING(File, LOCATE('slave-bin', File)) |
| 99 |
FROM mysql.ndb_binlog_index; |
| 100 |
SELECT * FROM mysql.ndb_binlog_index |
| 101 |
WHERE SUBSTRING(File, LOCATE('slave-bin', File)) |
| 102 |
NOT IN (SELECT name FROM binlogs); |
| 103 |
--die Orphan rows found in mysql_ndb_binlog_index table |
| 104 |
} |
| 105 |
|
| 106 |
# Cleanup |
| 107 |
--source include/rpl_connection_master.inc |
| 108 |
DROP TABLE t1; |
| 109 |
--source include/sync_slave_sql_with_master.inc |
| 110 |
|
| 111 |
--source include/rpl_end.inc |