Skip to content

Commit

Permalink
Adapt the innodb_undo tests from MySQL 5.7
Browse files Browse the repository at this point in the history
Simplify the tests that are present in MySQL 5.7. Make the table
smaller while generating enough undo log. Do not unnecessarily
drop tables.

trx_purge_initiate_truncate(): Remove two crash injection points
(before and after normal redo log checkpoint), because they are
not adding any value. Clarify some messages.

trx_sys_create_rsegs(): Display the number of active undo tablespaces.

srv_undo_tablespaces_init(): When initializing the data files, do not
leave srv_undo_tablespaces_active at 0.
Do not display that number; let trx_sys_create_rsegs() display it once
the final number is known.

innodb_params_adjust(): Adjust parameters after startup.

innobase_init(): Do not allow innodb_max_undo_size to be less
than SRV_UNDO_TABLESPACE_SIZE_IN_PAGES. This avoids unnecessary
repeated truncation of undo tablespaces when using
innodb_page_size=32k or innodb_page_size=64k.
  • Loading branch information
dr-m committed Apr 26, 2017
1 parent d1bcc1f commit ce3ffef
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 83 deletions.
4 changes: 4 additions & 0 deletions mysql-test/include/have_innodb_max_16k.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (`SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE LOWER(variable_name) = 'innodb_page_size' AND variable_value <= 16384`)
{
--skip Test requires InnoDB with page size not greater than 16k.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (`select count(*) = 0 from information_schema.global_variables where variable_name like 'innodb_undo_tablespaces' and variable_value >= 2`)
{
--skip Test requires InnoDB with at-least 2 undo tablespaces.
}
8 changes: 8 additions & 0 deletions mysql-test/suite/innodb_undo/include/truncate_recover.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
begin;
update t1 set c = 'MariaDB';
update t1 set c = 'InnoDB';
eval set global debug_dbug = '+d,$SEARCH_PATTERN';
commit;
--source include/shutdown_mysqld.inc
--source include/search_pattern_in_file.inc
--source include/start_mysqld.inc
11 changes: 11 additions & 0 deletions mysql-test/suite/innodb_undo/r/truncate.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET GLOBAL innodb_fast_shutdown=0;
create table t1(keyc int primary key, c1 char(100)) engine = innodb;
begin;
update t1 set c1 = 'mysql';
update t1 set c1 = 'oracle';
delete from t1;
commit;
drop table t1;
SET GLOBAL innodb_fast_shutdown=0;
SET GLOBAL innodb_undo_log_truncate=1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
51 changes: 51 additions & 0 deletions mysql-test/suite/innodb_undo/r/truncate_multi_client.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SET GLOBAL innodb_fast_shutdown=0;
create table t1(keyc int primary key, c char(100)) engine = innodb;
create table t2(keyc int primary key, c char(100)) engine = innodb;
CREATE PROCEDURE populate_t1()
BEGIN
DECLARE i INT DEFAULT 1;
while (i <= 20000) DO
insert into t1 values (i, 'a');
SET i = i + 1;
END WHILE;
END |
CREATE PROCEDURE populate_t2()
BEGIN
DECLARE i INT DEFAULT 1;
while (i <= 20000) DO
insert into t2 values (i, 'a');
SET i = i + 1;
END WHILE;
END |
connect con1,localhost,root,,;
begin;
call populate_t1();
connect con2,localhost,root,,;
begin;
call populate_t2();
connection con1;
update t1 set c = 'mysql';
connection con2;
update t2 set c = 'mysql';
connection con1;
update t1 set c = 'oracle';
connection con2;
update t2 set c = 'oracle';
connection con1;
delete from t1;
connection con2;
delete from t2;
connection con1;
commit;
disconnect con1;
connection con2;
commit;
disconnect con2;
connection default;
drop table t1, t2;
drop PROCEDURE populate_t1;
drop PROCEDURE populate_t2;
SET GLOBAL innodb_fast_shutdown=0;
SET GLOBAL innodb_undo_log_truncate=1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
FOUND 1 /Truncating UNDO tablespace 1/ in mysqld.1.err
15 changes: 15 additions & 0 deletions mysql-test/suite/innodb_undo/r/truncate_recover.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
create table t1(keyc int primary key, c char(100)) engine = innodb;
begin;
commit;
begin;
update t1 set c = 'MariaDB';
update t1 set c = 'InnoDB';
set global debug_dbug = '+d,ib_undo_trunc_before_truncate';
commit;
FOUND 1 /ib_undo_trunc_before_truncate/ in mysqld.1.err
begin;
update t1 set c = 'MariaDB';
update t1 set c = 'InnoDB';
set global debug_dbug = '+d,ib_undo_trunc_before_ddl_log_end';
commit;
FOUND 1 /ib_undo_trunc_before_ddl_log_end/ in mysqld.1.err
72 changes: 72 additions & 0 deletions mysql-test/suite/innodb_undo/t/truncate.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# WL#6965: Truncate UNDO logs.
#

--source include/have_innodb.inc
--source include/have_innodb_max_16k.inc
--source include/have_undo_tablespaces.inc

# The test is restarting the server to force undo truncation.
--source include/not_embedded.inc

SET GLOBAL innodb_fast_shutdown=0;
--let $restart_parameters=--innodb_undo_tablespaces=2 --innodb_undo_logs=4
--source include/restart_mysqld.inc

let MYSQLD_DATADIR = `select @@datadir`;

#-----------------------------------------------------------------------------
#
# 1. Perform enough DML action so that undo tablespace size grows beyond
# set threshold and then wait and see if it is being truncated.
#
create table t1(keyc int primary key, c1 char(100)) engine = innodb;
begin;
--disable_query_log
let $i=30000;
while ($i) {
eval insert into t1 values(30000-$i, '');
dec $i;
}
--enable_query_log
update t1 set c1 = 'mysql';
update t1 set c1 = 'oracle';
delete from t1;
commit;
drop table t1;

let CHECKFILE = $MYSQL_TMP_DIR/check.txt;
perl;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size1)
= stat("$ENV{MYSQLD_DATADIR}/undo001");
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size2)
= stat("$ENV{MYSQLD_DATADIR}/undo002");
open(OUT, ">$ENV{CHECKFILE}") || die;
print OUT "let \$size1='$size1,$size2';\n";
close(OUT);
EOF
SET GLOBAL innodb_fast_shutdown=0;
SET GLOBAL innodb_undo_log_truncate=1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
--source include/shutdown_mysqld.inc
--source $CHECKFILE
perl;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size1)
= stat("$ENV{MYSQLD_DATADIR}/undo001");
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size2)
= stat("$ENV{MYSQLD_DATADIR}/undo002");
open(OUT, ">$ENV{CHECKFILE}") || die;
print OUT "let \$size2='$size1,$size2';\n";
close(OUT);
EOF

