Debian Codegraph @

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

raw
1 --source include/have_debug.inc # --debug=+d,crash_after_checkpoint
2
3 # This test might take long time if the number of cpu cores dedicated
4 # to run the test is not high enough. That is because, this test uses
5 # 50 connections in parallel to generate a lot of redo log data before
6 # forcing a crash.
7 #
8 # Therefore, run it only when the --big-test mtr-flag is present.
9 --source include/big_test.inc
10
11 # We want to quickly produce redo which is difficult to consume.
12 # We will modify just one field (val++) in a large record (~1k)
13 # which means transaction threads will write just a few bytes
14 # related to val fields of just several (16?) records on page,
15 # while page cleaners need to flush whole page.
16 # We need CHAR not VARCHAR so whole space is always used
17 # (for the same reason it must be NOT NULL).
18 CREATE TABLE t (
19 id INT PRIMARY KEY,
20 val INT NOT NULL DEFAULT 0,
21 pad1 CHAR(250) NOT NULL DEFAULT "a",
22 pad2 CHAR(250) NOT NULL DEFAULT "a",
23 pad3 CHAR(250) NOT NULL DEFAULT "a",
24 pad4 CHAR(250) NOT NULL DEFAULT "a"
25 );
26 INSERT INTO t (id) VALUES (1);
27 let $i=0;
28 # Make the table large enough to span a lot of pages, so that page
29 # cleaners need to flush many different pages, not just a few to
30 # cover whole dirty set of pages mentioned in redo log.
31 while ($i < 16) {
32 # We specify id manually to not have any gaps in numbering which
33 # could happen in case of AUTO_INCREMENT id.
34 INSERT INTO t (id) SELECT id + (SELECT MAX(id) FROM t) FROM t;
35 inc $i;
36 }
37 SELECT COUNT(*) FROM t;
38 # Note we also make that t is small enough to fit in BP, and not trigger flushing
39 # due to too many dirty pages/too little free pages etc. Which you can check using:
40 SELECT (SUM(IF(type='t',cnt,0))/SUM(cnt)) BETWEEN 0.25 AND 0.75 AS is_ratio_ok
41 FROM (
42 SELECT
43 IF(SPACE=(SELECT SPACE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME='test/t'),'t','other') AS type,
44 COUNT(*) as cnt
45 FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
46 GROUP BY 1
47 ORDER BY 2 DESC
48 ) AS aux;
49 # We will need to generate redo log in a loop to happen continuously in background,
50 # while MTR will spawn more clients and do more stuff, so we use a stored procedure.
51 DELIMITER |;
52 CREATE PROCEDURE log_spammer(f INT,t INT)
53 BEGIN
54 WHILE 1 DO
55 START TRANSACTION;
56 UPDATE t SET val = val + 1 WHERE id BETWEEN f AND t-1;
57 COMMIT;
58 END WHILE;
59 END|
60 DELIMITER ;|
61 # We spawn many connections and give each of them a disjoint
62 # fragment to work on to avoid synchronization between them.
63 let $connections=50;
64 let $span=`SELECT FLOOR(COUNT(*)/$connections) FROM t;`;
65 let $i=0;
66 while ($i < $connections) {
67 --connect(C$i,localhost,root,,test)
68 --send_eval CALL log_spammer($i*$span,($i+1)*$span)
69 inc $i;
70 }
71
72 --connection default
73 echo Waiting for checkpoint age to be big enough to force a checkpoint even during recovery;
74 SET GLOBAL innodb_checkpoint_disabled = 1;
75 # The value of 6945280 is log.aggressive_checkpoint_min_age and 1200796 is margin = log_free_check_margin(log);
76 # observed in log_should_checkpoint() function during recovery.
77 # We want this function to return true, so we need large checkpoint age.
78 # The 32000 is just some value I found sufficient to give ourselves some time to request crash but not enough to
79 # page cleaners to eat too much as they become more and more agressive as redo grows longer.
80 # In particular I found myself unable to reach log_lsn_checkpoint_age > 6945280 even with 50 user threads vs 1 PC.
81 let $wait_timeout=600;
82 let $wait_condition=SELECT COUNT(*) FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME='log_lsn_checkpoint_age' AND `COUNT` > 6945280-1200796+32000;
83 let $silent_failure=1;
84 --source include/wait_condition.inc
85 if (!$success) {
86 --skip Skip rest of the test due to timeout on waiting for big enough checkpoint age
87 }
88 let $silent_failure=0;
89 --source include/kill_mysqld.inc
90 # This message is after the kill, not before, to minimize delay between satisfying wait_condition and kill.
91 --echo Killed the server while it had large checkpoint age
92 --echo Starting server making it crash as soon as it creates a checkpoint
93 --error 137
94 --exec $MYSQLD_CMD --debug=+d,crash_after_checkpoint
95 --echo Starting the usual way
96 --source include/start_mysqld.inc
97 SELECT COUNT(*) FROM t;
98 let $i=0;
99 while ($i < $connections) {
100 --disconnect C$i
101 # as each transaction of each thread always sets the same value to all rows in given range
102 # we exepct exactly one distinct value in each range
103 --eval SELECT COUNT(DISTINCT(val)) FROM t WHERE id BETWEEN $i*$span AND ($i+1)*$span-1;
104 inc $i;
105 }
106 CHECK TABLE t;
107 DROP PROCEDURE log_spammer;
108 DROP TABLE t;