mirror of
https://github.com/MariaDB/server.git
synced 2025-02-07 06:12:18 +01:00
ddd7d5d8e3
Under unknown circumstances, the SQL layer may wrongly disregard an invocation of thd_mark_transaction_to_rollback() when an InnoDB transaction had been aborted (rolled back) due to one of the following errors: * HA_ERR_LOCK_DEADLOCK * HA_ERR_RECORD_CHANGED (if innodb_snapshot_isolation=ON) * HA_ERR_LOCK_WAIT_TIMEOUT (if innodb_rollback_on_timeout=ON) Such an error used to cause a crash of InnoDB during transaction commit. These changes aim to catch and report the error earlier, so that not only this crash can be avoided but also the original root cause be found and fixed more easily later. The idea of this fix is from Michael 'Monty' Widenius. HA_ERR_ROLLBACK: A new error code that will be translated into ER_ROLLBACK_ONLY, signalling that the current transaction has been aborted and the only allowed action is ROLLBACK. trx_t::state: Add TRX_STATE_ABORTED that is like TRX_STATE_NOT_STARTED, but noting that the transaction had been rolled back and aborted. trx_t::is_started(): Replaces trx_is_started(). ha_innobase: Check the transaction state in various places. Simplify the logic around SAVEPOINT. ha_innobase::is_valid_trx(): Replaces ha_innobase::is_read_only(). The InnoDB logic around transaction savepoints, commit, and rollback was unnecessarily complex and might have contributed to this inconsistency. So, we are simplifying that logic as well. trx_savept_t: Replace with const undo_no_t*. When we rollback to a savepoint, all we need to know is the number of undo log records that must survive. trx_named_savept_t, DB_NO_SAVEPOINT: Remove. We can store undo_no_t directly in the space allocated at innobase_hton->savepoint_offset. fts_trx_create(): Do not copy previous savepoints. fts_savepoint_rollback(): If a savepoint was not found, roll back everything after the default savepoint of fts_trx_create(). The test innodb_fts.savepoint is extended to cover this code. Reviewed by: Vladislav Lesin Tested by: Matthias Leich
110 lines
3.7 KiB
Text
110 lines
3.7 KiB
Text
#
|
|
# Ensure that the number of locks (SELECT FOR UPDATE for example) is
|
|
# added to the number of altered rows when choosing the smallest
|
|
# transaction to kill as a victim when a deadlock is detected.
|
|
# Also transactions what had edited non-transactional tables should
|
|
# be heavier than ones that had not.
|
|
#
|
|
|
|
--disable_query_log
|
|
call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
|
|
--enable_query_log
|
|
|
|
-- source include/have_innodb.inc
|
|
|
|
SET default_storage_engine=InnoDB;
|
|
|
|
# we do not really care about what gets printed, we are only
|
|
# interested in getting the deadlock resolved according to our
|
|
# expectations
|
|
-- disable_query_log
|
|
-- disable_result_log
|
|
|
|
# we want to use "-- eval statement1; statement2" which does not work with
|
|
# prepared statements. Because this test should not behave differently with
|
|
# or without prepared statements we disable them so the test does not fail
|
|
# if someone runs ./mysql-test-run.pl --ps-protocol
|
|
-- disable_ps_protocol
|
|
|
|
# we will create a simple deadlock with t1, t2 and two connections
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE TABLE t2 (a INT);
|
|
|
|
# auxiliary table with a bulk of rows which will be locked by a
|
|
# transaction to increase its weight
|
|
CREATE TABLE t3 (a INT);
|
|
|
|
# auxiliary empty table which will be inserted by a
|
|
# transaction to increase its weight
|
|
CREATE TABLE t4 (a INT);
|
|
|
|
# auxiliary non-transactional table which will be edited by a
|
|
# transaction to tremendously increase its weight
|
|
CREATE TABLE t5_nontrans (a INT) ENGINE=MyISAM;
|
|
|
|
INSERT INTO t1 VALUES (1);
|
|
INSERT INTO t2 VALUES (1);
|
|
# insert a lot of rows in t3
|
|
INSERT INTO t3 VALUES (1);
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
INSERT INTO t3 SELECT * FROM t3;
|
|
|
|
# test locking weight
|
|
|
|
-- let $con1_extra_sql =
|
|
-- let $con1_extra_sql_present = 0
|
|
-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
|
|
-- let $con2_extra_sql_present = 1
|
|
-- let $con1_should_be_rolledback = 1
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1)
|
|
-- let $con1_extra_sql_present = 1
|
|
-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
|
|
-- let $con2_extra_sql_present = 1
|
|
-- let $con1_should_be_rolledback = 1
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1), (1), (1), (1)
|
|
-- let $con1_extra_sql_present = 1
|
|
-- let $con2_extra_sql = SELECT * FROM t3 FOR UPDATE
|
|
-- let $con2_extra_sql_present = 1
|
|
-- let $con1_should_be_rolledback = 1
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
# test weight when non-transactional tables are edited
|
|
|
|
-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
|
|
-- let $con1_extra_sql_present = 1
|
|
-- let $con2_extra_sql =
|
|
-- let $con2_extra_sql_present = 0
|
|
-- let $con1_should_be_rolledback = 0
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
|
|
-- let $con1_extra_sql_present = 1
|
|
-- let $con2_extra_sql = INSERT INTO t5_nontrans VALUES (1)
|
|
-- let $con2_extra_sql_present = 1
|
|
-- let $con1_should_be_rolledback = 1
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
-- let $con1_extra_sql = INSERT INTO t4 VALUES (1), (1), (1)
|
|
-- let $con1_extra_sql = $con1_extra_sql; INSERT INTO t5_nontrans VALUES (1)
|
|
-- let $con1_extra_sql_present = 1
|
|
-- let $con2_extra_sql = INSERT INTO t5_nontrans VALUES (1)
|
|
-- let $con2_extra_sql_present = 1
|
|
-- let $con1_should_be_rolledback = 0
|
|
-- source include/innodb_trx_weight.inc
|
|
|
|
DROP TABLE t1, t2, t3, t4, t5_nontrans;
|
|
|
|
call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");
|