--source $CHECKFILE
--remove_file $CHECKFILE

if ($size1 == $size2)
{
echo Truncation did not happen: $size1 == $size2;
}

--let $restart_parameters=
--source include/start_mysqld.inc
77 changes: 77 additions & 0 deletions mysql-test/suite/innodb_undo/t/truncate_multi_client.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# WL#6965: Truncate UNDO logs.
#

--source include/have_innodb.inc
# This test is restarting the server.
--source include/not_embedded.inc
# With larger innodb_page_size, the undo log tablespaces do not grow enough.
--source include/have_innodb_max_16k.inc
--source include/have_undo_tablespaces.inc

SET GLOBAL innodb_fast_shutdown=0;
--let $restart_parameters=--innodb_undo_tablespaces=2 --innodb_undo_logs=4
--source include/restart_mysqld.inc

#-----------------------------------------------------------------------------
#
# Perform DML action using multiple clients and multiple undo tablespace.
#
#
create table t1(keyc int primary key, c char(100)) engine = innodb;
create table t2(keyc int primary key, c char(100)) engine = innodb;
#
delimiter |;
CREATE PROCEDURE populate_t1()
BEGIN
DECLARE i INT DEFAULT 1;
while (i <= 20000) DO
insert into t1 values (i, 'a');
SET i = i + 1;
END WHILE;
END |
delimiter ;|
#
delimiter |;
CREATE PROCEDURE populate_t2()
BEGIN
DECLARE i INT DEFAULT 1;
while (i <= 20000) DO
insert into t2 values (i, 'a');
SET i = i + 1;
END WHILE;
END |
delimiter ;|
#
#
connect (con1,localhost,root,,);
begin;
send call populate_t1();

connect (con2,localhost,root,,);
begin;
send call populate_t2();

connection con1; reap; send update t1 set c = 'mysql';
connection con2; reap; send update t2 set c = 'mysql';
connection con1; reap; send update t1 set c = 'oracle';
connection con2; reap; send update t2 set c = 'oracle';
connection con1; reap; send delete from t1;
connection con2; reap; send delete from t2;
connection con1; reap; commit; disconnect con1;
connection con2; reap; commit; disconnect con2;

connection default;
drop table t1, t2;
drop PROCEDURE populate_t1;
drop PROCEDURE populate_t2;

SET GLOBAL innodb_fast_shutdown=0;
SET GLOBAL innodb_undo_log_truncate=1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;

--source include/restart_mysqld.inc

let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN = Truncating UNDO tablespace 1;
--source include/search_pattern_in_file.inc
50 changes: 50 additions & 0 deletions mysql-test/suite/innodb_undo/t/truncate_recover.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# WL#6965: Truncate UNDO logs.
#

--source include/have_innodb.inc
--source include/have_debug.inc
# With larger innodb_page_size, the undo log tablespaces do not grow enough.
--source include/have_innodb_max_16k.inc
--source include/have_undo_tablespaces.inc

