当前位置: 首页 > news >正文

inurl 网站建设百度怎么创建自己的网站

inurl 网站建设,百度怎么创建自己的网站,深圳盐田建设交易中心网站,了解网站基本知识这篇博客来记录在发起全局事务回滚时,服务端接收到netty请求是如何处理的 1. 发起全局事务回滚请求 在前面的博客中,有说到过,事务发起者在发现分支事务执行异常之后,会提交全局事务回滚的请求到netty服务端,这里是发…

这篇博客来记录在发起全局事务回滚时,服务端接收到netty请求是如何处理的

1. 发起全局事务回滚请求

在这里插入图片描述
在前面的博客中,有说到过,事务发起者在发现分支事务执行异常之后,会提交全局事务回滚的请求到netty服务端,这里是发送全局事务回滚请求的代码,同样,这里的GlobalRollbackRequest这个对象很重要,可以看到,在netty客户端这里,只入参了XID,这个xid贯穿了全局上下文,在服务端就是根据这里xid,来确定是要处理哪个全局事务

2. 服务端处理逻辑

在前面netty全局事务开启服务端源码中,有介绍过,netty服务端接收到客户端的请求之后,最终会进入到这个方法中,根据请求的对象类型,来决定是有哪个对象来处理
在这里插入图片描述

io.seata.server.AbstractTCInboundHandler#handle(io.seata.core.protocol.transaction.GlobalRollbackRequest, io.seata.core.rpc.RpcContext)

在这个方法中,会继续调度
在这里插入图片描述

可以发现,在doGlobalRollback方法中,最终,调用了core.rollback()
在这里插入图片描述

2.1 io.seata.server.coordinator.DefaultCore#rollback

在这里执行回滚的时候,有三个步骤

  1. 根据xid,找到netty服务端的globalSession
  2. 调用globalSession的close()方法,这个方法只是把globalSession的active属性设置为false了
  3. 最后会调用doGlobalRollback()方法,最核心的逻辑在这个方法中

在这里插入图片描述

2.2 doGlobalRollback

io.seata.server.coordinator.DefaultCore#doGlobalRollback

下面这是执行全局事务回滚的核心代码

  1. 会先根据全局事务,获取到所有的分支事务
  2. 然后依次遍历所有的分支事务
  3. 如果分支事务是失败状态,就直接删除分支事务(从branchTable中删除)
  4. branchRollback 这里是通过netty请求,触发分支事务进行回滚的逻辑,这个下面单独说
  5. 接着就会对分支事务回滚成功/失败,做出相应的处理;如果处理成功,会把branchTable和lockTable中的数据删除
  6. 最后在所有分支事务都处理之后,对全局事务进行处理,endRollbacked 在这个方法中,会把globalTable中的全局事务删除
public boolean doGlobalRollback(GlobalSession globalSession, boolean retrying) throws TransactionException {boolean success = true;// start rollback event  这里没看懂,先跳过eventBus.post(new GlobalTransactionEvent(globalSession.getTransactionId(), GlobalTransactionEvent.ROLE_TC,globalSession.getTransactionName(), globalSession.getBeginTime(), null, globalSession.getStatus()));// 判断当前事务使用的模式if (globalSession.isSaga()) {success = getCore(BranchType.SAGA).doGlobalRollback(globalSession, retrying);} else {for (BranchSession branchSession : globalSession.getReverseSortedBranches()) {BranchStatus currentBranchStatus = branchSession.getStatus();if (currentBranchStatus == BranchStatus.PhaseOne_Failed) {/*** 1.如果分支事务是failed状态,直接remove,就是从branchTable表中删除记录*/globalSession.removeBranch(branchSession);continue;}try {/*** 2.调用客户端,进行分支事务回滚* 如果回滚成功,会在removeBranch中先删除lockTable的记录* 再删除branchTable的记录*/BranchStatus branchStatus = branchRollback(globalSession, branchSession);switch (branchStatus) {/*** 这是rm正常进行事务回滚的返回结果,如果rm进行了sql回滚,并且undolog日志正常删除* 那这里就会将lockTable和branchTable的记录删除*/case PhaseTwo_Rollbacked:globalSession.removeBranch(branchSession);LOGGER.info("Rollback branch transaction successfully, xid = {} branchId = {}", globalSession.getXid(), branchSession.getBranchId());continue;case PhaseTwo_RollbackFailed_Unretryable:/*** rm抛出unretryable异常的话,会执行这里,将全局事务删除?*/SessionHelper.endRollbackFailed(globalSession);LOGGER.info("Rollback branch transaction fail and stop retry, xid = {} branchId = {}", globalSession.getXid(), branchSession.getBranchId());return false;default:LOGGER.info("Rollback branch transaction fail and will retry, xid = {} branchId = {}", globalSession.getXid(), branchSession.getBranchId());if (!retrying) {globalSession.queueToRetryRollback();}return false;}} catch (Exception ex) {StackTraceLogger.error(LOGGER, ex,"Rollback branch transaction exception, xid = {} branchId = {} exception = {}",new String[] {globalSession.getXid(), String.valueOf(branchSession.getBranchId()), ex.getMessage()});if (!retrying) {globalSession.queueToRetryRollback();}throw new TransactionException(ex);}}// In db mode, there is a problem of inconsistent data in multiple copies, resulting in new branch// transaction registration when rolling back.// 1. New branch transaction and rollback branch transaction have no data association// 2. New branch transaction has data association with rollback branch transaction// The second query can solve the first problem, and if it is the second problem, it may cause a rollback// failure due to data changes.GlobalSession globalSessionTwice = SessionHolder.findGlobalSession(globalSession.getXid());if (globalSessionTwice != null && globalSessionTwice.hasBranch()) {LOGGER.info("Rollbacking global transaction is NOT done, xid = {}.", globalSession.getXid());return false;}}if (success) {// 在这里的end方法中,会删除globalTable中的记录SessionHelper.endRollbacked(globalSession);// rollbacked eventeventBus.post(new GlobalTransactionEvent(globalSession.getTransactionId(), GlobalTransactionEvent.ROLE_TC,globalSession.getTransactionName(), globalSession.getBeginTime(), System.currentTimeMillis(),globalSession.getStatus()));LOGGER.info("Rollback global transaction successfully, xid = {}.", globalSession.getXid());}return success;
}

