Debian Codegraph @

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

raw
1 --source include/have_innodb.inc
2 # The embedded server tests do not support restarting.
3 --source include/not_embedded.inc
4 --source include/have_debug.inc
5 --source include/have_debug_sync.inc
6
7 --let transactions_count=10
8 --let perl_inc_file=$MYSQL_TMP_DIR/max_trx_no_recovery.inc
9
10 --let $i=$transactions_count
11 # We need several tables to avoid blocking on records locking and pages latching
12 while($i) {
13 --dec $i
14 if ($i == 0) {
15 --eval CREATE TABLE t_1_$i(a INT primary key) Engine=InnoDB STATS_PERSISTENT=0
16 --eval INSERT INTO t_1_$i SET a = 10
17 }
18 --eval CREATE TABLE t_2_$i(a INT primary key) Engine=InnoDB STATS_PERSISTENT=0
19 --eval INSERT INTO t_2_$i SET a = 10
20 }
21 --source include/wait_all_purged.inc
22
23 --connect (prevent_purge,localhost,root,,)
24 START TRANSACTION WITH CONSISTENT SNAPSHOT;
25
26 # Let all the following redo logs will be pushed in the same rseg
27 SET GLOBAL DEBUG_DBUG ="+d,assign_same_rseg";
28
29 --connection default
30 # Add the first undo log to the history of trx_sys.rseg_array[0] to fordbid
31 # "if (auto len= flst_get_len(TRX_RSEG + TRX_RSEG_HISTORY + ...)" branch of
32 # "trx_rseg_mem_restore()" to update rseg->needs_purge. Let trx_id and trx_no
33 # of the following transaction is L and M correspondingly.
34 UPDATE t_2_1 SET a=150;
35
36 --connect (con_1_0, localhost,root,,)
37 BEGIN;
38 # After the following transaction the undo segment will contain the following
39 # undo logs:
40 # sn: 0, trx_id: L, trx_no: M
41 # sn: 1, trx_id: N=M+1, trx_no: 0
42 UPDATE t_1_0 SET a=15;
43 --connect (con_2_0, localhost,root,,)
44 BEGIN;
45 # Stop the following "UPDATE" just before the undo log creating.
46 SET DEBUG_SYNC="before_undo_log_trx_id_write SIGNAL before_0 WAIT_FOR cont_0";
47 SET DEBUG_SYNC="after_undo_log_trx_id_write SIGNAL after_0";
48 --send UPDATE t_2_0 SET a=15
49 --connection con_1_0
50 SET DEBUG_SYNC="now WAIT_FOR before_0";
51
52 # The following trick with perl code, which generates mysqltest code, is applied
53 # to bypass the restriction of mysqltest in substitution variable values in
54 # connection names.
55 --perl END_OF_FILE
56 use strict;
57 use warnings;
58 my $out_file = $ENV{'perl_inc_file'};
59 my $transactions_count = $ENV{'transactions_count'};
60 open (my $output, '>', $out_file) or die $!;
61 my $i = 1;
62 while ($i < $transactions_count) {
63 print $output
64 "--connect (con_2_$i, localhost,root,,)\n".
65 "BEGIN;\n".
66 "SET DEBUG_SYNC=\"before_undo_log_trx_id_write SIGNAL before_$i WAIT_FOR cont_$i\";\n".
67 "--send UPDATE t_2_$i SET a=15\n".
68 "--connection default\n".
69 "SET DEBUG_SYNC=\"now WAIT_FOR before_$i\";\n";
70 ++$i;
71 }
72 close $output;
73 END_OF_FILE
74
75 # The generated code starts rw transactions just to increase
76 # trx_sys.m_max_trx_id by the number of started transactions S.
77 --source $perl_inc_file
78 --remove_file $perl_inc_file
79
80 --connection con_1_0
81 # After the following COMMIT and debug sync points the undo segment will contain
82 # the following undo logs:
83 # sn: 0, trx_id: L, trx_no: M
84 # sn: 1, trx_id: N=M+1, trx_no: N+S
85 # sn: 2, trx_id: N+1, trx_no: 0
86 COMMIT;
87 SET DEBUG_SYNC="now SIGNAL cont_0";
88 SET DEBUG_SYNC="now WAIT_FOR after_0";
89
90 --source include/kill_and_restart_mysqld.inc
91
92 # The trx_no of the last undo log is 0 and it's in active state, that's why
93 # the rseg->needs_purge is set to trx_id+1 = N+1+1 in
94 # trx_undo_mem_create_at_db_start(). The trx_sys.m_max_trx_id is set to maximum
95 # value of rseg->needs_purge among all rsegs + 1, i.e. for our case it's
96 # N+1+1+1.
97 #
98 # After uncommitted transactions rolling back on recovery, the undo
99 # segment will contain the following undo logs:
100 # sn: 0, trx_id: L, trx_no: M
101 # sn: 1, trx_id: N=M+1, trx_no: N+S
102 # and
103 # trx_sys.m_max_trx_id =
104 # N + 3(see above)
105 # + 1(row_merge_drop_temp_indexes())
106 # + 1(active transaction rollback)
107 # So trx_sys.m_max_trx_id = N + 5.
108 #
109 # The trx_no of the last undo log in the above undo segment is N+S. In the case
110 # if S > 5, the trx_no of one of the following transactions will be greater than
111 # N + S, i.e. the trx_no of the last undo log in the undo segment.
112 #
113 # That is treated as error in purge thread, because purge queue is
114 # min-heap of (trx_no, trx_sys.rseg_array index) pairs, where the key is trx_no,
115 # and it must not be that trx_no of the last parsed undo log of a committed
116 # transaction is greater than the last trx_no of the rseg at the top of
117 # the queue.
118 INSERT INTO t_2_1 SET a = 20;
119 INSERT INTO t_2_1 SET a = 30;
120 INSERT INTO t_2_1 SET a = 40;
121 INSERT INTO t_2_1 SET a = 50;
122 INSERT INTO t_2_1 SET a = 60;
123
124 # Assertion ut_a(tail.trx_no <= last_trx_no) failures in
125 # purge_sys_t::choose_next_log if the bug is not fixed.
126 SET GLOBAL innodb_max_purge_lag_wait=0;
127
128 --let $i=$transactions_count
129 while($i) {
130 --dec $i
131 if ($i == 0) {
132 --eval DROP TABLE t_1_$i
133 }
134 --eval DROP TABLE t_2_$i
135 }