seata之at模式源码分析(一)

at模式讲解

public Object execute(TransactionalExecutor business) throws Throwable {
        // 1 get transactionInfo  获取事务相关的配置信息
        // 1.1 get or create a transaction  获取事务
        // 1.2 根据事务不同的传播机制 进行处理
   
        try {

                // 2. begin transaction
                beginTransaction(txInfo, tx);

                Object rs = null;
                try {

                    // Do Your Business
                    rs = business.execute();

                } catch (Throwable ex) {

                    // 3.the needed business exception to rollback.
                    completeTransactionAfterThrowing(txInfo, tx, ex);
                    throw ex;
                }

                // 4. everything is fine, commit.
                commitTransaction(tx);

                return rs;
            } finally {
                //5. clear
                triggerAfterCompletion();
                cleanUp();
            }
        } finally {
            tx.resume(suspendedResourcesHolder);
        }

    }

假设现在有一个上游方法,内部调用了a服务和b服务,这两个服务都是分布式的,并且都更新了各自的数据,则相应的时序逻辑如下:


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。