Debian Codegraph @

mysql-test/suite/rpl/t/rpl_memory_engine_truncate_on_restart.test

raw
1 #
2 # This test ensures that a table with engine=memory is kept consistent with
3 # the slave when the master restarts. That is, when the master is restarted, it
4 # should binlog a new TRUNCATE TABLE command for tables with MEMORY engines,
5 # such that after the slave executes these events, its MEMORY-engine tables
6 # should be empty.
7 #
8 # References:
9 # MDEV-25607: Auto-generated DELETE from HEAP table can break replication
10 #
11 --source include/master-slave.inc
12
13 --connection master
14 create table t (val int) engine=MEMORY;
15
16 -- echo # DELETE trigger should never be activated
17 create trigger tr after delete on t for each row update t2 set val = 1;
18
19 insert into t values (1),(2);
20 --source include/save_master_gtid.inc
21 --connection slave
22 --source include/sync_with_master_gtid.inc
23
24 -- echo # Check pre-restart values
25 --let $diff_tables= master:test.t,slave:test.t
26 --source include/diff_tables.inc
27
28 --echo # Restarting master should empty master and slave `t`
29 --connection master
30 --let $seq_no_before_restart= `SELECT REGEXP_REPLACE(@@global.gtid_binlog_pos, "0-1-", "")`
31 --let $rpl_server_number= 1
32 --source include/rpl_restart_server.inc
33
34 --connection master
35 --echo # Validating MEMORY table on master is empty after restart
36 --let $table_size= `select count(*) from t`
37 if ($table_size)
38 {
39 --echo # MEMORY table is not empty
40 --die MEMORY table is not empty
41 }
42 --let $seq_no_after_restart= `SELECT REGEXP_REPLACE(@@global.gtid_binlog_pos, "0-1-", "")`
43 if ($seq_no_before_restart == $seq_no_after_restart)
44 {
45 --echo # Event to empty MEMORY table was not binlogged
46 --die Event to empty MEMORY table was not binlogged
47 }
48
49 --let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
50 --let $datadir=`select @@datadir`
51 --let assert_file= $MYSQLTEST_VARDIR/tmp/binlog_decoded.out
52 --echo # MYSQL_BINLOG datadir/binlog_file --result-file=assert_file
53 --exec $MYSQL_BINLOG $datadir/$binlog_file --result-file=$assert_file
54
55 --let assert_text= Query to truncate the MEMORY table should be the contents of the new event
56 --let assert_count= 1
57 --let assert_select= ^TRUNCATE TABLE .+generated.+memory table
58 --source include/assert_grep.inc
59
60 --echo # Ensuring slave MEMORY table is empty
61 --connection master
62 --source include/save_master_gtid.inc
63 --connection slave
64 --source include/sync_with_master_gtid.inc
65 --source include/diff_tables.inc
66
67 --echo # Ensure new events replicate correctly
68 --connection master
69 insert into t values (3),(4);
70 --source include/save_master_gtid.inc
71 --connection slave
72 --source include/sync_with_master_gtid.inc
73
74 --echo # Validate values on slave, after master restart, do not include those inserted previously
75 --source include/diff_tables.inc
76
77 --echo #
78 --echo # Cleanup
79 --connection master
80 drop table t;
81 --source include/rpl_end.inc
82 --echo # End of rpl_memory_engine_truncate_on_restart.test