mariadb/mysql-test/t/tc_heuristic_recover.test
Andrei Elkin 888a8b69bd MDEV-13437 InnoDB fails to return error for XA COMMIT or XA ROLLBACK in read-only mode
Assertions failed due to incorrect handling of the --tc-heuristic-recover
option when InnoDB is in read-only mode either due to innodb_read_only=1
or innodb_force_recovery>3. InnoDB failed to refuse a XA COMMIT or
XA ROLLBACK operation, and there were errors in the error handling in
the upper layer.

This was fixed by making InnoDB XA operations respect the
high_level_read_only flag. The InnoDB part of the fix and
parts of the test main.tc_heuristic_recover were provided
by Marko Mäkelä.

LOCK_log mutex lock/unlock had to be added to fix MDEV-13438.
The measure is confirmed by mysql sources as well.

For testing of the conflicting option combination, mysql-test-run is
made to export a new $MYSQLD_LAST_CMD. It holds the very last value
generated by mtr.mysqld_start().  Even though the options have been
also always stored in $mysqld->{'started_opts'} there were no access
to them beyond the automatic server restart by mtr through the expect
file interface.

Effectively therefore $MYSQLD_LAST_CMD represents a more general
interface to $mysqld->{'started_opts'} which can be used in wider
scopes including server launch with incompatible options.

Notice another existing method to restart the server with incompatible
options relying on $MYSQLD_CMD is is aware of $mysqld->{'started_opts'}
(the actual options that the server is launched by mtr). In order to use
this method they would have to be provided manually.

NOTE: When merging to 10.2, the file search_pattern_in_file++.inc
should be replaced with the pre-existing search_pattern_in_file.inc.
2017-08-29 11:59:59 +03:00

106 lines
4.1 KiB
Text

# The test verifies a few server/engine recovery option combinations.
# Specifically, MDEV-13437,13438 are concerned with no crashes
# due to InnoDB being read-only during --tc-heuristic-recover=ROLLBACK|COMMIT.
#
# Initially the test commits a transaction and in the following proceeds
# throughout some phases.
# Within them the server is shut down and attempted to restart, to succeed
# that in the end.
# All this proves no crashes and effective rollback of the transaction.
#
--source include/have_innodb.inc
# The test logics really requires --log-bin.
--source include/have_binlog_format_mixed.inc
--source include/have_debug_sync.inc
--source include/not_embedded.inc
call mtr.add_suppression("Can't init tc log");
call mtr.add_suppression("Found 1 prepared transactions!");
call mtr.add_suppression("Aborting");
# Now take a shapshot of the last time server options.
#
# The "restart" expect-file facility can't be engaged because the server
# having conflicting options may not succeed to boot up.
# Also notice $MYSQLD_CMD is too "static" being unaware of the actual options
# of the last (before shutdown or kill) server run.
# That's why $MYSQLD_LAST_CMD that allows for the server new start
# with more options appended to a stub set which is settled at this very point.
--let $mysqld_stub_cmd= $MYSQLD_LAST_CMD
--let $error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err
--let SEARCH_FILE= $error_log
set debug_sync='RESET';
CREATE TABLE t1 (i INT) ENGINE=InnoDB;
SET GLOBAL innodb_flush_log_at_trx_commit=1;
FLUSH TABLES; # we need the table post crash-restart, see MDEV-8841.
# Run transaction in a separate "prey" connection
--connect (con1,localhost,root,,)
# The signal won't arrive though
set debug_sync='ha_commit_trans_after_prepare WAIT_FOR go';
--send INSERT INTO t1 VALUES (1);
--connection default
--let $table= information_schema.processlist
--let $where= where state = 'debug sync point: ha_commit_trans_after_prepare'
--let $wait_condition= SELECT count(*) = 1 FROM $table $where
--source include/wait_condition.inc
--echo # Prove that no COMMIT or ROLLBACK occurred yet.
SELECT * FROM t1;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t1;
# TODO: MDEV-12700 Allow innodb_read_only startup without prior slow shutdown.
--source include/kill_mysqld.inc
--let $restart_parameters= --innodb-force-recovery=4
--source include/fail_start_mysqld.inc
--let SEARCH_PATTERN= was in the XA prepared state
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Found 1 prepared transactions!
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
--source include/search_pattern_in_file++.inc
--let $restart_parameters= --innodb-force-recovery=4 --tc-heuristic-recover=COMMIT
--source include/fail_start_mysqld.inc
--let SEARCH_PATTERN= was in the XA prepared state
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Found 1 prepared transactions!
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Please restart mysqld without --tc-heuristic-recover
--source include/search_pattern_in_file++.inc
--let $restart_parameters= --tc-heuristic-recover=ROLLBACK
--source include/fail_start_mysqld.inc
--let SEARCH_PATTERN= was in the XA prepared state
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Found 1 prepared transactions!
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= \\[ERROR\\] Can\\'t init tc log
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Please restart mysqld without --tc-heuristic-recover
--source include/search_pattern_in_file++.inc
--let $restart_parameters=
--source include/start_mysqld.inc
--let SEARCH_PATTERN= was in the XA prepared state
--source include/search_pattern_in_file++.inc
--let SEARCH_PATTERN= Found 1 prepared transactions!
--source include/search_pattern_in_file++.inc
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT * FROM t1;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t1;
#
# Cleanup
#
DROP TABLE t1;