Bug #121903 SET PERSIST can persist the value of a concurrent SET GLOBAL
Description:
SET PERSIST sets the global value, releases LOCK_global_system_variables,
and then reads the current global value back to store it as the persisted
value. A SET GLOBAL of the same variable by another session in between
changes the value that is read. The persisted value is then the value of the
other session's SET GLOBAL, which that session did not ask to persist, and
not the value given to SET PERSIST.
In the test below one session only runs SET PERSIST max_connections = 200,
and the other only runs SET GLOBAL max_connections = 300. Right after each
SET PERSIST, performance_schema.persisted_variables shows 300 in about 1 to
2.5% of the iterations:
8.4.11: 200 19517, 300 483
9.7.4: 200 19794, 300 206
trunk: 200 19514, 300 486
How to repeat:
Session 1:
CREATE DATABASE t;
CREATE TABLE t.seen (v VARCHAR(16));
DELIMITER //
CREATE PROCEDURE t.persist_loop(n INT)
BEGIN
WHILE n > 0 DO
SET PERSIST max_connections = 200;
INSERT INTO t.seen SELECT VARIABLE_VALUE FROM performance_schema.persisted_variables
WHERE VARIABLE_NAME = 'max_connections';
SET n = n - 1;
END WHILE;
END //
CREATE PROCEDURE t.global_loop(n INT)
BEGIN
WHILE n > 0 DO
SET GLOBAL max_connections = 300;
SET n = n - 1;
END WHILE;
END //
DELIMITER ;
Session 2:
CALL t.global_loop(2000000);
Session 1, while session 2 runs:
CALL t.persist_loop(20000);
SELECT v, COUNT(*) FROM t.seen GROUP BY v ORDER BY v;
Expected: only 200.
Actual: some rows show 300.
The attached persist_race.sh does all of this:
BASEDIR=/path/to/mysql ./persist_race.sh
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: SET PERSIST sets the global value, releases LOCK_global_system_variables, and then reads the current global value back to store it as the persisted value. A SET GLOBAL of the same variable by another session in between changes the value that is read. The persisted value is then the value of the other session's SET GLOBAL, which that session did not ask to persist, and not the value given to SET PERSIST. In the test below one session only runs SET PERSIST max_connections = 200, and the other only runs SET GLOBAL max_connections = 300. Right after each SET PERSIST, performance_schema.persisted_variables shows 300 in about 1 to 2.5% of the iterations: 8.4.11: 200 19517, 300 483 9.7.4: 200 19794, 300 206 trunk: 200 19514, 300 486 How to repeat: Session 1: CREATE DATABASE t; CREATE TABLE t.seen (v VARCHAR(16)); DELIMITER // CREATE PROCEDURE t.persist_loop(n INT) BEGIN WHILE n > 0 DO SET PERSIST max_connections = 200; INSERT INTO t.seen SELECT VARIABLE_VALUE FROM performance_schema.persisted_variables WHERE VARIABLE_NAME = 'max_connections'; SET n = n - 1; END WHILE; END // CREATE PROCEDURE t.global_loop(n INT) BEGIN WHILE n > 0 DO SET GLOBAL max_connections = 300; SET n = n - 1; END WHILE; END // DELIMITER ; Session 2: CALL t.global_loop(2000000); Session 1, while session 2 runs: CALL t.persist_loop(20000); SELECT v, COUNT(*) FROM t.seen GROUP BY v ORDER BY v; Expected: only 200. Actual: some rows show 300. The attached persist_race.sh does all of this: BASEDIR=/path/to/mysql ./persist_race.sh