Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持MySQL5.7的XA binlog事件 #626

Closed
agapple opened this issue May 7, 2018 · 5 comments
Closed

支持MySQL5.7的XA binlog事件 #626

agapple opened this issue May 7, 2018 · 5 comments
Assignees
Labels
Milestone

Comments

@agapple
Copy link
Member

agapple commented May 7, 2018

支持一下MySQL 5.7之后的XA能力:https://mysqlserverteam.com/improvements-to-xa-support-in-mysql-5-7/

`
TRANSACTION_CONTEXT_EVENT= 36,

VIEW_CHANGE_EVENT= 37,

/* Prepared XA transaction terminal event similar to Xid */
XA_PREPARE_LOG_EVENT= 38,
`

@agapple agapple self-assigned this May 7, 2018
@agapple agapple added the feature label May 7, 2018
@agapple agapple added this to the v1.0.26 milestone May 7, 2018
@agapple
Copy link
Member Author

agapple commented May 7, 2018

| mysql-bin.000011 | 13688 | Gtid | 1 | 13753 | SET @@SESSION.GTID_NEXT= 'f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:26' |
| mysql-bin.000011 | 13753 | Query | 1 | 13846 | XA START X'74657374',X'',1 |
| mysql-bin.000011 | 13846 | Rows_query | 1 | 13897 | # update test set id = id + 5 |
| mysql-bin.000011 | 13897 | Table_map | 1 | 13985 | table_id: 256 (test.test) |
| mysql-bin.000011 | 13985 | Update_rows_v1 | 1 | 14167 | table_id: 256 flags: STMT_END_F |
| mysql-bin.000011 | 14167 | Query | 1 | 14258 | XA END X'74657374',X'',1 |
| mysql-bin.000011 | 14258 | XA_prepare | 1 | 14298 | XA PREPARE X'74657374',X'',1 |
| mysql-bin.000011 | 14298 | Gtid | 1 | 14363 | SET @@SESSION.GTID_NEXT= 'f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:27' |
| mysql-bin.000011 | 14363 | Query | 1 | 14459 | XA ROLLBACK X'74657374',X'',1 |
| mysql-bin.000011 | 14459 | Gtid | 1 | 14524 | SET @@SESSION.GTID_NEXT= 'f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:28' |
| mysql-bin.000011 | 14524 | Query | 1 | 14617 | XA START X'74657374',X'',1 |
| mysql-bin.000011 | 14617 | Rows_query | 1 | 14668 | # update test set id = id + 5 |
| mysql-bin.000011 | 14668 | Table_map | 1 | 14756 | table_id: 256 (test.test) |
| mysql-bin.000011 | 14756 | Update_rows_v1 | 1 | 14938 | table_id: 256 flags: STMT_END_F |
| mysql-bin.000011 | 14938 | Query | 1 | 15029 | XA END X'74657374',X'',1 |
| mysql-bin.000011 | 15029 | XA_prepare | 1 | 15069 | XA PREPARE X'74657374',X'',1 |
| mysql-bin.000011 | 15069 | Gtid | 1 | 15134 | SET @@SESSION.GTID_NEXT= 'f1ceb61a-a5d5-11e7-bdee-107c3dbcf8a7:29' |
| mysql-bin.000011 | 15134 | Query | 1 | 15228 | XA COMMIT X'74657374',X'',1

mysql xa的binlog提交格式,会在prepare时就记录到binlog并且对外可见,而后续会对xa继续进行commit或者rollback,如果执行rollback时还需要执行回滚对应的SQL(xa rollback没有记录对应的逆向binlog,需要在内存里暂缓存xa prepare的变更)

agapple added a commit that referenced this issue May 7, 2018
@agapple
Copy link
Member Author

agapple commented May 7, 2018

http://mysql.taobao.org/monthly/2017/11/06/, 一片比较不错介绍MySQL XA

@withlin
Copy link
Contributor

withlin commented May 24, 2018

上面地址404...

@zhmz1326
Copy link
Contributor

上面地址去掉后面的逗号就能看了 http://mysql.taobao.org/monthly/2017/11/06/

@agapple
Copy link
Member Author

agapple commented Jun 6, 2018

输出格式类似:

================> binlog[mysql-bin.000012:35614] 
 BEGIN ----> Thread id: 3 ------> XA START  X'63',X'',1


 END ----> transaction id: 0 ------> XA END  X'63',X'',1
================> binlog[mysql-bin.000012:36022]


----------------> binlog[mysql-bin.000012:35459]
 ------> XA ROLLBACK  X'62',X'',1

----------------> binlog[mysql-bin.000012:36209]
 ------> XA COMMIT  X'63',X'',1

打印xa信息:

protected void printXAInfo(List<Pair> pairs) {
        if (pairs == null) {
            return;
        }

        String xaType = null;
        String xaXid = null;
        for (Pair pair : pairs) {
            String key = pair.getKey();
            if (StringUtils.endsWithIgnoreCase(key, "XA_TYPE")) {
                xaType = pair.getValue();
            } else if (StringUtils.endsWithIgnoreCase(key, "XA_XID")) {
                xaXid = pair.getValue();
            }
        }

        if (xaType != null && xaXid != null) {
            logger.info(" ------> " + xaType + " " + xaXid);
        }
    }

@agapple agapple closed this as completed Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants