Bug #85639 | XA transactions are 'unsafe' for RPL using SBR | ||
---|---|---|---|
Submitted: | 27 Mar 2017 9:11 | Modified: | 4 Oct 2017 14:33 |
Reporter: | João Gramacho | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Replication | Severity: | S3 (Non-critical) |
Version: | 5.7 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[27 Mar 2017 9:11]
João Gramacho
[24 Jul 2017 12:49]
Margaret Fisher
Posted by developer: Changelog entry for 8.0.2 and 5.7.20: Now that XA transactions are prepared and committed in two parts, an issue with statement-based replication has been identified. If two XA transactions committed on the master are being prepared on the slave in the inverse order, locking dependencies can occur that cannot be safely resolved. The issue is not present with row-based replication. XA transactions are therefore now considered unsafe for statement-based replication. - When binlog_format = STATEMENT, a warning is issued for DML statements inside XA transactions, and replication might fail with deadlock on slaves. - When binlog_format = MIXED, DML statements inside XA transactions are logged using row-based replication. - When binlog_format = ROW, DML statements inside XA transactions are logged as before. Documentation changes for 8.0.2: https://dev.mysql.com/doc/refman/8.0/en/xa-restrictions.html C.6 Restrictions on XA Transactions ... The following restrictions exist for using XA transactions: ... >> Add: XA transactions are considered unsafe for statement-based replication. If two XA transactions committed in parallel on the master are being prepared on the slave in the inverse order, locking dependencies can occur that cannot be safely resolved, and it is possible for replication to fail with deadlock on the slave. From MySQL 8.0.2, when <literal>binlog_format = STATEMENT</literal> is set, a warning is issued for DML statements inside XA transactions. When <literal>binlog_format = MIXED</literal> or <literal>binlog_format = ROW</literal> is set, DML statements inside XA transactions are logged using row-based replication, and the potential issue is not present. https://dev.mysql.com/doc/refman/8.0/en/replication-features-transactions.html 18.4.1.33 Replication and Transactions >> Add a link to XA transactions restrictions topic above: For restrictions that apply specifically to XA transactions, see C.6 Restrictions on XA Transactions. https://dev.mysql.com/doc/refman/8.0/en/replication-rbr-safe-unsafe.html 18.2.1.3 Determination of Safe and Unsafe Statements in Binary Logging >> Add: XA transactions. If two XA transactions committed in parallel on the master are being prepared on the slave in the inverse order, locking dependencies can occur with statement-based replication that cannot be safely resolved, and it is possible for replication to fail with deadlock on the slave. From MySQL 8.0.2, when <literal>binlog_format = STATEMENT</literal> is set, DML statements inside XA transactions are flagged as being unsafe and generate a warning. When <literal>binlog_format = MIXED</literal> or <literal>binlog_format = ROW</literal> is set, DML statements inside XA transactions are logged using row-based replication, and the potential issue is not present.
[16 Nov 2017 10:02]
Erlend Dahl
Bug#86486 XA Transactions in binlog cause replication broken was marked as a duplicate
[26 Apr 2021 3:42]
jingbo zhao
Nice Job! But your repeat case is hard to repeat(need complie MySQL to use debug mode) and understand. Our team(ksyun) has repeated this error use a sample case. create table: CREATE TABLE `test1` ( `id` int(11) DEFAULT NULL, `name` varchar(36) DEFAULT NULL, KEY `idx_id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 make data: mysql> insert into test1() values(1, "zbdba"),(3, "zbdba"),(5, "zbdba"),(6, "zbdba"),(10, "zbdba"),(10, "zbdba"),(15, "zbdba"),(18, "zbdba"); Query OK, 8 rows affected (0.03 sec) Records: 8 Duplicates: 0 Warnings: 0 start repeat: transaction 1: mysql> xa start '111'; Query OK, 0 rows affected (0.00 sec) mysql> insert into test1() values(8, "zbdba"); Query OK, 1 row affected (0.01 sec) mysql> xa end '111'; Query OK, 0 rows affected (0.01 sec) transaction 2: mysql> xa start '222'; Query OK, 0 rows affected (0.00 sec) mysql> delete from test1 where id = 10; Query OK, 2 rows affected (0.00 sec) mysql> xa end '222'; Query OK, 0 rows affected (0.00 sec) mysql> xa prepare '222'; Query OK, 0 rows affected (0.00 sec) transaction 1: mysql> xa prepare '111'; Query OK, 0 rows affected (0.00 sec) mysql> xa commit '111'; Query OK, 0 rows affected (0.00 sec) transaction 2: mysql> xa commit '222'; Query OK, 0 rows affected (0.00 sec)