Description:
The xa transaction still be able to modify the table data, event if there is a global read lock, such as "flush tables with read lock"
How to repeat:
==============================================
Open one session as session1, and do a xa prepare:
==============================================
[root@s12 ~]# mysql -udbscale -pdbscale -h172.16.90.15 -P9997 wen
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 881
Server version: 5.7.13-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show create table t1;
+-------+----------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------+
1 row in set (0.03 sec)
mysql> xa start '1';
Query OK, 0 rows affected (0.00 sec)
mysql> insert into t1 values (1);
Query OK, 1 row affected (0.00 sec)
mysql> xa end '1';
Query OK, 0 rows affected (0.00 sec)
mysql> xa prepare '1';
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
==========================================================
Then open a new session session2, and acquire a global read lock.
And try to commit the xa transaction of session1 after acquired lock.
==========================================================
gaoxiaoxin@gaoxiaoxin-X550JX:~$ mysql -udbscale -pdbscale -h172.16.90.15 -P9997 wen
Warning: Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 882
Server version: 5.7.13-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from t1;
Empty set (0.01 sec)
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> xa recover;
+----------+--------------+--------------+------+
| formatID | gtrid_length | bqual_length | data |
+----------+--------------+--------------+------+
| 1 | 1 | 0 | 1 |
+----------+--------------+--------------+------+
1 row in set (0.00 sec)
mysql> xa commit '1';
Query OK, 0 rows affected (0.04 sec)
mysql> select * from t1;
+------+
| c1 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql>
The session2 will be able to modify the table data of t1 event in the global read lock mode!
(If we do the "xa commit '1'" on session1, it will be blocked by the global read lock.)
Suggested fix:
XA commit should be blocked under the global read lock mode in any case.