What is innodb_support_xa?
Join the DZone community and get the full member experience.Join For Free
This is a guest post by Baron Schwartz
A common misunderstanding about innodb_support_xa is that it enables user-initiated XA transactions, that is, transactions that are prepared and then committed on multiple systems, with an external transaction coordinator. This is actually not precisely what this option is for. It enables two-phase commit in InnoDB (prepare, then commit). This is necessary not only for user-initiated XA, but also for internal XA coordination between the InnoDB transaction logs and the MySQL binary logs, to ensure that they are consistent. Consistent is an important word with a special meaning.
We have done some benchmarking and performance research on this option in the past (see also: post 1, post 2). This was motivated by the severe performance hit that occurred when the commit process was changed to an internal XA implementation. This did two things: it disabled group commit, and it added an extra fsync per commit. The extra fsync is required because during the internal ‘prepare’ stage, the transaction can’t be considered prepared (and thus guaranteed to be recoverable) until it is synced to durable storage. The final fsync marks the transaction as committed, not just prepared. The extra fsync can be avoided by disabling the option. (Group commit can’t be re-enabled unless the binary log is also disabled.)
The prepare-then-commit process does two important things: it ensures that the binary log and the engine’s transaction log agree on which transactions are committed; and it ensures that they agree on the order in which the transactions were committed. The first is important for crash recovery, and the second is important for replication.
However, it is not as simple as “if you want higher performance, disable innodb_support_xa.” Our past blog posts might have been too shallow in their discussion on this point. You can disable InnoDB two-phase commit if you wish, but you need to weigh the risk of out-of-sync data on replicas (and after point-in-time recovery) when you do that.
Unfortunately, the manual isn’t that helpful in this instance — it doesn’t clear things up very well:
When the variable is enabled (the default), InnoDB support for two-phase commit in XA transactions is enabled, which causes an extra disk flush for transaction preparation. If you do not wish to use XA transactions, you can disable this variable to reduce the number of disk flushes and get better InnoDB performance. Having innodb_support_xa enabled on a replication master—or on any MySQL server where binary logging is in use—ensures that the binary log does not get out of sync compared to the table data.
That sort of touches on both internal and external XA transactions, but doesn’t distinguish between them. Hopefully this post will help clarify the difference, and help people make good decisions about the setting. Thanks to Kristian Nielsen for review and feedback.
Published at DZone with permission of Peter Zaitsev, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.