# Valgrind would complain about memory leaks when we crash on purpose.
--source include/not_valgrind.inc
# Embedded server does not support crashing
--source include/not_embedded.inc
# Avoid CrashReporter popup on Mac
--source include/not_crashrep.inc

--disable_query_log
# FIXME: The doublewrite buffer should not issue these warnings.
# FIXME: Maybe buf_dblwr_process() should empty the buffer at the end?
call mtr.add_suppression("InnoDB: A copy of page.*in the doublewrite buffer slot.*is not within space bounds");
FLUSH TABLES;
--enable_query_log

--let $restart_parameters=--innodb-undo-logs=4 --innodb-undo-tablespaces=2 --innodb-undo-log-truncate=1 --innodb-max-undo-log-size=10485760 --innodb-purge-rseg-truncate-frequency=1 --innodb-fast-shutdown=0
--source include/restart_mysqld.inc

let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;

create table t1(keyc int primary key, c char(100)) engine = innodb;
begin;
--disable_query_log
let $i=30000;
while ($i) {
eval insert into t1 values(30000-$i, '');
dec $i;
}
--enable_query_log
commit;

let SEARCH_PATTERN = ib_undo_trunc_before_truncate;
--source include/truncate_recover.inc

let SEARCH_PATTERN = ib_undo_trunc_before_ddl_log_end;
--source include/truncate_recover.inc

let SEARCH_PATTERN = ib_undo_trunc_trunc_done;
let $restart_parameters=
--source include/truncate_recover.inc
drop table t1;
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ COUNT(@@GLOBAL.innodb_max_undo_log_size)
1
1 Expected
'#---------------------BS_STVARS_035_02----------------------#'
SET @save = @@GLOBAL.innodb_max_undo_log_size;
SET @@GLOBAL.innodb_max_undo_log_size=1073741824;
SELECT COUNT(@@GLOBAL.innodb_max_undo_log_size);
COUNT(@@GLOBAL.innodb_max_undo_log_size)
1
1 Expected
SET @@GLOBAL.innodb_max_undo_log_size=18446744073709551615;
SELECT @@GLOBAL.innodb_max_undo_log_size;
@@GLOBAL.innodb_max_undo_log_size
18446744073709551615
18446744073709551615 Expected
Warnings:
Warning 1292 Truncated incorrect innodb_max_undo_log_size value: '18446744073709551615'
SELECT FLOOR(@@GLOBAL.innodb_max_undo_log_size / @@GLOBAL.innodb_page_size);
FLOOR(@@GLOBAL.innodb_max_undo_log_size / @@GLOBAL.innodb_page_size)
4294967296
4294967296 Expected
SET @@GLOBAL.innodb_max_undo_log_size=1073741824;
SET GLOBAL innodb_max_undo_log_size = @save;
'#---------------------BS_STVARS_035_03----------------------#'
SELECT @@GLOBAL.innodb_max_undo_log_size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/sys_vars/r/sysvars_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1618,14 +1618,14 @@ READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME INNODB_MAX_UNDO_LOG_SIZE
SESSION_VALUE NULL
GLOBAL_VALUE 1073741824
GLOBAL_VALUE 10485760
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 1073741824
DEFAULT_VALUE 10485760
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Maximum size of UNDO tablespace in MB (If UNDO tablespace grows beyond this size it will be truncated in due course).
VARIABLE_COMMENT Desired maximum UNDO tablespace size in bytes
NUMERIC_MIN_VALUE 10485760
NUMERIC_MAX_VALUE 18446744073709551615
NUMERIC_MAX_VALUE 281474976710656
NUMERIC_BLOCK_SIZE 0
ENUM_VALUE_LIST NULL
READ_ONLY NO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ SELECT COUNT(@@GLOBAL.innodb_max_undo_log_size);
# Check if Value can set #
####################################################################

SET @save = @@GLOBAL.innodb_max_undo_log_size;

SET @@GLOBAL.innodb_max_undo_log_size=1073741824;

SELECT COUNT(@@GLOBAL.innodb_max_undo_log_size);
--echo 1 Expected

SET @@GLOBAL.innodb_max_undo_log_size=18446744073709551615;
SELECT @@GLOBAL.innodb_max_undo_log_size;
--echo 18446744073709551615 Expected
SELECT FLOOR(@@GLOBAL.innodb_max_undo_log_size / @@GLOBAL.innodb_page_size);
--echo 4294967296 Expected

SET @@GLOBAL.innodb_max_undo_log_size=1073741824;

SET GLOBAL innodb_max_undo_log_size = @save;

--echo '#---------------------BS_STVARS_035_03----------------------#'
#################################################################
# Check if the value in GLOBAL Table matches value in variable #
Expand Down
Loading

0 comments on commit ce3ffef

Please sign in to comment.