Skip to content

MDEV-36330: SERIALIZABLE read inconsistency #4050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 10.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions mysql-test/suite/innodb/r/lock_isolation.result
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ SELECT * FROM t FORCE INDEX (b) FOR UPDATE;
a b
1 NULL
COMMIT;
disconnect con_weird;
connection consistent;
SELECT * FROM t FORCE INDEX (b) FOR UPDATE;
a b
Expand Down Expand Up @@ -230,9 +229,35 @@ UPDATE t SET b=4 WHERE a=1;
connection consistent;
SELECT * FROM t WHERE a=1 FOR UPDATE;
ERROR HY000: Record has changed since last read in table 't'
disconnect consistent;
disconnect disable_purging;
connection default;
SET DEBUG_SYNC="RESET";
DROP TABLE t;
CREATE TABLE t1(a INT) ENGINE=InnoDB STATS_PERSISTENT=0;
CREATE TABLE t2(a INT) ENGINE=InnoDB STATS_PERSISTENT=0;
BEGIN;
INSERT INTO t1 SET a=1;
connection con_weird;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t2 SET a=1;
connection consistent;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
INSERT INTO t2 SET a=2;
connection default;
COMMIT;
connection con_weird;
SELECT * FROM t1;
a
1
COMMIT;
disconnect con_weird;
connection consistent;
SELECT * FROM t1;
ERROR HY000: Record has changed since last read in table 't1'
COMMIT;
disconnect consistent;
connection default;
DROP TABLE t1,t2;
# End of 10.6 tests
25 changes: 23 additions & 2 deletions mysql-test/suite/innodb/t/lock_isolation.test
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ ROLLBACK;
--reap
SELECT * FROM t FORCE INDEX (b) FOR UPDATE;
COMMIT;
--disconnect con_weird

--connection consistent
SELECT * FROM t FORCE INDEX (b) FOR UPDATE;
Expand Down Expand Up @@ -246,12 +245,34 @@ UPDATE t SET b=4 WHERE a=1;
--connection consistent
--error ER_CHECKREAD
SELECT * FROM t WHERE a=1 FOR UPDATE;
--disconnect consistent
--disconnect disable_purging

--connection default
SET DEBUG_SYNC="RESET";
DROP TABLE t;

CREATE TABLE t1(a INT) ENGINE=InnoDB STATS_PERSISTENT=0;
CREATE TABLE t2(a INT) ENGINE=InnoDB STATS_PERSISTENT=0;
BEGIN; INSERT INTO t1 SET a=1;
--connection con_weird
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN; INSERT INTO t2 SET a=1;
--connection consistent
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN; INSERT INTO t2 SET a=2;
--connection default
COMMIT;
--connection con_weird
SELECT * FROM t1;
COMMIT;
--disconnect con_weird
--connection consistent
--error ER_CHECKREAD
SELECT * FROM t1;
COMMIT;
--disconnect consistent
--connection default
DROP TABLE t1,t2;

--source include/wait_until_count_sessions.inc
--echo # End of 10.6 tests
3 changes: 2 additions & 1 deletion sql/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ bool trans_begin(THD *thd, uint flags)
#endif //EMBEDDED_LIBRARY

/* ha_start_consistent_snapshot() relies on OPTION_BEGIN flag set. */
if (flags & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
if ((flags & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) ||
thd->tx_isolation == ISO_SERIALIZABLE)
{
#ifndef EMBEDDED_LIBRARY
if (thd->variables.session_track_transaction_info > TX_TRACK_NONE)
Expand Down
7 changes: 3 additions & 4 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4476,15 +4476,14 @@ innobase_start_trx_and_assign_read_view(
trx->isolation_level = innobase_map_isolation_level(
thd_get_trx_isolation(thd)) & 3;

if (trx->isolation_level == TRX_ISO_REPEATABLE_READ) {
if (trx->isolation_level != TRX_ISO_READ_UNCOMMITTED) {
trx->read_view.open(trx);
} else {
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
HA_ERR_UNSUPPORTED,
"InnoDB: WITH CONSISTENT SNAPSHOT"
" was ignored because this phrase"
" can only be used with"
" REPEATABLE READ isolation level.");
" is ignored at READ UNCOMMITTED"
" isolation level.");
}

/* Set the MySQL flag to mark that there is an active transaction */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
--- suite/storage_engine/trx/cons_snapshot_serializable.result
+++ suite/storage_engine/trx/cons_snapshot_serializable.reject
@@ -5,12 +5,15 @@
CREATE TABLE t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
+Warnings:
+Warning 138 InnoDB: WITH CONSISTENT SNAPSHOT was ignored because this phrase can only be used with REPEATABLE READ isolation level.
connection con2;
INSERT INTO t1 (a) VALUES (1);
connection con1;
@@ -11,6 +11,7 @@
# If consistent read works on this isolation level (SERIALIZABLE), the following SELECT should not return the value we inserted (1)
SELECT a FROM t1;
a
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
+Warnings:
+Warning 138 InnoDB: WITH CONSISTENT SNAPSHOT was ignored because this phrase can only be used with REPEATABLE READ isolation level.
+Warning 138 InnoDB: WITH CONSISTENT SNAPSHOT is ignored at READ UNCOMMITTED isolation level.
connection con2;
INSERT INTO t1 (a) VALUES (1);
connection con1;