The output of 'XA recover convert xid' is not useful
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
MySQL Server |
Unknown
|
Unknown
|
||||
Percona Server moved to https://jira.percona.com/projects/PS | Status tracked in 5.7 | |||||
5.5 |
Triaged
|
Medium
|
Unassigned | |||
5.6 |
Triaged
|
Medium
|
Unassigned | |||
5.7 |
Triaged
|
Medium
|
Unassigned |
Bug Description
An XA transaction can use up to 3 fields in the Xid, gtrid (global trx id), bqual (branch qualifier) and Formatid. Here's an example:
mysql> xa start 'gtrid'
Query OK, 0 rows affected (0.00 sec)
mysql> insert into testtable (val) values (now());
Query OK, 1 row affected (0.00 sec)
mysql> xa end 'gtrid'
Query OK, 0 rows affected (0.00 sec)
mysql> xa prepare 'gtrid'
Query OK, 0 rows affected (0.06 sec)
mysql> xa recover;
+------
| formatID | gtrid_length | bqual_length | data |
+------
| 1234 | 5 | 5 | gtridbqual |
+------
1 row in set (0.00 sec)
So, if you are stuck here, let's say after a server crash, you need to commit or rollback but:
mysql> xa commit 'gtridbqual';
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
mysql> xa recover convert xid;
+------
| formatID | gtrid_length | bqual_length | data |
+------
| 1234 | 5 | 5 | 0x6774726964627
+------
1 row in set (0.00 sec)
mysql> xa commit 0x6774726964627
ERROR 1399 (XAE07): XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
The answer is to parse the output correctly, as it is in the binlog.
# at 2511
#170823 17:02:20 server id 1 end_log_pos 2557 CRC32 0xbe8c0d98 XA PREPARE X'6774726964'
XA PREPARE X'6774726964'
mysql> xa commit X'6774726964'
Query OK, 0 rows affected (0.11 sec)
The output of the column data when using "convert xid" should be the value needed like here:
+------
| formatID | gtrid_length | bqual_length | data |
+------
| 1234 | 5 | 5 | X'6774726964,
+------
here a patch doing this (untested):
--- xa.cc.orig 2017-08-23 13:39:21.125823306 -0400
+++ xa.cc 2017-08-23 14:41:54.388030226 -0400
@@ -762,7 +762,7 @@
field_
- field_list.
+ field_list.
if (thd->send_
@@ -883,18 +883,16 @@
if (print_xid_as_hex)
{
/*
- xid_buf contains enough space for 0x followed by HEX representation
- of the binary XID data and one null termination character.
+ xid_buf contains enough space for twice X'', two comma, the string
+ representation of formatId and a null terminator
*/
- char xid_buf[XIDDATASIZE * 2 + 2 + 1];
-
- xid_buf[0]= '0';
- xid_buf[1]= 'x';
-
- size_t xid_str_len= bin_to_
- const_cast<
- m_xid.gtrid_length +
- m_xid.bqual_length) + 2;
+ char xid_buf[XIDDATASIZE * 2 + 8 + 10 + 1];
+
+ size_t xid_str_
+ m_xid.gtrid_length,
+ m_xid.bqual_length,
+ const_cast<
+
protocol-
}
else
The serialize_xid function is the same function that write the xid to the binlog.
tags: | added: contribution upstream |
patch is against PS 5.7