XA两阶段提交并在准备阶段执行? [英] XA Two Phase Commit and execution in Prepare Phase?

查看:115
本文介绍了XA两阶段提交并在准备阶段执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解两阶段提交,但是我不清楚每个本地站点何时执行其分布式事务的一部分.

I am trying to understand two-phase-commit and it is not clear to me when each local site executes its portion of the distributed transaction.

在发送准备消息之前会发生这种情况.那是在两阶段提交xa协议运行之前发生的吗?

Does that happen before the prepare messages are sent. That is does it happen before the two-phase-commit xa protocol is even run?

还是每个站点在接收到准备消息后执行分布式交易的一部分,这意味着准备消息本身还包括要执行的交易查询?

Or does each site executes its portion of the distributed transaction after receiving the prepare message, meaning the prepare message itself also includes the transaction query to be executed?

推荐答案

是的,执行是在发送准备消息之前进行的.您应该假定整个2PC协议都在执行完所有操作后在commit()操作中运行.考虑以下关于最终提交的分布式事务的想象的跟踪.缩进意味着过程嵌套:

Yes, execution happens before prepare messages are sent. You should assume that the entire 2PC protocol runs within the commit() operation after everything has already been executed. Consider the following imagined trace of a distributed transaction that eventually commits. Indentation means procedure nesting:

transactionalOperation() is a procedure at some client site
    begin() is a remote invocation to the coordinator
        create global XID
        return global XID
    XID is added to the thread-local context at the caller
    executeOperation(params) is a remote invocation to a participant site
        XID is implicitly propagated to the server side thread
        inform coordinator that this site is a participant
        execute the operation! (acquiring locks)
    ... more operations ....
    commit() is a remote invocation to the coordinator
        XID is implicitly propagated to the server side thread
        -------------- 2PC starts here ----------------
        for all registered participants:
            prepare(XID) is a remote invocation to each site
                make sure that the transaction can be committed,
                usually by writing and flushing a log 
                return OK
        gather decisions
        for all reguistered participants:
            commit(XID) is a remote invocation to each site
                log transaction commit
                (release locks)
        -------------- 2PC ends here ----------------
    XID is removed from the thread-local context at the caller
    transaction is complete!

实际上,如您所见,协调员只会将prepare消息发送给那些先前已在此事务的上下文中执行某些操作并因此先前已注册为该事务的参与者的站点.

Actually, as you can see, the prepare message will be sent by the coordinator only to those sites that have previously executed something within the context of such transaction, and thus have previously registered as participants in that transaction.

这篇关于XA两阶段提交并在准备阶段执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