[MDEV-21168] Active XA transactions stop slave from working after backup was restored. Created: 2019-11-28 Updated: 2023-03-06 Resolved: 2020-04-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Backup |
| Affects Version/s: | 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.2.32, 10.3.23, 10.4.13 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Vladislav Lesin | Assignee: | Vladislav Lesin |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
When using Mariabackup to create a slave, the slave had XA transactions active which stopped the slave from working. The easiest way to fix this is that when mariabackup runs recover on the backup, set up --tc-heuristic-recover=ROLLBACK. This will ensure that any XA prepared transaction are rolled back on the slave. |
| Comments |
| Comment by Max Mether [ 2019-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Note that there is an active open issue that is being worked on related to --tc-heuristic-recover=ROLLBACK: | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2019-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
The issue In case of FLUSH TABLES WITH READ LOCK, there can't be any active XA transactions. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Max Mether [ 2019-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
I was merely pointing out that there is work ongoing that changes the behaviour of --tc-heurustic-recover=ROLLBACK. It might of course have no impact on this issue. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Lesin [ 2019-12-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Let's consider the following test case in 10.2:
xarecover_handlerton() contains the following code:
In the above test xid_t::get_my_xid() returns 0 (as the XID does not have MYSQL_XID_PREFIX prefix) for XID pushed in info->list by innodb(innobase_xa_prepare()). As a result, the XID is just pushed in xid_cache, and then XA transaction stays in prepared state independently on tc_heuristic_recover value. Elkin confirmed this is correct behaviour. There are two kinds of XA transactions: 1) client XA transactions, which are created explicitly by user with "XA start/end/prepare/commit/rollback" statements, 2) server XA transactions(with MYSQL_XID_PREFIX prefix in XID), which are created implicitly by the server to commit transaction in binary log and storage engine using two phase commit(see also innobase_xa_prepare()):
Client XA transactions are not rolled back or committed on recovery, they stays in prepared state independently on tc_heuristic_recover value until user commits or rolls them back manually. As I understood from our conversation with Elkin, this is intentional and correct behaviour. So the solution with tc_heuristic_recover will not work. We could, for example, invoke innobase_rollback_by_xid() for prepared client transactions in mariabackup, but I am not sure this is correct behaviour, as there can be other storage engines involved in XA transaction. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2019-12-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
When doing a backup, we want to have the state of committed transactions. Anything that is not committed, including XA transactions, should roll back! In the case of the killed server, the intention is that the server will restart and the client will reconnect and issue new XA commands (commit or rollback). Regards, | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Lesin [ 2019-12-18 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
What about the case when backup is used to create slave? Prepared XA's can be committed or rolled back by slave thread. Elkin is working on The answer from Monty: | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Lesin [ 2019-12-20 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
The commit https://github.com/MariaDB/server/commit/be85c2dc889b668382106071e712213cd3b1cbcf disables transactions processing on mariabackup --prepare (except --prepare --export to export tablespaces, see also https://mariadb.com/kb/en/library/copying-tables-between-different-mariadb-databases-and-mariadb-servers/, https://mariadb.com/kb/en/library/partial-backup-and-restore-with-mariabackup/). The comment from marko: So currently mariabackup does not process transactions on backup restoring to allow incremental backup delta applying. We could, for example, implement some option, like --prepare-finalize, which would make backup data directory unusable for further incremental backup delta applying. | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2019-12-20 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
For what it is worth, I would like to make the mariabackup --prepare step optional, and allow the server to start directly on the backup directory. With the redo log format changes in | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2020-03-03 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
julien.fritsch, vlad.lesin: First, it's correct | ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2020-05-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
I believe that we cannot claim this to work correctly without the fix of Starting InnoDB with wrong LSN can potentially cause serious corruption of all InnoDB data files. Before
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Lesin [ 2020-07-06 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Just for the note, --apply-log-only was removed in this commit:
| ||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2023-03-06 ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
|