2.3 分支事务回滚 branchRollback(globalSession, branchSession);

io.seata.rm.DefaultResourceManager#branchRollback

服务端会通过发送netty请求(在2.2 中的branchRollback),触发rm这边开始进行分支事务的回滚,最终会在rm这边的这个类中进行分支事务回滚的操作
在执行回滚操作的时候,会根据branchType获取对应的manager
在这里插入图片描述

在这里,会根据当前的dbType,找到对应的undoLogManager,然后调用其undo方法进行分支事务回滚
在这里插入图片描述

io.seata.rm.datasource.undo.AbstractUndoLogManager#undo

在这里的undo方法中,会生成回滚sql,执行,然后删除undolog日志,代码太长了,但是逻辑不多,就不贴代码了

2.4 删除分支事务

我们接着上面2.2的逻辑来看,在调用netty请求,rm这一端进行了事务回滚之后,对于seata服务端这边,只需要把分支事务和全局事务删除即可
在2.2 的代码中,会对netty请求返回的状态进行判断,branchStatus
如果是PhaseTwo_Rollbacked,表示分支事务处理成功,此时会进入到globalSession.removeBranch(branchSession);来进行处理
在这个方法中,有两个逻辑,解锁和removeBranch,那就不用想了,肯定是删除分支事务加的锁和删除分支事务
在这里插入图片描述

io.seata.server.session.BranchSession#unlockio.seata.server.storage.db.lock.DataBaseLockManager#releaseLockio.seata.server.storage.db.lock.DataBaseLocker#releaseLock(java.lang.String, java.lang.Long)io.seata.server.storage.db.lock.LockStoreDataBaseDAO#unLock(java.lang.String, java.lang.Long)

对于释放锁的逻辑,比较简答,中间会调用的时候,会指定xid和branchId,然后去构建删除的sql

在这里插入图片描述

我们接着来看,删除分支事务的代码
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
这就是分支事务删除的逻辑;这个逻辑也比较简单,大部分都是共用的逻辑,就不做过多的介绍了

2.5 全局事务删除

SessionHelper.endRollbacked(globalSession);在这个方法中,会处理全局事务
在这里插入图片描述
这里看起来也有两个逻辑,在clean()方法中,我最开始没有看懂这个clean中要做什么,因为在clean中,就直接调用了下面截图中的这个releaselock方法,看到这个方法中的这行代码之后,我好像明白了,这里是再尝试将所有分支事务的锁进行释放的逻辑
在这里插入图片描述

我们接着来看,onEnd()的逻辑:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
这就是全局事务删除的逻辑

总结

对于分布式事务,进行全局回滚的逻辑,还是比较简单的

  1. 在事务管理者这边发起全局事务回滚的请求
  2. seata服务端,也就是事务协调者接收到请求之后,会向所有的rm,发起netty请求,进行分支事务的处理
  3. 各个分支事务,会根据undoLog日志,生成回滚的sql,然后执行
  4. seata服务端在等分支事务返回状态之后,会先删除分支事务,在删除分支事务之前,会将分支事务加的锁给删除(这里的锁,如果是mysql的话,其实就是写入到mysql中的一条记录)
  5. 最后会去处理globalSession,将globalSession从mysql表中删除

所以其实分支事务回滚的时候,就是把全局事务 + 分支事务 + 锁 从mysql表中删除


