1. Project Overview & Quickstart (apache/incubator-seata)
File: README.md
Apache Seata (incubating): Simple Extensible Autonomous Transaction Architecture
What is Apache Seata (incubating)?
A distributed transaction solution with high performance and ease of use for microservices architecture.
Distributed Transaction Problem in Microservices
Let's imagine a traditional monolithic application. Its business is built up with 3 modules. They use a single local data source.
Naturally, data consistency will be guaranteed by the local transaction.
Things have changed in a microservices architecture. The 3 modules mentioned above are designed to be 3 services on top of 3 different data sources (Pattern: Database per service). Data consistency within every single service is naturally guaranteed by the local transaction.
But how about the whole business logic scope?
Architecture
Apache Seata offers a robust solution to the distributed transaction challenges in microservices.
Core Concepts
A Distributed Transaction is a Global Transaction composed of a batch of Branch Transactions, where a Branch Transaction is typically a Local Transaction.
Roles
There are three main roles in the Apache Seata Framework:
- Transaction Coordinator(TC): Maintain status of global and branch transactions, drive the global commit or rollback.
- Transaction Manager(TM): Define the scope of global transaction: begin a global transaction, commit or rollback a global transaction.
- Resource Manager(RM): Manage resources that branch transactions working on, talk to TC for registering branch transactions and reporting status of branch transactions, and drive the branch transaction commit or rollback.
Transaction Lifecycle
A typical lifecycle of an Apache Seata managed distributed transaction:
- TM asks TC to begin a new global transaction. TC generates an XID representing the global transaction.
- XID is propagated through microservices' invoke chain.
- RM registers local transaction as a branch of the corresponding global transaction of XID to TC.
- TM asks TC for committing or rollbacking the corresponding global transaction of XID.
- TC drives all branch transactions under the corresponding global transaction of XID to finish branch committing or rollbacking.
For more details about principle and design, please go to Apache Seata wiki page.
History
Alibaba
- TXC: Taobao Transaction Constructor. Alibaba middleware team started this project since 2014 to meet the distributed transaction problems caused by application architecture change from monolithic to microservices.
- GTS: Global Transaction Service. TXC as an Aliyun middleware product with new name GTS was published since 2016.
- Fescar: we started the open source project Fescar based on TXC/GTS since 2019 to work closely with the community in the future.
Ant Financial
XTS: Extended Transaction Service. Ant Financial middleware team developed the distributed transaction middleware since 2007, which is widely used in Ant Financial and solves the problems of data consistency across databases and services.
DTX: Distributed Transaction Extended. Since 2013, XTS has been published on the Ant Financial Cloud, with the name of DTX .
Seata Community
- Seata: Simple Extensible Autonomous Transaction Architecture. Ant Financial joins Fescar, which make it to be a more neutral and open community for distributed transaction, and Fescar be renamed to Seata.
- Apache Seata: In October 2023, Seata entered the Apache Incubator.
Maven dependency
Depending on the scenario, choose one of the two dependencies: org.apache.seata:seata-all or org.apache.seata:seata-spring-boot-starter.
<seata.version>2.5.0</seata.version>
<dependencies>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-all</artifactId>
<version>${seata.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>${seata.version}</version>
</dependency>
</dependencies>Quick Start
Documentation
You can view the full documentation from Apache Seata Official Website: Apache Seata Website page.
Reporting bugs
Please follow the template for reporting any issues.
Security
Please do not use our public issue tracker but refer to our security policy
Contributing
Contributors are welcomed to join the Apache Seata project. Please check CONTRIBUTING and CONTRIBUTING-CN about how to contribute to this project.
Contact
- Mailing list:
- [email protected] , for dev/user discussion. subscribe, unsubscribe, archive
- Online chat:
| Dingtalk group | Wechat official account | QQ group | Wechat assistant |
|---|---|---|---|
Apache Seata ecosystem
- Apache Seata Website - Apache Seata official website
- Apache Seata GoLang - Apache Seata GoLang client
- Apache Seata Samples - Samples for Apache Seata Java
- Apache Seata GoLang Samples - Samples for Apache Seata GoLang
- Apache Seata K8s - Apache Seata integration with Kubernetes
- Apache Seata CLI - CLI tool for Apache Seata operations
Contributors
This project exists thanks to all the people who contribute. [Contributors].
License
Apache Seata is under the Apache 2.0 license. See the LICENSE file for details.
Who is using
These are only part of the companies using Apache Seata, for reference only. If you are using Apache Seata, please add your company
here to tell us your scenario to make Apache Seata better.
File: console/src/main/resources/static/console-fe/README.md
开始项目
cnpm 安装(可忽略)
npm install cnpm --registry=https://registry.npmmirror.com
# 设置匿名
alias cnpm="npm --registry=https://registry.npmmirror.com \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npmmirror.com/mirrors/node \
--userconfig=$HOME/.cnpmrc"
# Or alias it in .bashrc or .zshrc
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npmmirror.com \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npmmirror.com/mirrors/node \
--userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc安装依赖
yarn或
cnpm install启动
yarn start或
npm start构建打包
yarn build或
npm run build代理配置
build/webpack.dev.conf.js
修改proxy属性
proxy: [{
context: ['/'],
changeOrigin: true,
secure: false,
target: 'http://ip:port',
}],File: core/src/main/java/io/seata/core/README.md
request
rm client -> server
RegisterRMRequest
MergedWarpMessage
BranchRegisterRequest
BranchReportRequest
GlobalLockQueryRequesttm client -> server
RegisterTMRequest
MergedWarpMessage
GlobalBeginRequest
GlobalCommitRequest
GlobalRollbackRequest
GlobalStatusRequest
GlobalReportRequestserver -> rm client
BranchCommitRequest
BranchRollbackRequest
UndoLogDeleteRequestserver -> tm client
// nullresponse
Server -> rm client
RegisterRMResponse
MergeResultMessage
BranchRegisterResponse
BranchReportResponse
GlobalLockQueryResponseServer -> tm client
RegisterTMResponse
MergeResultMessage
GlobalBeginResponse
GlobalCommitResponse
GlobalReportResponse
GlobalRollbackResponserm client -> server
BranchCommitResponse
BranchRollbackResponsetm client -> server
// nullFile: metrics/README.md
Metrics
设计思路
- Seata作为一个被集成的数据一致性框架,Metrics模块将尽可能少的使用第三方依赖以降低发生冲突的风险;
- Metrics模块将竭力争取更高的度量性能和更低的资源开销,尽可能降低开启后带来的副作用;
- 配置式,Metrics是否激活、数据如何发布,取决于对应的配置;
- 不使用Spring,使用SPI(Service Provider Interface)加载扩展;
- 初始仅发布核心Transaction相关指标,之后结合社区的需求,逐步完善运维方面的所有其他指标。
模块说明
由2个核心API模块seata-metrics-api和seata-metrics-core,以及N个实现模块例如seata-metrics-registry-compact、seata-metrics-exporter-prometheus构成:
- seata-metrics-api模块
此模块是Metrics的核心,将作为Seata基础架构的一部分被TC、TM和RM引用,它内部没有任何具体实现代码,仅包含接口定义,定义的内容包括:
- Meter类接口:
Gauge、Counter、Timer... - 注册容器接口
Registry - Measurement数据导出接口
Exporter
提示:Metrics本身在开源领域也已有很多实现,例如
它们有的轻而敏捷,有的重而强大,由于也是“实现”,因此不会纳入
seata-metrics-api中,避免实现绑定。
- seata-metrics-core模块
Metrics核心模块,根据配置组织(加载)1个Registry和N个Exporter;
- seata-metrics-registry-compact模块
这是我们提供的默认(内置)的Registry实现,不使用其它Metrics开源库,轻量级的实现了以下四种Meter:
| Meter类型 | 描述 |
|---|---|
| CompactGauge | 单一最新值度量器 |
| CompactCounter | 单一累加度量器,可增可减 |
| CompactSummary | 多Measurement输出计数器,将输出total(合计)、count(计数)、max(最大)、average(合计/计数)和tps(合计/时间间隔),无单位 |
| CompactTimer | 多Measurement输出计时器,将输出total(合计)、count(计数)、max(最大)和average(合计/计数),支持微秒为单位累计 |
其中包含的Registry,即CompactRegistry,它只有接受measure()方法调用的时候才计算度量值,因此计算窗口完全取决于Exporter的实现,故目前不太适合需要多Exporter的场景使用(如何扩展请参见后文)。
说明:
- 未来可能增加更丰富复杂的度量器例如Histogram,这是一种可以本地统计聚合75th, 90th, 95th, 98th, 99th,99.9th...的度量器,适合某些场合,但需要更多内存。
- 所有的计量器都将继承自Meter,所有的计量器执行measure()方法后,都将归一化的生成1或N个Measurement结果。
- seata-metrics-exporter-prometheus模块
Prometheus发布器PrometheusExporter,将度量数据同步给Prometheus。
说明:不同的监控系统,采集度量数据的方式不尽相同,例如Zabbix支持用zabbix-agent推送,Prometheus则推荐使用prometheus-server拉取的方式;同样数据交换协议也不同,因此往往需要逐一适配。
如何使用
如果需要开启TC的Metrics,需要在其配置中增加配置项:
## metrics settings
metrics {
enable = true
registry-type = "compact"
# multi exporters use comma divided
exporter-list = "prometheus"
exporter-prometheus-port = 9898
}启动TC,即可在http://tc-server-ip:9898/metrics上获取到Metrics的文本格式数据。
提示:默认使用
9898端口,Prometheus已登记的端口列表在此,如果想更换端口,可通过metrics.exporter-prometheus-port配置修改。
下载并启动Prometheus
下载完毕后,修改Prometheus的配置文件prometheus.yml,在scrape_configs中增加一项抓取Seata的度量数据:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'seata'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['tc-server-ip:9898']查看数据输出
推荐结合配置Grafana获得更好的查询效果,初期Seata导出的Metrics包括:
- TC :
| Metrics | 描述 |
|---|---|
| seata.transaction(role=tc,meter=counter,status=active/committed/rollback) | 当前活动中/已提交/已回滚的事务总数 |
| seata.transaction(role=tc,meter=summary,statistic=count,status=committed/rollback) | 当前周期内提交/回滚的事务数 |
| seata.transaction(role=tc,meter=summary,statistic=tps,status=committed/rollback) | 当前周期内提交/回滚的事务TPS(transaction per second) |
| seata.transaction(role=tc,meter=timer,statistic=total,status=committed/rollback) | 当前周期内提交/回滚的事务耗时总和 |
| seata.transaction(role=tc,meter=timer,statistic=count,status=committed/rollback) | 当前周期内提交/回滚的事务数 |
| seata.transaction(role=tc,meter=timer,statistic=average,status=committed/rollback) | 当前周期内提交/回滚的事务平均耗时 |
| seata.transaction(role=tc,meter=timer,statistic=max,status=committed/rollback) | 当前周期内提交/回滚的事务最大耗时 |
提示:seata.transaction(role=tc,meter=summary,statistic=count,status=committed/rollback)和seata.transaction(role=tc,meter=timer,statistic=count,status=committed/rollback)的值可能相同,但它们来源于两个不同的度量器。
- TM:
稍后实现,包括诸如:
seata.transaction(role=tm,name={GlobalTransactionalName},meter=counter,status=active/committed/rollback) : 以GlobalTransactionalName为维度区分不同Transactional的状态。
- RM:
稍后实现,包括诸如:
seata.transaction(role=rm,name={BranchTransactionalName},mode=at/mt,meter=counter,status=active/committed/rollback):以BranchTransactionalName为维度以及AT/MT维度区分不同分支Transactional的状态。
如何扩展
如果有下面几种情况:
- 您不是使用Prometheus作为运维监控系统,但希望能够将Seata的Metrics数据集成进Dashboard中;
您需要实现新的Exporter,例如如果需要对接Zabbix,创建seata-metrics-exporter-zabbix模块,然后在ExporterType中添加新的Exporter类型,最后在metrics.exporter-list中配置。
- 您需要更复杂强大的度量器类型,这些度量器在其他Metrics实现库中已有,希望集成这些第三方依赖直接使用;
您可以不使用内置的CompactRegistry的实现,完全扩展一个新的Registry库,例如希望使用Netflix Spectator的实现,扩展名为seata-metrics-registry-spectator的模块,然后在RegistryType中添加新的Registry类型,开发完成后,设置metrics.registry-type为对应的类型。
- 您需要改变默认Metric的Measurement输出,例如在Timer中增加一个
min或sd(方差);
您可以修改对应Meter的实现,包括measure()方法返回的Measurement列表。
File: saga/seata-saga-statemachine-designer/README.md
English | 简体中文
Seata Saga StateMachine Designer
A visual graph Seata Saga StateMachine Designer based on GGEditor.
run
$ git clone https://github.com/seata/seata.git
$ cd saga/seata-saga-statemachine-designer
$ npm install
$ npm startbuild a package
$ cd saga/saga-statemachine-designer
$ npm run buildcopy 'index.html' and 'dist' directory to static html directory of web server
Usage
To understand the state types of the state machine, please see document of Saga. After using the designer to complete the design of the state machine, you can click the 'Json View' button on the toolbar to switch to the Json view, and save the Json to the project of your own application. Although the Json generated by the designer is different from the standard Json of the Saga state machine (because the json generated by the designer has layout information), the state machine can be directly loaded and it will be converted into the Json of the Saga state machine standard.
File: saga/seata-saga-statemachine-designer/README.zh-CN.md
English | 简体中文
Seata Saga 状态机可视化图形设计器
Seata Saga 状态机可视化图形设计器, 基于 GGEditor
运行
$ git clone https://github.com/seata/seata.git
$ cd saga/seata-saga-statemachine-designer
$ npm install
$ npm start打包
$ cd saga/saga-statemachine-designer
$ npm run build然后将index.html和dist目录拷贝到web server的静态页面目录下
使用
了解状态机的种状态类型,请看Saga的文档。 通过设计器完成设计后可以点击工具栏的'Json View'按钮切换到Json视图,将Json拷贝保存到自己应用的工程里。虽然设计器生成的Json与Saga标准的Json有所差别(因为设计器生成的json带有布局信息),但状态机可以直接加载,它会将其转化成Saga状态机标准的Json。
File: script/config-center/README.md
Script usage demo
important attributes
you only need to follow the instructions below and keep the corresponding configuration in 'config.txt' to run. For more configuration information, please visit seata.apache.org
| server | client |
|---|---|
| store.mode: file,db | config.type: file、nacos 、apollo、zk、consul、etcd3、custom |
| #only db: | #only file: |
| store.db.driverClassName | service.default.grouplist |
| store.db.url | #All: |
| store.db.user | service.vgroupMapping.default_tx_group |
| store.db.password | service.disableGlobalTransaction |
Script Introduction
The Script has interactive and non-interactive configuration modes,different patterns are distinguished by different file names.
interactive mode(*-config-interactive.sh or *-config-interactive.py): the script starts the config program in interactive mode on the command line, prompting you for each option.
non-interactive mode(*-config.sh or *-config.py): the script use additional config options to specify values for the options you choose during interactive mode, thus scripting the config process.
Nacos
shell:
- Interactive Mode
sh ${SEATAPATH}/script/config-center/nacos/nacos-config-interactive.shThis command will generate interactive configuration mode, eg:
Please enter the host of nacos.
请输入nacos的host [localhost]:
>>>
Please enter the port of nacos.
请输入nacos的port [8848]:
>>>
Please enter the group of nacos.
请输入nacos的group [SEATA_GROUP]:
>>>
Please enter the tenant of nacos.
请输入nacos的tenant:
>>>
Please enter the username of nacos.
请输入nacos的username:
>>>
Please enter the password of nacos.
请输入nacos的password:
>>>
Are you sure to continue? [y/n]- Non-Interactive Mode
sh ${SEATAPATH}/script/config-center/nacos/nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t 5a3c7d6c-f497-4d68-a71a-2e5e3340b3ca -u username -w passwordpython:
- Interactive Mode
python ${SEATAPATH}/script/config-center/nacos/nacos-config-interactive.pyThis command will generate interactive configuration mode like nacos-config-interactive.sh.
- Non-Interactive Mode
python ${SEATAPATH}/script/config-center/nacos/nacos-config.py localhost:8848Parameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 8848.
-g: Configure grouping, the default value is 'SEATA_GROUP'.
-t: Tenant information, corresponding to the namespace ID field of Nacos, the default value is ''.
-u: username, nacos 1.2.0+ on permission control, the default value is ''.
-w: password, nacos 1.2.0+ on permission control, the default value is ''.
Apollo
- Interactive Mode
sh ${SEATAPATH}/script/config-center/apollo/apollo-config-interactive.shThis command will generate interactive configuration mode, eg:
Please enter the host of apollo.
请输入apollo的host [localhost]:
>>>
Please enter the port of apollo.
请输入apollo的port [8070]:
>>>
Please enter the env of apollo.
请输入apollo的env [DEV]:
>>>
Please enter the appId of apollo.
请输入apollo的appId [seata-server]:
>>>
Please enter the clusterName of apollo.
请输入apollo的clusterName [default]:
>>>
Please enter the namespaceName of apollo.
请输入apollo的namespaceName [application]:
>>>
Please enter the dataChangeCreatedBy of apollo.
请输入apollo的dataChangeCreatedBy:
>>>
Please enter the releasedBy of apollo.
请输入apollo的releasedBy:
>>>
Please enter the token of apollo.
请输入apollo的token:
>>>
Are you sure to continue? [y/n]- Non-Interactive Mode
sh ${SEATAPATH}/script/config-center/apollo/apollo-config.sh -h localhost -p 8070 -e DEV -a seata-server -c default -n application -d apollo -r apollo -t 3aa026fc8435d0fc4505b345b8fa4578fb646a2cParameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 8070.
-e: Managed configuration environment, the default value is DEV.
-a: AppId to which the namespace belongs, the default value is seata-server.
-c: Managed configuration cluster name, Generally, you can pass in default. If it is a special cluster, just pass in the name of the corresponding cluster,the default value is default.
-n: Name of the managed namespace, If the format is not properties, you need to add a suffix name, such as sample.yml, the default value is application.
-d: The creator of the item, in the format of a domain account, which is the User ID of the sso system.
-r: Publisher, domain account, note: if namespace.lock.switch in ApolloConfigDB.ServerConfig is set to true (default is false), Then the environment does not allow the publisher and editor to be the same person. So if the editor is zhangsan, the publisher can no longer be zhangsan.
-t: Apollo admin creates third-party applications in http://{portal_address}/open/manage.html, It is best to check whether this AppId has been created before creation. After successful creation, a token will be generated.
For details of the above parameter descriptions, please see:
https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0
Consul
- Interactive Mode
sh ${SEATAPATH}/script/config-center/consul/consul-config-interactive.shThis command will generate interactive configuration mode, eg:
Please enter the host of consul.
请输入consul的host [localhost]:
>>>
Please enter the port of consul.
请输入consul的port [8500]:
>>>
Are you sure to continue? [y/n]- Non-Interactive Mode
sh ${SEATAPATH}/script/config-center/consul/consul-config.sh -h localhost -p 8500Parameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 8500.
Etcd3
- Interactive Mode
sh ${SEATAPATH}/script/config-center/etcd3/etcd3-config-interactive.shThis command will generate interactive configuration mode, eg:
Please enter the host of etcd3.
请输入etcd3的host [localhost]:"
>>>
Please enter the port of etcd3.
请输入etcd3的port [2379]:
>>>
Are you sure to continue? [y/n]- Non-Interactive Mode
sh ${SEATAPATH}/script/config-center/etcd3/etcd3-config.sh -h localhost -p 2379Parameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 2379.
ZK
- Interactive Mode
sh ${SEATAPATH}/script/config-center/zk/zk-config-interactive.shThis command will generate interactive configuration mode, eg:
Please enter the host of zookeeper.
请输入zookeeper的host [localhost]:
>>>
Please enter the port of zookeeper.
请输入zookeeper的port [2181]:
>>>
Please enter the zkHome of zookeeper.
请输入zookeeper的zkHome:
>>>
Are you sure to continue? [y/n]- Non-Interactive Mode
sh ${SEATAPATH}/script/config-center/zk/zk-config.sh -h localhost -p 2181 -z "/Users/zhangchenghui/zookeeper-3.4.14"Parameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 2181.
-z: zk path.
File: server/src/main/resources/README.md
Script Description
[client](https://github.com/seata/seata/tree/develop/script/client)
Store configuration and SQL for client side
- at: Script of create table
undo_logfor AT mode. - conf: Configuration which client need.
- saga: Script of create table in SAGA mode
- spring: Configuration for Spring Boot
[server](https://github.com/seata/seata/tree/develop/script/server)
Store SQL and deploy script for server side
- db: Create table script for server when store mode is
db - docker-compose: Script for deploy server by docker-compose
- helm: Script for deploy server by Helm
- kubernetes: Script for deploy server by Kubernetes
[config-center](https://github.com/seata/seata/tree/develop/script/config-center)
Store initialize script for configuration center, will use
config.txtas configuration when initial
- nacos: Initialize script for Nacos
- zk: Initialize script for ZooKeeper, the script need related script in Zookeeper, you need download yourself. You can modify
zk-params.txtto change the ZooKeeper server configuration, or input when execute also - apollo: Initialize script for Apollo. You can modify
apollo-params.txtto change the Apollo server configuration, or input when execute also - etcd3: Initialize script for Etcd3
- consul: Initialize script for consul
build packege
./mvnw -Prelease-seata -Dmaven.test.skip=true clean install -U
File: server/src/main/resources/README-zh.md
脚本说明
[client](https://github.com/seata/seata/tree/develop/script/client)
存放用于客户端的配置和SQL
- at: AT模式下的
undo_log建表语句 - conf: 客户端的配置文件
- saga: SAGA 模式下所需表的建表语句
- spring: SpringBoot 应用支持的配置文件
[server](https://github.com/seata/seata/tree/develop/script/server)
存放server侧所需SQL和部署脚本
- db: server 侧的保存模式为
db时所需表的建表语句 - docker-compose: server 侧通过 docker-compose 部署的脚本
- helm: server 侧通过 Helm 部署的脚本
- kubernetes: server 侧通过 Kubernetes 部署的脚本
[config-center](https://github.com/seata/seata/tree/develop/script/config-center)
用于存放各种配置中心的初始化脚本,执行时都会读取
config.txt配置文件,并写入配置中心
- nacos: 用于向 Nacos 中添加配置
- zk: 用于向 Zookeeper 中添加配置,脚本依赖 Zookeeper 的相关脚本,需要手动下载;ZooKeeper相关的配置可以写在
zk-params.txt中,也可以在执行的时候输入 - apollo: 向 Apollo 中添加配置,Apollo 的地址端口等可以写在
apollo-params.txt,也可以在执行的时候输入 - etcd3: 用于向 Etcd3 中添加配置
- consul: 用于向 consul 中添加配置
打包
./mvnw -Prelease-seata -Dmaven.test.skip=true clean install -U
File: tcc/README.md
TCC
简介
在2PC(两阶段提交)协议中,事务管理器分两阶段协调资源管理,资源管理器对外提供了3个操作,分别是一阶段的准备操作,二阶段的提交操作和回滚操作;
TCC服务作为一种事务资源,遵循两阶段提交协议,由业务层面自定义,需要用户根据业务逻辑编码实现;其包含Try、Confirm 和 Cancel 3个操作,其中Try操作对应分布式事务一阶段的准备,Confirm操作对应分布式事务二阶段提交,Cancel对应分布式事务二阶段回滚:
- Try:
资源的检查和预留;
- Confirm:
使用预留的资源,完成真正的业务操作;要求Try成功Confirm 一定要能成功;
- Cancel:
释放预留资源;
TCC的3个方法均由用户根据业务场景编码实现,并对外发布成微服务,供事务管理器调用;事务管理器在一阶段调用TCC的Try方法,在二阶段提交时调用Confirm方法,在二阶段回滚时调用Cancel方法。
实现
1、TCC 微服务
TCC服务由用户编码实现并对外发布成微服务,目前支持3种形式的TCC微服务,分别是:
- SofaRpc 服务
用户将实现的TCC操作对外发布成 SofaRpc 服务,事务管理器通过订阅SofaRpc服务,来协调TCC资源;
- Dubbo 服务
将TCC发布成dubbo服务,事务管理器订阅dubbo服务,来协调TCC资源;
- Local TCC
本地普通的TCC Bean,非远程服务;事务管理器通过本地方法调用,来协调TCC 资源;
2、TCC 资源动态代理
对TCC服务进行动态代理,GlobalTransactionScanner中当扫描到TCC 服务的 ‘reference’时,会对其进行动态代理;
TCC 动态代理的主要功能是:生成TCC运行时上下文、透传业务参数、注册分支事务记录;
模块说明
seata-tcc 包含TCC主要代码:
interceptor:TCC 动态代理;
remoting:TCC微服务扫描、RPC协议解析、TCC资源注册;
TccResourceManager、RMHandlerTCC: TCC资源管理器;
其他说明:
本此为了区分AT、TCC 2种资源类型,在客户端和服务端通信的接口中,均添加了 BranchType 参数;
2. Official Technical Reference & Guides (apache/incubator-seata.github.io)
Seata Official Website
All website material of https://seata.apache.org, which uses a open source framework: Docusaurus.
Quick Start
npm installnpm run startfor starting Seata's English webpage in your local machine.npm run start-zh-cnfor starting Seata's Chinese Simplified webpage in your local machine.Visit
localhost:3000/Build
npm run buildnpm run serveVisit
localhost:3000/Requirements
Base docusaurus 2.4.1
Node.js version 19.5.0
Note for i18n
Please be noted that locale switching function doesn't work if you start the website in development mode using npm run start-zh-cn or npm run start. Please run it in production mode using the build-and-serve process to enable the locale switching function.
Overview of the Website Structure
We use the Docusaurus internationalization (i18n) to support both English(en) and Chinese Simplified(zh-cn) Seata Website. Besides, we apply Docusaurus Versioning to get versioned docs.
Our website stucture with i18n and versioning looks like below:
website
├── sidebars.json # sidebar for the current docs version
├── docs # docs directory for the current docs version
│ ├── foo
│ │ └── bar.md # https://mysite.com/docs/next/foo/bar
│ └── hello.md # https://mysite.com/docs/next/hello
├── versions.json # file to indicate what versions are available
├── versioned_docs
│ ├── version-1.1.0
│ │ ├── foo
│ │ │ └── bar.md # https://mysite.com/docs/foo/bar
│ │ └── hello.md
│ └── version-1.0.0
│ ├── foo
│ │ └── bar.md # https://mysite.com/docs/1.0.0/foo/bar
│ └── hello.md
├── versioned_sidebars
│ ├── version-1.1.0-sidebars.json
│ └── version-1.0.0-sidebars.json
├── blog
├── docusaurus.config.js
├── package.json
├── i18n
│ ├── en
│ │ ├── docusaurus-plugin-content-docs
│ │ │ ├── current
│ │ │ ├── version-1.0.0
│ │ │ └── version-1.1.0
│ │ ├── docusaurus-plugin-content-blog
│ │ └── ...
│ └── zh-cn
│ │ ├── docusaurus-plugin-content-docs
│ │ │ ├── current
│ │ │ ├── version-1.0.0
│ │ │ └── version-1.1.0
│ │ ├── docusaurus-plugin-content-blog
│ │ └── ...How To Add Documents
Directories Related to Adding Documents
docs - Contain the current (latest version) documents (placeholder for sidebar indexing purposes)
Document Content should be Placeholder. DO NOT DELETE.
sidebars.json - Set the sidebar for the current (latest version) documents.
versioned_docs - Contain the previous version documents (placeholder for sidebar indexing purposes)
Document Content should be Placeholder. DO NOT DELETE.
versioned_sidebars - Set the sidebar for the specific previous versions documents.
i18n-en-docusaurus-plugin-content-docs-current - Contain the actual latest version English documents.
i18n-en-docusaurus-plugin-content-docs-version-1.0.0 - Contain the actual 1.0.0 version English documents.
i18n-zh-cn-docusaurus-plugin-content-docs-current - Contains the actual latest version Simplified Chinese documents.
i18n-zh-cn-docusaurus-plugin-content-docs-version-1.0.0 - Contain the actual 1.0.0 version Simplified Chinese documents.
Summary of Adding Documents
Steps to add a document for the latest version:
- Place placeholder document under the docs directory which is located in the root directory.
- Update sidebar.js, add a new entry to the path of this document.
- Place the English document under the i18-
en-docusaurus-plugin-content-docs-currentdirectory. - Place the Chinese document under the i18-
zh-cn-docusaurus-plugin-content-docs-currentdirectory.
Steps to add a document for a previous version:
- Place a placeholder document under the specific versioned_docs directory for the desired version which is located in the root directory.
- Update specific versioned_sidebars file, add a new entry to the path of this document.
- Place the English document under the i18-
en-docusaurus-plugin-content-docs-specific version numberdirectory. - Place the Chinese document under the i18-
zh-cn-docusaurus-plugin-content-docs-specific version numberdirectory.
Notes: Corresponding to Chinese file and English file of same contents, and the Chinese and English file names should be consistent.
How To Add Blogs
We don't have a versioned blog, so it's easier to add a blog. When adding a new blog, it is automatically added in the Blog sidebar, where the order of blogs is sorted by the date field in SEO in the blog file.
Directories Related to Adding Blogs
blog - Contain the blogs(placeholder for blog sidebar indexing purposes)
Blog Content should be Placeholder. DO NOT DELETE.
i18n-en-docusaurus-plugin-content-blog - Contain all the actual English blogs.
i18n-zh-cn-docusaurus-plugin-content-blog - Contain all the actual Simplified Chinese blogs.
Summary of Adding Blogs
Steps to add a blog:
- Place placeholder blog under the blog directory which is located in the root directory.
- Place the English blog under the i18-
en-docusaurus-plugin-content-blog directory. - Place the Chinese blog under the i18-
zh-cn-docusaurus-plugin-content-blog directory.
Notes: Corresponding to Chinese file and English file of same contents, and the Chinese and English file names should be consistent.
SEO Needed in Both Docs and Blogs
The type is:
---
title: title
keywords: [keywords1,keywords2]
author: author name
date: 2018-12-29
custom_edit_url: https://github.com/apache/incubator-seata-website/blob/docusaurus/i18n/en/docusaurus-plugin-content-blog/quick-start-use-seata-and-dubbo-services.md
---Note:
titlecan not include:keywordsmust be aArray
Note for .md file
- Do not use un correct html tag like
、, replace with - If you want show
<xx>, replace with<xx> - Use
npm run lintto check the style.
Others
This is official Docusaurus docs: https://docusaurus.io/docs