diff -uraNd mysql-5.7.19/sql/binlog.cc mysql-5.7.19_xa_rollback_fix/sql/binlog.cc --- mysql-5.7.19/sql/binlog.cc 2017-06-22 22:13:19.000000000 +0800 +++ mysql-5.7.19_xa_rollback_fix/sql/binlog.cc 2017-08-11 17:07:38.255741007 +0800 @@ -2203,6 +2203,13 @@ DBUG_ASSERT(cache_mngr || !xs->is_binlogged() || !(is_open() && thd->variables.option_bits & OPTION_BIN_LOG)); + const xid_t *m_xid = ((Sql_cmd_xa_rollback*)thd->lex->m_sql_cmd)->get_xid(); + if (thd->is_error() && !xs->has_same_xid(m_xid)) + { + error = 1; + goto end; + } + if ((error= do_binlog_xa_commit_rollback(thd, xs->get_xid(), false))) goto end; cache_mngr= thd_get_cache_mngr(thd); diff -uraNd mysql-5.7.19/sql/xa.h mysql-5.7.19_xa_rollback_fix/sql/xa.h --- mysql-5.7.19/sql/xa.h 2017-06-22 22:13:19.000000000 +0800 +++ mysql-5.7.19_xa_rollback_fix/sql/xa.h 2017-08-11 17:05:20.112832761 +0800 @@ -191,6 +191,11 @@ virtual bool execute(THD *thd); + const xid_t *get_xid() const + { + return m_xid; + } + private: bool trans_xa_rollback(THD *thd);