MDEV-35124 Set innodb_snapshot_isolation=ON by default

From the very beginning, the default InnoDB transaction isolation level
REPEATABLE READ does not correspond to any well formed definition.
The main issue is the lack of write/write conflict detection.
To fix that and to make REPEATABLE READ correspond to Snapshot Isolation,
b8a6719889 introduced the Boolean
session variable innodb_snapshot_isolation. It was disabled by default
in order not to break any user applications.

In a new major version of MariaDB Server, we had better enable this
parameter by default.
This commit is contained in:
Marko Mäkelä 2024-10-11 15:02:31 +03:00
parent 26dce1cec3
commit 4e1e9ea6f3
28 changed files with 35 additions and 3 deletions

View file

@ -1,5 +1,7 @@
SET @save_timeout = @@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout = 1;
SET @save_snapshot_isolation = @@GLOBAL.innodb_snapshot_isolation;
SET GLOBAL innodb_snapshot_isolation = OFF;
SET @save_isolation = @@GLOBAL.transaction_isolation;
SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
connection default;
@ -792,3 +794,4 @@ drop user mysqltest@localhost;
SET SQL_MODE=default;
SET GLOBAL innodb_lock_wait_timeout = @save_timeout;
SET GLOBAL transaction_isolation = @save_isolation;
SET GLOBAL innodb_snapshot_isolation = @save_snapshot_isolation;

View file

@ -18,6 +18,8 @@ let $engine_type= InnoDB;
SET @save_timeout = @@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout = 1;
SET @save_snapshot_isolation = @@GLOBAL.innodb_snapshot_isolation;
SET GLOBAL innodb_snapshot_isolation = OFF;
SET @save_isolation = @@GLOBAL.transaction_isolation;
SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
--disable_service_connection
@ -25,3 +27,4 @@ SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
--enable_service_connection
SET GLOBAL innodb_lock_wait_timeout = @save_timeout;
SET GLOBAL transaction_isolation = @save_isolation;
SET GLOBAL innodb_snapshot_isolation = @save_snapshot_isolation;

View file

@ -17,6 +17,7 @@ a
3
connection b;
set binlog_format=mixed;
set innodb_snapshot_isolation=OFF;
set session transaction isolation level repeatable read;
set autocommit=0;
update t1 set a=10 where a=5;

View file

@ -29,6 +29,7 @@ set autocommit=0;
select * from t1 where a=3 lock in share mode;
connection b;
set binlog_format=mixed;
set innodb_snapshot_isolation=OFF;
set session transaction isolation level repeatable read;
set autocommit=0;
-- error ER_LOCK_WAIT_TIMEOUT

View file

@ -77,6 +77,7 @@ COUNT(DISTINCT node_uuid) = 1
wsrep_gcomm_uuid_match
1
connection node_1;
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (30);
INSERT INTO t1 VALUES (31);
INSERT INTO t1 VALUES (32);

View file

@ -138,6 +138,7 @@ SELECT COUNT(DISTINCT node_uuid) = 1 FROM mysql.wsrep_streaming_log;
#
--connection node_1
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (30);
INSERT INTO t1 VALUES (31);
INSERT INTO t1 VALUES (32);

View file

@ -22,6 +22,7 @@ DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT, f2 CHAR(10)) ENGINE=InnoDB;
connection node_1;
SET innodb_snapshot_isolation = OFF;
SET SESSION wsrep_trx_fragment_size = 1;
START TRANSACTION;
INSERT INTO t1 VALUES (1, 'node1');

View file

@ -31,6 +31,7 @@ SET GLOBAL wsrep_cluster_address = '';
SET SESSION wsrep_sync_wait = 0;
SET SESSION wsrep_sync_wait = default;
connection node_1;
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (6);
INSERT INTO t1 VALUES (7);
INSERT INTO t1 VALUES (8);

View file

@ -24,6 +24,7 @@ SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log;
COUNT(*) = 0
1
connection node_1;
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (REPEAT('d', 512));
INSERT INTO t1 VALUES (REPEAT('e', 512));
INSERT INTO t1 VALUES (REPEAT('f', 512));

View file

@ -39,6 +39,7 @@ DROP TABLE t2;
#
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY AUTO_INCREMENT, f2 CHAR(10)) ENGINE=InnoDB;
--connection node_1
SET innodb_snapshot_isolation = OFF;
SET SESSION wsrep_trx_fragment_size = 1;
START TRANSACTION;
INSERT INTO t1 VALUES (1, 'node1');

View file

@ -58,6 +58,7 @@ SET SESSION wsrep_sync_wait = default;
# Continue generating events in the transaction
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (6);
INSERT INTO t1 VALUES (7);
INSERT INTO t1 VALUES (8);

View file

@ -38,6 +38,7 @@ SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log;
# Confirm that the transaction can be restarted on either node
--connection node_1
SET innodb_snapshot_isolation=OFF;
INSERT INTO t1 VALUES (REPEAT('d', 512));
INSERT INTO t1 VALUES (REPEAT('e', 512));
INSERT INTO t1 VALUES (REPEAT('f', 512));

View file

@ -10,6 +10,7 @@ SELECT * FROM t WHERE a = 20 FOR UPDATE;
a b
20 20
connect con_2,localhost,root,,;
SET innodb_snapshot_isolation=OFF;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
SET DEBUG_SYNC = 'lock_trx_handle_wait_enter SIGNAL upd_locked WAIT_FOR upd_cont EXECUTE 2';

