Skip to content

Commit

Permalink
MDEV-13520 InnoDB attempts UPDATE with DB_TRX_ID=0 if innodb_force_re…
Browse files Browse the repository at this point in the history
…covery=3

trx_set_rw_mode(): Check the flag high_level_read_only instead
of testing srv_force_recovery (innodb_force_recovery) directly.
There is no need to prevent the creation of read-write transactions
if innodb_force_recovery=3 is used. Yes, in that mode any recovered
incomplete transactions will not be rolled back, but these transactions
will continue to hold locks on the records that they have modified.
If the new read-write transactions hit conflicts with already existing
(possibly recovered) transactions, the lock wait timeout mechanism
will work just fine.
  • Loading branch information
dr-m committed Aug 15, 2017
1 parent a5e4365 commit b4f6b67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions mysql-test/suite/innodb/r/read_only_recovery.result
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
connect con1, localhost, root;
CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t VALUES(1);
BEGIN;
INSERT INTO t VALUES(1),(2);
INSERT INTO t VALUES(2);
DELETE FROM t WHERE a=2;
connection default;
# Normal MariaDB shutdown would roll back the above transaction.
Expand All @@ -16,20 +17,23 @@ ROLLBACK;
disconnect con1;
SELECT * FROM t;
a
1
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t;
a
1
UPDATE t SET a=3 WHERE a=1;
# Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED.
# In earlier versions, this would return the last committed version
# (empty table)!
SELECT * FROM t;
a
1
3
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t;
a
1
3
SELECT * FROM t;
a
3
DROP TABLE t;
4 changes: 3 additions & 1 deletion mysql-test/suite/innodb/t/read_only_recovery.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

--connect(con1, localhost, root)
CREATE TABLE t(a INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t VALUES(1);
BEGIN;
# Generate insert_undo log.
INSERT INTO t VALUES(1),(2);
INSERT INTO t VALUES(2);
# Generate update_undo log.
DELETE FROM t WHERE a=2;
--connection default
Expand All @@ -27,6 +28,7 @@ ROLLBACK;
SELECT * FROM t;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t;
UPDATE t SET a=3 WHERE a=1;
--let $restart_parameters= --innodb-read-only
--source include/restart_mysqld.inc
--echo # Starting with MariaDB 10.2, innodb_read_only implies READ UNCOMMITTED.
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/trx/trx0trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,7 @@ trx_set_rw_mode(
ut_ad(!trx->in_rw_trx_list);
ut_ad(!trx_is_autocommit_non_locking(trx));

if (srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO) {
if (high_level_read_only) {
return;
}

Expand Down

0 comments on commit b4f6b67

Please sign in to comment.