Bug #121903 SET PERSIST can persist the value of a concurrent SET GLOBAL

Submitted: 24 Nov 9:19
Reporter: Tomas Ulin Email Updates:
Status: Open Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:8.4.11, 9.7.4, trunk (26.10.0) OS:Any
Assigned to: CPU Architecture:Any

[24 Nov 9:19] Tomas Ulin
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
[24 Nov 9:19] Tomas Ulin
repro

Attachment: persist_race.sh (application/x-sh, text), 1.59 KiB.

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.