mirror of
https://github.com/MariaDB/server.git
synced 2025-02-10 15:35:34 +01:00
![Marko Mäkelä](/assets/img/avatar_default.png)
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
112 lines
3.7 KiB
Text
112 lines
3.7 KiB
Text
source include/have_innodb.inc;
|
|
|
|
--disable_query_log
|
|
call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
|
|
--enable_query_log
|
|
|
|
#
|
|
# MDEV-20354 All but last insert ignored in InnoDB tables when table locked
|
|
#
|
|
rename table mysql.table_stats to mysql.table_stats_save;
|
|
flush tables;
|
|
set use_stat_tables= PREFERABLY;
|
|
create table t1 (a int) engine=InnoDB;
|
|
start transaction;
|
|
insert t1 values (1);
|
|
insert t1 values (2);
|
|
commit;
|
|
select * from t1;
|
|
drop table t1;
|
|
rename table mysql.table_stats_save to mysql.table_stats;
|
|
flush tables;
|
|
|
|
--echo #
|
|
--echo # MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed
|
|
--echo #
|
|
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
|
|
XA START 'test';
|
|
SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE;
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1';
|
|
XA END 'test';
|
|
XA ROLLBACK 'test';
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing "InnoDB: Column last_update in table mysql.innodb_table_stats is BINARY(4) NOT NULL but should be INT UNSIGNED NOT NULL"
|
|
--echo #
|
|
|
|
# The following tests demonstrate that these columns:
|
|
# - innodb_table_stats.last_update
|
|
# - innodb_index_stats.last_update
|
|
# have sane values close to NOW(), rather than any garbage,
|
|
# with all TIMESTAMP formats.
|
|
|
|
--echo #
|
|
--echo # Testing a non-default format: Field_timestamp0 - UINT4 based
|
|
--echo #
|
|
|
|
SET @@global.mysql56_temporal_format=0;
|
|
ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP;
|
|
ALTER TABLE mysql.innodb_index_stats MODIFY last_update TIMESTAMP;
|
|
SHOW COLUMNS FROM mysql.innodb_table_stats LIKE 'last_update';
|
|
SHOW COLUMNS FROM mysql.innodb_index_stats LIKE 'last_update';
|
|
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=1;
|
|
|
|
SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_table_stats
|
|
WHERE database_name='test' AND table_name='t1';
|
|
SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats
|
|
WHERE database_name='test' AND table_name='t1' AND stat_name='size';
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # Now as the table t1 is dropped, expect no statistics
|
|
--echo #
|
|
|
|
SELECT * FROM mysql.innodb_table_stats
|
|
WHERE database_name='test' AND table_name='t1';
|
|
SELECT * FROM mysql.innodb_index_stats
|
|
WHERE database_name='test' AND table_name='t1' AND stat_name='size';
|
|
|
|
--echo #
|
|
--echo # Testing with the default format: Field_timestampf - BINARY(4) based with the UNSIGNED_FLAG
|
|
--echo #
|
|
|
|
SET @@global.mysql56_temporal_format=1;
|
|
ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP;
|
|
ALTER TABLE mysql.innodb_index_stats MODIFY last_update TIMESTAMP;
|
|
SHOW COLUMNS FROM mysql.innodb_table_stats LIKE 'last_update';
|
|
SHOW COLUMNS FROM mysql.innodb_index_stats LIKE 'last_update';
|
|
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=1;
|
|
SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_table_stats
|
|
WHERE database_name='test' AND table_name='t1';
|
|
SELECT TIMESTAMPDIFF(DAY,last_update,now())<=1 FROM mysql.innodb_index_stats
|
|
WHERE database_name='test' AND table_name='t1' AND stat_name='size';
|
|
DROP TABLE t1;
|
|
|
|
--echo #
|
|
--echo # MDEV-34207: ALTER TABLE...STATS_PERSISTENT=0 fails to drop statistics
|
|
--echo #
|
|
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
|
|
ALTER TABLE t1 STATS_PERSISTENT 0;
|
|
DROP TABLE t1;
|
|
|
|
SET @save_persistent=@@GLOBAL.innodb_stats_persistent;
|
|
SET GLOBAL innodb_stats_persistent=1;
|
|
|
|
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB;
|
|
RENAME TABLE t2 TO t1;
|
|
|
|
DROP TABLE t1;
|
|
SET GLOBAL innodb_stats_persistent=0;
|
|
|
|
CREATE TABLE t2 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
|
|
RENAME TABLE t2 TO t1;
|
|
|
|
SET GLOBAL innodb_stats_persistent=@save_persistent;
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (c1 INT) ENGINE=InnoDB STATS_PERSISTENT 1;
|
|
DROP TABLE t1;
|
|
|
|
--echo # End of 10.6 tests
|