mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +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
76 lines
2.8 KiB
Text
76 lines
2.8 KiB
Text
--source include/have_innodb.inc
|
|
--source include/have_debug.inc
|
|
--source include/have_debug_sync.inc
|
|
--source include/count_sessions.inc
|
|
|
|
--disable_query_log
|
|
call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
|
|
--enable_query_log
|
|
|
|
--connect (pause_purge,localhost,root)
|
|
START TRANSACTION WITH CONSISTENT SNAPSHOT;
|
|
|
|
--connection default
|
|
CREATE TABLE t (pk int PRIMARY KEY, sk INT UNIQUE) ENGINE=InnoDB;
|
|
INSERT INTO t VALUES (10, 100);
|
|
|
|
--connect (con1,localhost,root)
|
|
BEGIN; # trx 0
|
|
SELECT * FROM t WHERE sk = 100 FOR UPDATE;
|
|
|
|
--connect (con2,localhost,root)
|
|
SET DEBUG_SYNC="lock_wait_start SIGNAL insert_wait_started";
|
|
# trx 1 is locked on try to read the record in secondary index during duplicates
|
|
# check. It's the first in waiting queue, that's why it will be woken up firstly
|
|
# when trx 0 commits.
|
|
--send INSERT INTO t VALUES (5, 100) # trx 1
|
|
|
|
--connect (con3,localhost,root)
|
|
# MDEV-30225 is fixed only for RR
|
|
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
|
|
SET DEBUG_SYNC="now WAIT_FOR insert_wait_started";
|
|
SET DEBUG_SYNC="lock_wait_start SIGNAL delete_started_waiting";
|
|
# trx 2 can delete (5, 100) on master, but not on slave, as on slave trx 1
|
|
# can insert (5, 100) after trx 2 positioned it's cursor. Trx 2 lock is placed
|
|
# in waiting queue after trx 1 lock, but its persistent cursor position was
|
|
# stored on (100, 10) record in secondary index before suspending. After trx 1
|
|
# is committed, trx 2 will restore persistent cursor position on (100, 10). As
|
|
# (100, 5) secondary index record was inserted before (100, 10) in logical
|
|
# order, and (100, 10) record is delete-marked, trx 2 just continues scanning.
|
|
#
|
|
# Note. There can be several records with the same key in unique secondary
|
|
# index, but only one of them must be non-delete-marked. That's why when we do
|
|
# point query, cursor position is set in the first record in logical order, and
|
|
# then records are iterated until either non-delete-marked record is found or
|
|
# all records with the same unique fields are iterated.
|
|
--send DELETE FROM t WHERE sk = 100 # trx 2
|
|
|
|
--connection con1
|
|
SET DEBUG_SYNC="now WAIT_FOR delete_started_waiting";
|
|
DELETE FROM t WHERE sk=100; # trx 0
|
|
COMMIT;
|
|
--disconnect con1
|
|
|
|
--connection con2
|
|
--reap
|
|
--disconnect con2
|
|
|
|
--connection con3
|
|
# If the bug is fixed, deadlock error will be there, as trx 2 owns
|
|
# next-key lock waiting for trx 1, and trx 1 requests
|
|
# insert-intention lock, conflicting with trx 2 next-key lock.
|
|
--error ER_LOCK_DEADLOCK
|
|
--reap
|
|
--disconnect con3
|
|
|
|
--connection default
|
|
# If the bug is not fixed, we will see the row inserted by trx 1 here. This can
|
|
# cause duplicate key error on slave, when some other trx tries in insert row
|
|
# with the same secondary key, as was inserted by trx 1, and not deleted by trx
|
|
# 2.
|
|
SELECT * FROM t;
|
|
|
|
--disconnect pause_purge
|
|
SET DEBUG_SYNC="RESET";
|
|
DROP TABLE t;
|
|
--source include/wait_until_count_sessions.inc
|