This task is ensued by
MDEV-742 and implements the upstream's
In fact there's no issue in the ordering of logging of XA PREPARE into the binary log and transaction preparing in Engine. The chosen by upstream method of the logging goes first is not really incorrect but just needs
some refinement of the server recovery.
So in case the server crashes having XA-prepared "transaction" binlogged but not yet
prepared in Engine, its next recovery must be augmented with identifying the XA-prepared's events in the binlog and resubmitting the transaction for preparing in Engine.
XA-COMMIT or XA-ROLLBACK are logged compatibly with XA-PREPARE and therefore
a similar issue arises when the server crashes after binary logging but before actual transaction completion in Engine. The same technique must be used to identify and resubmit to commit-or-rollback.