Seata: 全局提交中DefaultCore.commit方法中globalSession.closeAndClean();做的事情和这个方法上面的注释不服,里面的代码实现不能实现注释上的功能

Created on 15 May 2020  ·  5Comments  ·  Source: seata/seata

TC question

All 5 comments

🖖🏽

can you elaborate on that

我尝试解答下你的疑问:
1.这是源代码和注释
// the lock should release after branch commit // Highlight: Firstly, close the session, then no more branch can be registered. // 1.分支事务提交后释放锁; // 2.关闭全局session(active=false),这样就不会注册新分支了; globalSession.closeAndClean();
2.globalSession.closeAndClean()内部
public void closeAndClean() throws TransactionException { //关闭GlobalSession,状态置为active=false close(); //清理此全局事务上所有分支事务的行锁,lockTable表中 clean(); }
3.close方法
@Override public void onClose(GlobalSession globalSession) throws TransactionException { globalSession.setActive(false); }
这里就是把全局事务关闭了,这样分支事务就不能注册了
4.clean方法
你追下去发现最终落在
delete from #lock_table# where xid = ? and branch_id in ( #in_params# )
这里是删除分支事务的行锁
5.close方法中,active=false,为什么就不能注册了呢?
在一阶段,分支事务注册方法里,方法最前面有这么个方法
globalSessionStatusCheck(globalSession);
这个方法是检查全局事务状态的,如果全局事务状态active=false,会报错的,方法实现为:
protected void globalSessionStatusCheck(GlobalSession globalSession) throws GlobalTransactionException { if (!globalSession.isActive()) { throw new GlobalTransactionException(GlobalTransactionNotActive, String.format( "Could not register branch into global session xid = %s status = %s, cause by globalSession not active", globalSession.getXid(), globalSession.getStatus())); } if (globalSession.getStatus() != GlobalStatus.Begin) { throw new GlobalTransactionException(GlobalTransactionStatusInvalid, String .format("Could not register branch into global session xid = %s status = %s while expecting %s", globalSession.getXid(), globalSession.getStatus(), GlobalStatus.Begin)); } }
群里的朋友有时候会遇到分支事务无法注册的错误,原因就在这里。

@tanjiaxin1999 上面的回答,你可以跟下源码,和注释做的事情,还是比较一致的。如果有什么问题,再继续交流。

注释信息的确有问题。这个PR已经删除掉注释了。

Was this page helpful?
0 / 5 - 0 ratings