• 二、分布式事务协调者DefaultCoordinator


    所有文章

    https://www.cnblogs.com/lay2017/p/12485081.html

    正文

    由seata-server的main方法我们可以知道,netty的RPC机制负责了网络部分的职责。而DefaultCoordinator负责了分布式事务协调者的主体功能。

    本文将预先看看DefaultCoordinator的整体结构

    UML类图

    必不可少的,首先看看DefaultCoordinator的类图结构

    DefaultCoordinator主要实现了三个接口

    1)TCInboundHandler,作为事务协调者处理器

    2) ResourceManagerInbound,作为Server端的资源管理器

    3)TransactionMessageHandler,作为事务的消息处理器

    TransactionMessageHandler无非就是经过RPC调用的请求消息比如全局事务begin、commit、rollback...等,将消息传递给DefaultCoordinator进行处理。

    那么其它两个接口分别对外提供哪些接口呢?

    TCInboundHandler

    public interface TCInboundHandler {
        // 开始全局事务
        GlobalBeginResponse handle(GlobalBeginRequest globalBegin, RpcContext rpcContext);
    
        // 全局事务提交
        GlobalCommitResponse handle(GlobalCommitRequest globalCommit, RpcContext rpcContext);
    
        // 全局事务回滚
        GlobalRollbackResponse handle(GlobalRollbackRequest globalRollback, RpcContext rpcContext);
    
        // 分支事务注册
        BranchRegisterResponse handle(BranchRegisterRequest branchRegister, RpcContext rpcContext);
    
        // 分支事务上报
        BranchReportResponse handle(BranchReportRequest branchReport, RpcContext rpcContext);
    
        // 全局锁查询
        GlobalLockQueryResponse handle(GlobalLockQueryRequest checkLock, RpcContext rpcContext);
    
        // 事务状态查询
        GlobalStatusResponse handle(GlobalStatusRequest globalStatus, RpcContext rpcContext);
    
        // 全局上报
        GlobalReportResponse handle(GlobalReportRequest globalReport, RpcContext rpcContext);
    }

    可以看到,TCInboundHandler主要定义了关于全局事务的begin、commit、rollback,以及分支事务的register、report,附加全局锁查询和两个report。

    与全局事务内部相关的在TCInboundHandler中,那么与分支事务内部相关的就分离到了ResourceManagerInbound中

    ResourceManagerInbound

    public interface ResourceManagerInbound {
        // 分支事务提交
        BranchStatus branchCommit(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException;
    
        // 分支事务回滚
        BranchStatus branchRollback(BranchType branchType, String xid, long branchId, String resourceId, String applicationData) throws TransactionException;
    }

    和TCInboundHandler比起来,ResourceManagerInbound中的定义就简单了很多,仅仅是对分支事务的提交和回滚。

    总结

    DefaultCoordinator作为Server端的核心实现类,实现了TCInboundHandler和ResourceManagerInbound两个接口,分别关于全局事务的处理和分支事务的处理逻辑。

  • 相关阅读:
    〖C语言学习笔记 〗(一) HelloWorld
    〖C语言学习笔记 〗(二) 数据类型
    「学习笔记」进制转换
    Debian/Ubuntu 下网易云音乐无法由图标/列表 打开的解决方案
    Linux iptables常用命令的使用
    【学习笔记】Spring AOP注解使用总结
    【学习笔记】AspectJ笔记
    SpringMvc数据校验@Valid等注解的使用与工具类抽取
    Ubuntu 16.04开机自启Nginx简单脚本
    Spring Cloud (十五)Stream 入门、主要概念与自定义消息发送与接收
  • 原文地址:https://www.cnblogs.com/lay2017/p/12497882.html
Copyright © 2020-2023  润新知