#
# Tests for the changed page tracking bitmap crash recovery and very fast shutdowns
#
--source include/have_innodb.inc
--source include/not_embedded.inc
--source include/not_crashrep.inc
--source include/have_debug.inc
--source include/not_valgrind.inc

call mtr.add_suppression("last tracked LSN in");

RESET CHANGED_PAGE_BITMAPS;

# Generate log data that is larger than the log capacity and has two tablespace ids.
CREATE TABLE t1 (x INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
INSERT INTO t1 SELECT x FROM t1;
CREATE TABLE t2 (x INT) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1),(2),(3),(4),(5);

#
# Test the very fast server shutdown
#
SET GLOBAL INNODB_FAST_SHUTDOWN=2;

--echo 1st restart
--source include/restart_mysqld.inc

--let $assert_text= There should not be a hole in the tracked LSN range
--let $assert_cond= COUNT(*) FROM INFORMATION_SCHEMA.INNODB_CHANGED_PAGES
--source include/assert.inc

#
# Test crash right before writing of new bitmap data
#

--echo 2nd restart
--let $restart_parameters=restart:--debug="+d,crash_before_bitmap_write"
--source include/restart_mysqld.inc
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--error 2013
INSERT INTO t1 SELECT x FROM t1;
--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_reconnect

--let $assert_text= There should not be a hole in the tracked LSN range
--let $assert_cond= COUNT(*) FROM INFORMATION_SCHEMA.INNODB_CHANGED_PAGES
--source include/assert.inc

DROP TABLE t1, t2;