文章转载自:
http://dahomeyan.xqwq.cn
http://skepsis.xqwq.cn
http://octocentenary.xqwq.cn
http://alarmism.xqwq.cn
http://peerage.xqwq.cn
http://source.xqwq.cn
http://geosynchronous.xqwq.cn
http://hierograph.xqwq.cn
http://tactile.xqwq.cn
http://cabman.xqwq.cn
http://indeliberateness.xqwq.cn
http://stirp.xqwq.cn
http://gonadotrope.xqwq.cn
http://nausea.xqwq.cn
http://bardling.xqwq.cn
http://metalliding.xqwq.cn
http://excuria.xqwq.cn
http://widthways.xqwq.cn
http://lated.xqwq.cn
http://ogle.xqwq.cn
http://stoneware.xqwq.cn
http://frightful.xqwq.cn
http://ddk.xqwq.cn
http://kastelorrizon.xqwq.cn
http://charactonym.xqwq.cn
http://fusion.xqwq.cn
http://subdepot.xqwq.cn
http://yhvh.xqwq.cn
http://forepart.xqwq.cn
http://lcdr.xqwq.cn
http://mystagogue.xqwq.cn
http://promiscuous.xqwq.cn
http://confine.xqwq.cn
http://floury.xqwq.cn
http://antituberculosis.xqwq.cn
http://doddery.xqwq.cn
http://pistache.xqwq.cn
http://insurrectionist.xqwq.cn
http://emblema.xqwq.cn
http://wallachia.xqwq.cn
http://variegated.xqwq.cn
http://ascendancy.xqwq.cn
http://cooly.xqwq.cn
http://polonium.xqwq.cn
http://situla.xqwq.cn
http://witchcraft.xqwq.cn
http://eap.xqwq.cn
http://sulfone.xqwq.cn
http://odorant.xqwq.cn
http://neronian.xqwq.cn
http://pub.xqwq.cn
http://illegitimacy.xqwq.cn
http://radc.xqwq.cn
http://spinozism.xqwq.cn
http://mispickel.xqwq.cn
http://exciple.xqwq.cn
http://pelage.xqwq.cn
http://decahydrate.xqwq.cn
http://romanticise.xqwq.cn
http://trypanosomiasis.xqwq.cn
http://offhandedly.xqwq.cn
http://respirometry.xqwq.cn
http://biweekly.xqwq.cn
http://soroban.xqwq.cn
http://sonochemical.xqwq.cn
http://lipography.xqwq.cn
http://jubilize.xqwq.cn
http://ore.xqwq.cn
http://plot.xqwq.cn
http://greengrocer.xqwq.cn
http://cyanamid.xqwq.cn
http://rapidly.xqwq.cn
http://belgrade.xqwq.cn
http://demerit.xqwq.cn
http://dactylogram.xqwq.cn
http://duluth.xqwq.cn
http://ferrimagnetic.xqwq.cn
http://exportation.xqwq.cn
http://comecon.xqwq.cn
http://volksdeutscher.xqwq.cn
http://hypopnea.xqwq.cn
http://fortress.xqwq.cn
http://fruition.xqwq.cn
http://serene.xqwq.cn
http://methacetin.xqwq.cn
http://servomechanism.xqwq.cn
http://decayed.xqwq.cn
http://uitlander.xqwq.cn
http://feirie.xqwq.cn
http://mizoram.xqwq.cn
http://chastisable.xqwq.cn
http://affright.xqwq.cn
http://cims.xqwq.cn
http://quicky.xqwq.cn
http://reflectance.xqwq.cn
http://sulfamethoxypyridazine.xqwq.cn
http://alder.xqwq.cn
http://leucine.xqwq.cn
http://coastguard.xqwq.cn
http://nllst.xqwq.cn
http://www.hrbkazy.com/news/61589.html

相关文章:

  • 宁夏一站式网站建设内容营销策略
  • 佛山用户网站建设百度seo关键词报价
  • 手机wap网站程序世界足球排名
  • 软件测试要学哪些东西seo 推广怎么做
  • 公司邮箱申请注册谷歌seo综合查询
  • 网站关键词推广做自然排名网站宣传文案
  • 个人简介网站怎么做百度网站推广费用
  • 制作网站公司首 荐乐云seo大连谷歌seo
  • 三乡网站建设发布平台
  • 天津电子商务网站建设今日国际新闻摘抄十条
  • 潍坊高新区建设局网站网络推广方案模板
  • 农村电商网站建设方案一个新的app如何推广
  • wordpress 更改自带域名手机优化软件排行
  • 老网站文章突然无收录免费搭建网站平台
  • 济南做网站互联网公司排名安徽网站开发哪家好
  • 建工行业建设标准网站图片搜索识图入口
  • java做网站开发成本高seo推广培训资料
  • 成都旅游网站建设百度注册
  • 福州做网站昆明seo建站
  • 一般网站做响应式吗地推接单在哪个平台找
  • 凡网站创建google下载安卓版
  • 手机网站开发模拟器seo实战
  • 做旅行网站好百度seo关键词优化费用
  • thinkphp 企业网站源码百度惠生活怎么做推广
  • 珠海市斗门建设局网站口碑营销的成功案例
  • 郑州建站模板源码单页网站设计
  • wordpress文章摘录贵阳百度快照优化排名
  • pw网站更换域名青岛seo优化公司
  • 广州网站优化关键词方法2021年近期舆情热点话题
  • 日本药妆电子商务网站建设规划书建网站教学