April 24, 2014

What is innodb_support_xa?

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.

About Baron Schwartz

Baron is the lead author of High Performance MySQL. He maintains a personal blog at Xaprb. Follow him at @xaprb or connect with him on LinkedIn.

Comments

  1. Olivier says:

    Hi,

    Thank you for this very interresting post.

    Strangely, the following sentence :

    “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. ”

    present in release 5.0 has disappeared in versions 5.1 and 5.5 of the manual

    Does it means that MySQL behaves differently for lastest versions ?

  2. I’m surprised that they changed that in the manual. I am 99% sure that the behavior has not changed.

  3. Holger Thiel says:

    It seems there are many system variables which influence the consistency of the binlog with InnoDB:

    – sync_binlog
    – binlog_format
    – innodb_flush_log_at_trx_commit
    – innodb_locks_unsafe_for_binlog
    – innodb_support_xa
    – tx_isolation

  4. James Day says:

    It’s quite old news now but the manual these days is much improved and is much more prescriptive about saying when this must be used and when there is benefit from not using it. Just doing as the manual now says should be the correct choice:

    “The XA mechanism is used internally and is essential for any server that has its binary log turned on and is accepting changes to its data from more than one thread. If you turn it off, transactions can be written to the binary log in a different order from the one in which the live database is committing them. This can produce different data when the binary log is replayed in disaster recovery or on a replication slave. Do not turn it off on a replication master server unless you have an unusual setup where only one thread is able to change data.

    For a server that is accepting data changes from only one thread, it is safe and recommended to turn off this option to improve performance for InnoDB tables. For example, you can turn it off on replication slaves where only the replication SQL thread is changing data.

    You can also turn off this option if you do not need it for safe binary logging or replication, and you also do not use an external XA transaction manager.”

    I didn’t check when this change was made, though.

    If you know of any other cases where the current manual text is not prescriptive enough about saying use or do not use a setting please file a bug report so we can get it updated to give people better instructions. It’s an ongoing task and external feedback is good.

    James Day, MySQL Senior Principal Support Engineer, Oracle

Speak Your Mind

*