Debian Codegraph @

mysql-test/suite/innodb/t/max_trx_id.test

raw
1 --source include/have_debug.inc
2 --source include/have_debug_sync.inc
3 --source include/not_valgrind.inc
4 --source include/count_sessions.inc
5
6 --echo # Initialize new data directory and restart MySQL on that data directory.
7 --echo # The new data directory will be initialized by instance which has:
8 --echo # --debug="d,trx_sys_low_trx_id_write_margin" so it will do reservations
9 --echo # of trx_id values every 8 trx_id values (instead of every 256 values).
10 --echo # This way we could collect enough connections in mtr test runner to fill
11 --echo # concurrently the reservation interval (limit for mtr connections is 128).
12
13 let $INNODB_PAGE_SIZE = `select @@innodb_page_size`;
14 let $tmp_dir = $MYSQLTEST_VARDIR/tmp;
15 let $MYSQLD_DATADIR = $tmp_dir/max_trx_id;
16 let $MYSQLD_ERROR_LOG = $tmp_dir/my_restart.err;
17 let $MYSQLD_EXTRA_ARGS = --debug="d,trx_sys_low_trx_id_write_margin" --innodb-redo-log-capacity=8M --innodb_page_size=$INNODB_PAGE_SIZE;
18 --source include/initialize_datadir.inc
19
20 --echo # Restart MySQL using the new data directory.
21 let $restart_parameters = restart: --datadir=$MYSQLD_DATADIR --log-error=$MYSQLD_ERROR_LOG $MYSQLD_EXTRA_ARGS;
22 --replace_result $MYSQLD_ERROR_LOG my_restart.err $MYSQLD_DATADIR tmp/max_trx_id $INNODB_PAGE_SIZE INNODB_PAGE_SIZE
23 --source include/restart_mysqld.inc
24
25 --disable_query_log
26 CREATE TABLE t (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, c INT NOT NULL, INDEX(c)) ENGINE=InnoDB;
27
28 --let $N=7
29
30 --let $i=1
31 while ($i <= $N) {
32 INSERT INTO t (a, c) VALUES (NULL, 0);
33 --inc $i
34 }
35
36 INSERT INTO t (a, c) VALUES (-1, 0);
37
38 DELIMITER |;
39 CREATE PROCEDURE trx_loop(IN id INT)
40 BEGIN
41 WHILE 1 DO
42 START TRANSACTION;
43 UPDATE t SET c = c + 1 WHERE a = id;
44 COMMIT;
45 START TRANSACTION;
46 SELECT * FROM t WHERE a = id FOR UPDATE;
47 COMMIT;
48 END WHILE;
49 END|
50 DELIMITER ;|
51 --enable_query_log
52
53 --echo # Create $N connections which keep creating and comitting transactions.
54 --echo # Pause the created connections before trx_sys_mutex_enter() is called
55 --echo # before assigning trx->id.
56
57 --let $i=1
58 while ($i <= $N) {
59 --connect(con_id$i,localhost,root,,)
60 --eval SET DEBUG_SYNC = "trx_sys_before_assign_id SIGNAL con_id_waiting$i WAIT_FOR con_go NO_CLEAR_EVENT"
61 --eval SET @id = $i
62
63 START TRANSACTION;
64 --send UPDATE t SET c = c+1 WHERE a = @id
65 --inc $i
66 }
67
68 --echo # Wait.
69
70 --connection default
71 --let $i=1
72 while ($i <= $N) {
73 --echo # Wait for $i....
74 --eval SET DEBUG_SYNC = "now WAIT_FOR con_id_waiting$i"
75 --inc $i
76 }
77
78 --echo # Create a connection which will hang inside trx_sys_write_max_trx_id()
79 --echo # when holding the trx_sys_serialisation_mutex.
80
81 --connect(con_hang,localhost,root,,)
82 SET DEBUG_SYNC = "trx_sys_write_max_trx_id__ser SIGNAL write_waiting WAIT_FOR write_go";
83 --send CALL trx_loop(-1)
84
85 --echo # Wait until the created connection is hanging.
86
87 --connection default
88 SET DEBUG_SYNC = "now WAIT_FOR write_waiting";
89
90 --echo # Let the paused connections go, to check if they could corrupt the database.
91 --echo # Do not allow them to write max_trx_id to the transaction system header page.
92
93 SET GLOBAL DEBUG = "+d,trx_sys_write_max_trx_id__all_blocked";
94 SET DEBUG_SYNC = "now SIGNAL con_go";
95
96 --echo # Wait a little bit, giving a chance to corrupt the database to the resumed
97 --echo # connections (by writing down too high trx_id to some page / row).
98
99 --sleep 5
100
101 --echo # Kill and restart MySQL to see if the database is not corrupted.
102
103 --replace_result $MYSQLD_ERROR_LOG my_restart.err $MYSQLD_DATADIR tmp/max_trx_id $INNODB_PAGE_SIZE INNODB_PAGE_SIZE
104 --source include/kill_and_restart_mysqld.inc
105
106 --echo # Update rows using a new transaction. It would crash if the transaction
107 --echo # received a trx->id which had been assigned to some other transaction
108 --echo # and written to some page/row before MySQL crashed.
109
110 UPDATE t SET c = c + 1;
111
112 --echo # Check if there is no corruption if MySQL instantly crashed after using
113 --echo # the new transaction (after restart).
114
115 --replace_result $MYSQLD_ERROR_LOG my_restart.err $MYSQLD_DATADIR tmp/max_trx_id $INNODB_PAGE_SIZE INNODB_PAGE_SIZE
116 --source include/kill_and_restart_mysqld.inc
117
118 --echo # Update all rows using a new transaction to see if there is no assertion
119 --echo # failure on trx_id for any of the related pages.
120
121 UPDATE t SET c = c + 1;
122
123 --echo # Turn off MySQL and remove its data directory.
124
125 --source include/kill_mysqld.inc
126 --force-rmdir $MYSQLD_DATADIR
127 --remove_file $MYSQLD_ERROR_LOG
128
129 --echo # Restart usual instance of MySQL which is used for mtr tests.
130
131 let $restart_parameters = restart:;
132 --source include/start_mysqld.inc
133
134 --source include/wait_until_count_sessions.inc