View file

@ -8,6 +8,7 @@ SELECT * FROM t WHERE a = 20 FOR UPDATE;
a b
20 20
connect con_2,localhost,root,,;
SET innodb_snapshot_isolation=OFF;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN;
SET DEBUG_SYNC = 'lock_trx_handle_wait_before_unlocked_wait_lock_check SIGNAL upd_locked WAIT_FOR upd_cont';

View file

@ -8,6 +8,7 @@ SELECT * FROM t WHERE a = 20 FOR UPDATE;
a b
20 20
connect con_2,localhost,root,,;
SET innodb_snapshot_isolation=OFF;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET DEBUG_SYNC = 'lock_trx_handle_wait_enter SIGNAL upd_locked WAIT_FOR upd_cont';
SET DEBUG_SYNC = 'trx_t_release_locks_enter SIGNAL sel_cont WAIT_FOR upd_cont_2';

View file

@ -80,6 +80,7 @@ COUNT(*)
#
# Do some DML in the default connection and leave the transaction pending.
#
SET innodb_snapshot_isolation=OFF;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
UPDATE t1 SET c2 = c2 * 3 WHERE c1 = 1;
@ -140,6 +141,7 @@ COUNT(*)
# Connection 1 REPEATABLE READ
#
connect con1,localhost,root,,;
SET innodb_snapshot_isolation=OFF;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
########## innodb_isolation_selects.inc ##########

View file

@ -20,6 +20,7 @@ commit;
connection a;
commit;
connection b;
set innodb_snapshot_isolation=off;
set session transaction isolation level read committed;
update t1 set a=10 where a=5;
connection a;

View file

@ -17,6 +17,7 @@ insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
connect a,localhost,root,,;
connect b,localhost,root,,;
connection a;
set innodb_snapshot_isolation=OFF;
start transaction with consistent snapshot;
connection b;
start transaction;

View file

@ -11,6 +11,7 @@ a b
1 1
2 2
connect con_weird,localhost,root;
SET innodb_snapshot_isolation=OFF;
BEGIN;
SELECT * FROM t;
a b

View file

@ -27,6 +27,7 @@ SELECT * FROM t WHERE a = 20 FOR UPDATE;
# trx 1
--connect(con_2,localhost,root,,)
SET innodb_snapshot_isolation=OFF;
# RC is neccessary to do semi-consistent read
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN; # trx 2

View file

@ -34,6 +34,7 @@ SELECT * FROM t WHERE a = 20 FOR UPDATE;
--connect(con_2,localhost,root,,)
# RC is necessary to do semi-consistent read
SET innodb_snapshot_isolation=OFF;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
BEGIN; # trx 2
# The first time it will be hit on trying to lock (20,20), the second hit

View file

@ -33,6 +33,7 @@ UPDATE t2 SET a = a + 100;
SELECT * FROM t WHERE a = 20 FOR UPDATE;
--connect(con_2,localhost,root,,)
SET innodb_snapshot_isolation=OFF;
# RC is necessary to do semi-consistent read
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
# It will be hit on trying to lock (20,20).

View file

@ -45,6 +45,7 @@ INSERT INTO t2 (SELECT * FROM t1);
--echo #
--echo # Do some DML in the default connection and leave the transaction pending.
--echo #
SET innodb_snapshot_isolation=OFF;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
--enable_info
@ -59,6 +60,7 @@ DELETE FROM t1 WHERE c1 = 6;
--echo # Connection 1 REPEATABLE READ
--echo #
connect (con1,localhost,root,,);
SET innodb_snapshot_isolation=OFF;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN;
--source suite/innodb/include/innodb_isolation_selects.inc

View file

@ -28,6 +28,7 @@ connection a;
commit;
connection b;
# perform a semi-consisent read (and unlock non-matching rows)
set innodb_snapshot_isolation=off;
set session transaction isolation level read committed;
update t1 set a=10 where a=5;
connection a;

View file

@ -15,6 +15,7 @@ connect (a,localhost,root,,);
connect (b,localhost,root,,);
connection a;
set innodb_snapshot_isolation=OFF;
start transaction with consistent snapshot;
connection b;

View file

@ -10,6 +10,7 @@ CREATE TABLE t(a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t VALUES (1,1),(2,2);
BEGIN; SELECT * FROM t LOCK IN SHARE MODE;
--connect con_weird,localhost,root
SET innodb_snapshot_isolation=OFF;
BEGIN;
SELECT * FROM t;
--connect consistent,localhost,root

View file

@ -1353,8 +1353,8 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME INNODB_SNAPSHOT_ISOLATION
SESSION_VALUE OFF
DEFAULT_VALUE OFF
SESSION_VALUE ON
DEFAULT_VALUE ON
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BOOLEAN
VARIABLE_COMMENT Use snapshot isolation (write-write conflict detection)

View file

@ -871,7 +871,7 @@ static MYSQL_THDVAR_BOOL(table_locks, PLUGIN_VAR_OPCMDARG,
static MYSQL_THDVAR_BOOL(snapshot_isolation, PLUGIN_VAR_OPCMDARG,
"Use snapshot isolation (write-write conflict detection)",
NULL, NULL, FALSE);
NULL, NULL, TRUE);
static MYSQL_THDVAR_BOOL(strict_mode, PLUGIN_VAR_OPCMDARG,
"Use strict mode when evaluating create options",