Compare commits

...

1 Commits

Author SHA1 Message Date
lvekee ccefad5ad9
Refactor the directory structure of the official website (#438)
* refactor docs/zh-cn

* update seo

* refactor en-us

* fix error in the metrics doc

* fix

* fix
2022-04-22 22:31:16 +08:00
143 changed files with 1201 additions and 1612 deletions

View File

@ -2,6 +2,8 @@
title: Seata事务隔离 title: Seata事务隔离
keywords: Seata事务隔离 keywords: Seata事务隔离
description: Seata事务隔离 description: Seata事务隔离
author: 张思雨
date: 2021-10-16
--- ---
# Seata事务隔离 # Seata事务隔离

View File

@ -0,0 +1,7 @@
---
title: Seata Framework
keywords: Framework
description: Introduce the logical framework of Seata, and learn about Seata TC, TM and RM, their respective responsibilities and working methods
---
Welcome to claim this document

View File

@ -0,0 +1,8 @@
---
title: Transaction mode overview
keywords: Transaction mode
description: Introduce the four transaction modes of Seata, the applicable scenarios, advantages and disadvantages of each transaction mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata XA Mode
keywords: Seata,XA mode
description: Seata XA mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Transaction and distributed transaction
keywords: Transaction,distributed transaction
description: This paper introduces the characteristics of transaction acid and the mainstream distributed transaction solutions and theories
---
Welcome to claim this document

View File

@ -1,149 +0,0 @@
---
hidden: true
title: High Available Usage Deployment
keywords: kubernetes,ops
description: High Available Usage Deployment
author: helloworlde
date: 2020-04-10
---
# High Available Usage Deployment
> High available usage deployment of Seata depends on registry center, configuration center and database.
## Seata-Server
The Seata-Server need registry center, and save transaction data into database, for example, use Nacos
- Modify configuration in `registry.conf`
```
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.199.2"
namespace = ""
cluster = "default"
username = ""
password = ""
}
}
config {
type = "nacos"
nacos {
serverAddr = "192.168.199.2"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
}
```
- Modify configuration in configuration center
```
service.vgroupMapping.my_test_tx_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.199.2:30060/seata?useUnicode=true
store.db.user=root
store.db.password=123456
```
- Create table `global_table`, `branch_table`, `lock_table` in database
Please reference script on [/script/server/db/](https://github.com/seata/seata/tree/develop/script/server/db)
Now, startup multiple seata-server, and then the server is support high available usage.
----
For example, using Kubernetes deploy, the configuration file like:
```yaml
apiVersion: v1
kind: Service
metadata:
name: seata-ha-server
namespace: default
labels:
app.kubernetes.io/name: seata-ha-server
spec:
type: ClusterIP
ports:
- port: 8091
protocol: TCP
name: http
selector:
app.kubernetes.io/name: seata-ha-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: seata-ha-server
namespace: default
labels:
app.kubernetes.io/name: seata-ha-server
spec:
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: seata-ha-server
template:
metadata:
labels:
app.kubernetes.io/name: seata-ha-server
spec:
containers:
- name: seata-ha-server
image: docker.io/seataio/seata-server:latest
imagePullPolicy: IfNotPresent
env:
- name: SEATA_CONFIG_NAME
value: file:/root/seata-config/registry
ports:
- name: http
containerPort: 8091
protocol: TCP
volumeMounts:
- name: seata-config
mountPath: /root/seata-config
volumes:
- name: seata-config
configMap:
name: seata-ha-server-config
---
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-ha-server-config
data:
registry.conf: |
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.199.2"
}
}
config {
type = "nacos"
nacos {
serverAddr = "192.168.199.2"
group = "SEATA_GROUP"
}
}
```
You can reference [seata-ha-deploy-practice](https://seata.io/zh-cn/blog/seata-ha-practice.html) for more detail about practice of HA deploy.

View File

@ -1,64 +0,0 @@
---
title: Multi-configuration Isolation
keywords: Seata
description: Seata supports Multi-configuration Isolation since 0.6.1,You can configure it in the following steps.
---
# Multi-configuration Isolation
Seata supports Multi-configuration Isolation since 0.6.1,You can configure it in the following steps.
## use case
Suppose we now have a test environment in which we want to read only the configuration items corresponding to the test environment.
### 1.Environment Configuration
Seata provides two ways to set up different environments:
- **-e test**,where test is the name of the environment.(**This can be only used for server side**)
```shell
e.g.(Linux)
sh seata-server.sh -e test
```
- Use **SEATA_ENV** as the key of environment variable,and it's value will be the name of the environment.(**This can be only used for client side**)[**recommended**]
```shell
e.g.(Linux)
#vi /etc/profile
export SEATA_ENV=test
:wq
#source /etc/profile
```
- Use **seataEnv** as the key of jvm options,and it's value will be the name of the environment.(**This can be only used for client side**)[**recommended**]
```
-DseataEnv=test
```
### 2.Name the new configuration file
- Copy and rename file.conf to file-env.conf,where env is the name of the environment. e.g. **file-test.conf**
- Copy and rename registry.conf to registry-env.conf,where env is the name of the environment. e.g. **registry-test.conf**
- In the registry-test.conf file, modify as follows:
```shell
registry {
...
file {
name = "file-test.conf"
}
config {
...
file {
name = "file-test.conf"
}
```
After all the steps have been set up, you can start using Seata configuration isolation.

View File

@ -0,0 +1,8 @@
---
title: RoadMap
keywords: RoadMap
description: Seata roadmap
---
Welcome to claim this document

View File

@ -1,15 +0,0 @@
---
title: Seata Terminology
keywords: Seata
description: Seata Terminology.
---
# Seata Terminology
#### TC - Transaction Coordinator
Maintain status of global and branch transactions, drive the global commit or rollback.
#### TM - Transaction Manager
Define the scope of global transaction: begin a global transaction, commit or rollback a global transaction.
#### RM - Resource Manager
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.

View File

@ -0,0 +1,7 @@
---
title: Advanced use of AT mode
keywords: AT,AT Mode,Advanced
description: Advanced use of AT mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Integration use of AT mode
keywords: AT,AT Mode,Integration
description: Integration use of AT mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Quick start use of AT mode
keywords: AT,AT Mode,Quick start
description: Quick start use of AT mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Advanced use of Saga mode
keywords: Saga,Saga Mode,Advanced
description: Advanced use of Saga mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Integration use of Saga mode
keywords: Saga,Saga Mode,Integration
description: Integration use of Saga mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Quick start use of Saga mode
keywords: Saga,Saga Mode,Quick start
description: Quick start use of Saga mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Use Docker compose deploy Seata Server
keywords: docker-compose,ops
description: Use Docker compose deploy Seata Server
---
Welcome to claim this document

View File

@ -1,5 +1,4 @@
--- ---
hidden: true
title: Deploy Seata Server By Helm title: Deploy Seata Server By Helm
keywords: kubernetes,helm,ops keywords: kubernetes,helm,ops
description: Deploy Seata Server By Helm description: Deploy Seata Server By Helm

View File

@ -1,5 +1,4 @@
--- ---
hidden: true
title: Deploy Seata Server By Kubernetes title: Deploy Seata Server By Kubernetes
keywords: kubernetes,ops keywords: kubernetes,ops
description: Deploy Seata Server By Kubernetes description: Deploy Seata Server By Kubernetes

View File

@ -0,0 +1,7 @@
---
title: Seata integrates multiple data sources
keywords: multiple data sources,solutions
description: Seata integrates multiple data sources
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata integrates ShardingSphere
keywords: ShardingSphere,ShardingSphere,solutions
description: Seata integrates ShardingSphere
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Advanced use of TCC mode
keywords: TCC,TCC Mode,Advanced
description: Advanced use of TCC mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Integration use of TCC mode
keywords: TCC,TCC Mode,Integration
description: Integration use of TCC mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Quick start use of TCC mode
keywords: TCC,TCC Mode,Quick start
description: Quick start use of TCC mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Advanced use of XA mode
keywords: XA,XA Mode,Advanced
description: Advanced use of XA mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Integration use of XA mode
keywords: XA,XA Mode,Integration
description: Integration use of XA mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Quick start use of XA mode
keywords: XA,XA Mode,Quick start
description: Quick start use of XA mode
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: AT mode test report
keywords: AT,AT Mode,test report
description: AT mode test report
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Saga mode test report
keywords: Saga,Saga Mode,test report
description: Saga mode test report
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: TCC mode test report
keywords: TCC,TCC Mode,test report
description: TCC mode test report
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: XA mode test report
keywords: XA,XA Mode,test report
description: XA mode test report
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata version upgrade Guide
keywords: version upgrade,upgrade Guide
description: Seata version upgrade Guide
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Prometheus Metrics Configuration Guide
keywords: Seata,Prometheus,APM
description: Seata supports starting metrics data acquisition in TC and outputting it to Prometheus monitoring system
---
Welcome to claim this document

View File

@ -4,4 +4,4 @@ keywords: Seata, Metrics
description: Seata Metrics. description: Seata Metrics.
--- ---
TODO : Should be translated from docs/zh-cn/dev/architecture/seata_mertics.md Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: SkyWalking APM
keywords: Seata,APM,SkyWalking
description: SkyWalking APMApplication performance monitoring
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Apollo Configuration center
keywords: Seata,Apollo,Configuration center
description: Apollo Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Consul Configuration center
keywords: Seata,Consul,Configuration center
description: Consul Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Etcd3 Configuration center
keywords: Seata,Etcd3,Configuration center
description: Etcd3 Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: file Configuration center
keywords: Seata,file,Configuration center
description: file Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Configuration center
keywords: Seata,Configuration center
description: Seata Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Nacos Configuration center
keywords: Seata,Nacos,Configuration center
description: Nacos Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Zookeeper Configuration center
keywords: Seata,Zookeeper,Configuration center
description: Zookeeper Configuration center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata parameter configuration
keywords: Seata
description: Seata parameter configuration
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata parameter configuration 0.9.0 version
keywords: Seata
description: Seata parameter configuration 0.9.0 version
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata parameter configuration 1.0.0 version
keywords: Seata
description: Seata parameter configuration 1.0.0 version
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Transaction status
keywords: Transaction status
description: Global transaction status、branch transaction status
---
Welcome to claim this document

View File

@ -1,149 +0,0 @@
---
title: Microservice Framework Guide
keywords: Seata
description: Microservice Framework Guide.
---
# Transaction Context
Transaction context of Seata is managed by RootContext.
When application begins a global transaction, RootContext will bind the XID of the transaction automatically, at the end of transaction(commit or rollback), RootContext will unbind the XID automatically.
```java
// Bind XID
RootContext.bind(xid);
// Unbind XID
String xid = RootContext.unbind();
```
Application retrieve the global transaction XID through the API of RootContext.
```java
// Retrieve XID
String xid = RootContext.getXID();
```
Whether application is running a global transaction, just check if an XID bound to RootContext.
```java
public static boolean inGlobalTransaction() {
return CONTEXT_HOLDER.get(KEY_XID) != null;
}
```
# Transaction propagation
The mechanism of the global transaction of Seata is the propagation of transaction context, primarily, it's the propagation way of XID in runtime.
*1. The propagation of transaction in the service*
By default, RootContext is based on ThreadLocal, which is the XID is bound in the context of thread.
```java
public class ThreadLocalContextCore implements ContextCore {
private ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<Map<String, String>>() {
@Override
protected Map<String, String> initialValue() {
return new HashMap<String, String>();
}
};
@Override
public String put(String key, String value) {
return threadLocal.get().put(key, value);
}
@Override
public String get(String key) {
return threadLocal.get().get(key);
}
@Override
public String remove(String key) {
return threadLocal.get().remove(key);
}
}
```
So the inner XID of service is tracing by the same thread naturally, do nothing to propagate the transaction by default.
If it hopes to hung up the transaction context, implement it by the API of RootContext:
```java
// Hung up(pause)
String xid = RootContext.unbind();
// TODO: Logic running out of the global transaction scope
// recover the global transaction
RootContext.bind(xid);
```
*2. Transactional propagation across service calls*
It's easy to know by the basic idea preceding:
> The transaction propagation across service calls, essentially, propagate the XID via service call to service provider, and bind it to RootContext.
As long as it can be done, Seata can support any microservice framework in theory.
# Interpretation of supporting Dubbo
Let's interpret the inner support for Dubbo RPC to illustrate how Seata supports a specific microservice framework in follows:
We use the org.apache.dubbo.rpc.Filter of Dubbo to support propagation of transaction.
```java
/**
* The type Transaction propagation filter.
*/
@Activate(group = { Constants.PROVIDER, Constants.CONSUMER }, order = 100)
public class TransactionPropagationFilter implements Filter {
private static final Logger LOGGER = LoggerFactory.getLogger(TransactionPropagationFilter.class);
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
String xid = RootContext.getXID(); // Get XID of current transaction
String rpcXid = RpcContext.getContext().getAttachment(RootContext.KEY_XID); // Acquire the XID from RPC invoke
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("xid in RootContext[" + xid + "] xid in RpcContext[" + rpcXid + "]");
}
boolean bind = false;
if (xid != null) { // ConsumerPut XID into the attachment of RPC
RpcContext.getContext().setAttachment(RootContext.KEY_XID, xid);
} else {
if (rpcXid != null) { // ProviderBind the XID propagated by RPC to current runtime
RootContext.bind(rpcXid);
bind = true;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("bind[" + rpcXid + "] to RootContext");
}
}
}
try {
return invoker.invoke(invocation); // Business method invoke
} finally {
if (bind) { // ProviderClean up XID after invoke
String unbindXid = RootContext.unbind();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("unbind[" + unbindXid + "] from RootContext");
}
if (!rpcXid.equalsIgnoreCase(unbindXid)) {
LOGGER.warn("xid in change during RPC from " + rpcXid + " to " + unbindXid);
if (unbindXid != null) { // if there is new transaction begin, can't do clean up
RootContext.bind(unbindXid);
LOGGER.warn("bind [" + unbindXid + "] back to RootContext");
}
}
}
}
}
}
```

View File

@ -0,0 +1,7 @@
---
title: Seata Open-API
keywords: Seata,Open-API
description: Seata Open-API
---
Welcome to claim this document

View File

@ -1,225 +0,0 @@
---
title: Quick Start
keywords: Seata
description: Let's begin with a Microservices example.
---
# Quick Start
Let's begin with a Microservices example.
## Use case
A business logic for user purchasing commodities. The whole business logic is powered by 3 microservices:
- Storage service: deduct storage count on given commodity.
- Order service: create order according to purchase request.
- Account service: debit the balance of user's account.
### Architecture
![Architecture](/img/architecture.png)
### StorageService
```java
public interface StorageService {
/**
* deduct storage count
*/
void deduct(String commodityCode, int count);
}
```
### OrderService
```java
public interface OrderService {
/**
* create order
*/
Order create(String userId, String commodityCode, int orderCount);
}
```
### AccountService
```java
public interface AccountService {
/**
* debit balance of user's account
*/
void debit(String userId, int money);
}
```
### Main business logic
```java
public class BusinessServiceImpl implements BusinessService {
private StorageService storageService;
private OrderService orderService;
/**
* purchase
*/
public void purchase(String userId, String commodityCode, int orderCount) {
storageService.deduct(commodityCode, orderCount);
orderService.create(userId, commodityCode, orderCount);
}
}
```
```java
public class OrderServiceImpl implements OrderService {
private OrderDAO orderDAO;
private AccountService accountService;
public Order create(String userId, String commodityCode, int orderCount) {
int orderMoney = calculate(commodityCode, orderCount);
accountService.debit(userId, orderMoney);
Order order = new Order();
order.userId = userId;
order.commodityCode = commodityCode;
order.count = orderCount;
order.money = orderMoney;
// INSERT INTO orders ...
return orderDAO.insert(order);
}
}
```
## Distributed Transaction Solution with SEATA
![](/img/solution.png)
We just need an annotation `@GlobalTransactional` on business method:
```java
@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
......
}
```
## Example powered by Dubbo + SEATA
### Step 1: Setup database
- Requirement: MySQL with InnoDB engine.
**Note:** In fact, there should be 3 database for the 3 services in the example use case. However, we can just create one database and configure 3 data sources for simple.
Modify Spring XML with the database URL/username/password you just created.
dubbo-account-service.xml
dubbo-order-service.xml
dubbo-storage-service.xml
```xml
<property name="url" value="jdbc:mysql://x.x.x.x:3306/xxx" />
<property name="username" value="xxx" />
<property name="password" value="xxx" />
```
### Step 2: Create UNDO_LOG table
`UNDO_LOG` table is required by SEATA AT mode.
```sql
-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
```
### Step 3: Create tables for example business
```sql
DROP TABLE IF EXISTS `storage_tbl`;
CREATE TABLE `storage_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`commodity_code` varchar(255) DEFAULT NULL,
`count` int(11) DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY (`commodity_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `order_tbl`;
CREATE TABLE `order_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) DEFAULT NULL,
`commodity_code` varchar(255) DEFAULT NULL,
`count` int(11) DEFAULT 0,
`money` int(11) DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `account_tbl`;
CREATE TABLE `account_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(255) DEFAULT NULL,
`money` int(11) DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```
### Step 4: Start Server
- Download server package from <https://github.com/seata/seata/releases>, unzip it.
```shell
Usage: sh seata-server.sh(for linux and mac) or cmd seata-server.bat(for windows) [options]
Options:
--host, -h
The address is expose to registration center and other service can access seata-server via this ip.
Default: 0.0.0.0
--port, -p
The port to listen.
Default: 8091
--storeMode, -m
log store mode : file、db
Default: file
--help
e.g.
sh seata-server.sh -p 8091 -h 127.0.0.1 -m file
```
### Step 5: Run example
Go to samples repo: [seata-samples](https://github.com/seata/seata-samples)
- Start DubboAccountServiceStarter
- Start DubboStorageServiceStarter
- Start DubboOrderServiceStarter
- Run DubboBusinessTester for demo test
TBD: scripts for run demo applications

View File

@ -0,0 +1,7 @@
---
title: Consul Registration Center
keywords: Seata,Consul,Registration Center
description: Consul Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Etcd3 Registration Center
keywords: Seata,Etcd3,Registration Center
description: Etcd3 Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Eureka Registration Center
keywords: Seata,Eureka,Registration Center
description: Eureka Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: file Registration Center
keywords: Seata,file,Registration Center
description: file Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Registration Center
keywords: Seata,Registration Center
description: Seata Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Nacos注册中心
keywords: Seata,Nacos,注册中心
description: Nacos注册中心
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: redis注册中心
keywords: Seata,redis,注册中心
description: redis注册中心
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: sofa Registration Center
keywords: Seata,sofa,Registration Center
description: sofa Registration Center
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Zookeeper Registration Center
keywords: Seata,Zookeeper,Registration Center
description: Zookeeper Registration Center
---
Welcome to claim this document

7
docs/en-us/user/spi.md Normal file
View File

@ -0,0 +1,7 @@
---
title: Seata SPI
keywords: Seata,SPI
description: Seata SPI
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: DML statement
keywords: Seata
description: Seata DML statement
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: function
keywords: Seata
description: Seata function
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: sql decoration
keywords: Seata
description: sql decoration
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: sql restrictions
keywords: Seata
description: sql restrictions
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: transaction group best practice
keywords: Seata
description: Seata transaction group best practice
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata transaction group
keywords: Seata
description: Seata transaction group
---
Welcome to claim this document

View File

@ -0,0 +1,7 @@
---
title: Seata架构
keywords: 架构
description: 介绍Seata的逻辑架构了解Seata TC、TM、RM他们各自的职责和工作方式
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: 事务模式概述
keywords: 事务模式
description: 介绍Seata四种事务模式介绍各事务模式适用场景优缺点
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: 事务与分布式事务
keywords: 事务,分布式事务
description: 介绍事务ACID特性及主流的分布式事务解决方案和理论
---
欢迎认领此文档

View File

@ -1,68 +0,0 @@
---
title: Seata Saga 模式
keywords: Seata
description: Saga模式是SEATA提供的长事务解决方案在Saga模式中业务流程中每个参与者都提交本地事务当出现某一个参与者失败则补偿前面已经成功的参与者一阶段正向服务和二阶段补偿服务都由业务开发实现。
---
# SEATA Saga 模式
## 概述
Saga模式是SEATA提供的长事务解决方案在Saga模式中业务流程中每个参与者都提交本地事务当出现某一个参与者失败则补偿前面已经成功的参与者一阶段正向服务和二阶段补偿服务都由业务开发实现。
![Saga模式示意图](https://img.alicdn.com/tfs/TB1Y2kuw7T2gK0jSZFkXXcIQFXa-445-444.png)
理论基础Hector & Kenneth 发表论⽂ Sagas 1987
## Saga的实现
### 基于状态机引擎的 Saga 实现:
目前SEATA提供的Saga模式是基于状态机引擎来实现的机制是
1. 通过状态图来定义服务调用的流程并生成 json 状态语言定义文件
2. 状态图中一个节点可以是调用一个服务,节点可以配置它的补偿节点
3. 状态图 json 由状态机引擎驱动执行,当出现异常时状态引擎反向执行已成功节点对应的补偿节点将事务回滚
> 注意: 异常发生时是否进行补偿也可由用户自定义决定
4. 可以实现服务编排需求,支持单项选择、并发、子流程、参数转换、参数映射、服务执行状态判断、异常捕获等功能
示例状态图:
![示例状态图](/img/saga/demo_statelang.png?raw=true)
## 设计
### 状态机引擎原理:
![状态机引擎原理](/img/saga/saga_engine_mechanism.png?raw=true)
* 图中的状态图是先执行stateA, 再执行stateB然后执行stateC
* "状态"的执行是基于事件驱动的模型stateA执行完成后会产生路由消息放入EventQueue事件消费端从EventQueue取出消息执行stateB
* 在整个状态机启动时会调用Seata Server开启分布式事务并生产xid, 然后记录"状态机实例"启动事件到本地数据库
* 当执行到一个"状态"时会调用Seata Server注册分支事务并生产branchId, 然后记录"状态实例"开始执行事件到本地数据库
* 当一个"状态"执行完成后会记录"状态实例"执行结束事件到本地数据库, 然后调用Seata Server上报分支事务的状态
* 当整个状态机执行完成, 会记录"状态机实例"执行完成事件到本地数据库, 然后调用Seata Server提交或回滚分布式事务
### 状态机引擎设计:
![状态机引擎设计](/img/saga/saga_engine.png?raw=true)
状态机引擎的设计主要分成三层, 上层依赖下层,从下往上分别是:
* Eventing 层:
* 实现事件驱动架构, 可以压入事件, 并由消费端消费事件, 本层不关心事件是什么消费端执行什么,由上层实现
* ProcessController 层:
* 由于上层的Eventing驱动一个“空”流程引擎的执行"state"的行为和路由都未实现, 由上层实现
> 基于以上两层理论上可以自定义扩展任何"流程"引擎
* StateMachineEngine 层:
* 实现状态机引擎每种state的行为和路由逻辑
* 提供 API、状态机语言仓库
### 状态机的高可用设计:
![状态机的高可用](/img/saga/SagaEngineHA.png?raw=true)
状态机引擎是无状态的,它是内嵌在应用中。
当应用正常运行时(图中上半部分):
* 状态机引擎会上报状态到Seata Server
* 状态机执行日志存储在业务的数据库中;
当一台应用实例宕机时(图中下半部分):
* Seata Server 会感知到,并发送事务恢复请求到还存活的应用实例;
* 状态机引擎收到事务恢复请求后,从数据库里装载日志,并恢复状态机上下文继续执行;

View File

@ -1,7 +0,0 @@
---
title: 配置中心初始化
keywords: Seata
description: 配置中心初始化。
---
# 配置中心初始化

View File

@ -1,170 +0,0 @@
---
title: Seata部署指南
keywords: Seata
description: Seata分TC、TM和RM三个角色TCServer端为单独服务端部署TM和RMClient端由业务系统集成。
---
# 部署指南
## Seata新手部署指南(1.4.0版本)
Seata分TC、TM和RM三个角色TCServer端为单独服务端部署TM和RMClient端由业务系统集成。
### 资源目录介绍
#### <a href="https://github.com/seata/seata/tree/1.4.0/script" target="_blank">点击查看</a>
- client
> 存放client端sql脚本 (包含 undo_log表) ,参数配置
- config-center
> 各个配置中心参数导入脚本config.txt(包含server和client原名nacos-config.txt)为通用参数文件
- server
> server端数据库脚本 (包含 lock_table、branch_table 与 global_table) 及各个容器配置
### 注意事项
- seata-spring-boot-starter
```
内置GlobalTransactionScanner自动初始化功能若外部实现初始化请参考SeataAutoConfiguration保证依赖加载顺序
默认开启数据源自动代理可配置seata.enable-auto-data-source-proxy: false关闭
```
- spring-cloud-starter-alibaba-seata
> <a href="https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E" target="_blank">查看版本说明</a>
> 2.1.0内嵌seata-all 0.7.12.1.1内嵌seata-all 0.9.02.2.0内嵌seata-spring-boot-starter 1.0.0, 2.2.1内嵌seata-spring-boot-starter 1.1.0
```
2.1.0和2.1.1兼容starter解决方案:
@SpringBootApplication注解内exclude掉spring-cloud-starter-alibaba-seata内的com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration
```
- spring-cloud-starter-alibaba-seata推荐依赖配置方式
```java
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>最新版</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2.2.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
```
### 启动Server
Server端存储模式store.mode现有file、db、redis三种后续将引入raft,mongodbfile模式无需改动直接启动即可下面专门讲下db和redis启动步骤。
注: file模式为单机模式全局事务会话信息内存中读写并持久化本地文件root.data性能较高;
db模式为高可用模式全局事务会话信息通过db共享相应性能差些;
redis模式Seata-Server 1.3及以上版本支持,性能较高,存在事务信息丢失风险,请提前配置合适当前场景的redis持久化配置.
#### 步骤一:启动包
- <a href="https://github.com/seata/seata/releases" target="_blank">点击下载</a>
- 官方钉钉群群号231711671群5000人已满<a href="http://seata.io/zh-cn/community/index.html" target="_blank">2群</a>, 3群: 32033786qq群群号: 254657148,2群: 216012363群文件共享下载
#### 步骤二:建表(仅db)
全局事务会话信息由3块内容构成全局事务-->分支事务-->全局锁对应表global_table、branch_table、lock_table
#### 步骤三修改store.mode
启动包: seata-->conf-->file.conf修改store.mode="db或者redis"
源码: 根目录-->seata-server-->resources-->file.conf修改store.mode="db或者redis"
#### 步骤四:修改数据库连接|redis属性配置
启动包: seata-->conf-->file.conf修改store.db或store.redis相关属性。
源码: 根目录-->seata-server-->resources-->file.conf修改store.db或store.redis相关属性。
#### 步骤五:启动
- 源码启动: 执行Server.java的main方法
- 命令启动: seata-server.sh -h 127.0.0.1 -p 8091 -m db -n 1 -e test
```
-h: 注册到注册中心的ip
-p: Server rpc 监听端口
-m: 全局事务会话信息存储模式file、db、redis优先读取启动参数 (Seata-Server 1.3及以上版本支持redis)
-n: Server node多个Server时需区分各自节点用于生成不同区间的transactionId以免冲突
-e: 多环境配置参考 http://seata.io/en-us/docs/ops/multi-configuration-isolation.html
```
- <a href="https://seata.io/zh-cn/docs/ops/deploy-by-docker.html" target="_blank">点击查看docker部署</a>
注: 堆内存建议分配2G堆外内存1G
### 业务系统集成Client
#### 步骤一添加seata依赖建议单选
- 依赖seata-all
- 依赖seata-spring-boot-starter支持yml、properties配置(.conf可删除)内部已依赖seata-all
- 依赖spring-cloud-alibaba-seata内部集成了seata并实现了xid传递
#### 步骤二undo_log建表、配置参数
- <a href="https://seata.io/zh-cn/docs/user/configurations.html" target="_blank">查看参数配置介绍</a>
#### 步骤三:数据源代理(不支持自动和手动配置并存)
1. 如果使用seata-all
- 0.9.0版本开始seata支持自动代理数据源
```
1.1.0: seata-all取消属性配置改由注解@EnableAutoDataSourceProxy开启并可选择jdk proxy或者cglib proxy
1.0.0: client.support.spring.datasource.autoproxy=true
0.9.0: support.spring.datasource.autoproxy=true
```
如果采用XA模式`@EnableAutoDataSourceProxy(dataSourceProxyMode = "XA")`
- 手动配置可参考下方的例子
```
@Primary
@Bean("dataSource")
public DataSource dataSource(DataSource druidDataSource) {
//AT 代理 二选一
return new DataSourceProxy(druidDataSource);
//XA 代理
return new DataSourceProxyXA(druidDataSource)
}
```
2. 如果使用seata-starter
- 使用自动代理数据源时如果使用XA模式还需要调整配置文件
application.properties
```
seata.data-source-proxy-mode=XA
```
application.yml
```
seata:
data-source-proxy-mode: XA
```
- 如何关闭seata-spring-boot-starter的数据源自动代理
application.properties
```
seata.enable-auto-data-source-proxy=false
```
application.yml
```
seata:
enable-auto-data-source-proxy: false
```
#### 步骤四初始化GlobalTransactionScanner
- 手动
``` @Bean
@Bean
public GlobalTransactionScanner globalTransactionScanner() {
String applicationName = this.applicationContext.getEnvironment().getProperty("spring.application.name");
String txServiceGroup = this.seataProperties.getTxServiceGroup();
if (StringUtils.isEmpty(txServiceGroup)) {
txServiceGroup = applicationName + "-fescar-service-group";
this.seataProperties.setTxServiceGroup(txServiceGroup);
}
return new GlobalTransactionScanner(applicationName, txServiceGroup);
}
```
- 自动引入seata-spring-boot-starter、spring-cloud-starter-alibaba-seata等jar
#### 步骤五实现xid跨服务传递
- 手动
参考源码integration文件夹下的各种rpc实现 module
- 自动
springCloud用户可以引入spring-cloud-starter-alibaba-seata内部已经实现xid传递

View File

@ -1,156 +0,0 @@
---
hidden: true
title: Seata 高可用部署
keywords: kubernetes,ops
description: Seata 高可用部署
author: helloworlde
date: 2020-04-10
---
# Seata 高可用部署
> Seata 的高可用依赖于注册中心、配置中心和数据库来实现
## Seata-Server
Seata-Server 需要使用注册中心,并把事务数据保存到数据库中,以 Nacos 为例
- 修改`registry.conf`的注册中心配置
```
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.199.2"
namespace = ""
cluster = "default"
username = ""
password = ""
}
}
config {
type = "nacos"
nacos {
serverAddr = "192.168.199.2"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
}
```
- 需要修改配置中心的以下几个配置(含db与redis,二者选其一 注:redis需seata-server 1.3版本及以上)
```
service.vgroupMapping.my_test_tx_group=default
store.mode=db|redis
-----db-----
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=root
store.db.password=123456
----redis----
store.redis.host=127.0.0.1
store.redis.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.database=0
store.redis.password=null
store.redis.queryLimit=100
```
- db模式需要在数据库创建 `global_table`, `branch_table`, `lock_table`
相应的脚本在GitHub 的 [/script/server/db/](https://github.com/seata/seata/tree/develop/script/server/db) 目录下
这样启动多个seata-server即可实现其高可用
----
以 Kubernetes 为例,部署文件参考:
```yaml
apiVersion: v1
kind: Service
metadata:
name: seata-ha-server
namespace: default
labels:
app.kubernetes.io/name: seata-ha-server
spec:
type: ClusterIP
ports:
- port: 8091
protocol: TCP
name: http
selector:
app.kubernetes.io/name: seata-ha-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: seata-ha-server
namespace: default
labels:
app.kubernetes.io/name: seata-ha-server
spec:
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: seata-ha-server
template:
metadata:
labels:
app.kubernetes.io/name: seata-ha-server
spec:
containers:
- name: seata-ha-server
image: docker.io/seataio/seata-server:latest
imagePullPolicy: IfNotPresent
env:
- name: SEATA_CONFIG_NAME
value: file:/root/seata-config/registry
ports:
- name: http
containerPort: 8091
protocol: TCP
volumeMounts:
- name: seata-config
mountPath: /root/seata-config
volumes:
- name: seata-config
configMap:
name: seata-ha-server-config
---
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-ha-server-config
data:
registry.conf: |
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.199.2"
}
}
config {
type = "nacos"
nacos {
serverAddr = "192.168.199.2"
group = "SEATA_GROUP"
}
}
```

View File

@ -0,0 +1,7 @@
---
title: RoadMap
keywords: RoadMap
description: Seata roadmap
---
欢迎认领此文档

View File

@ -1,16 +0,0 @@
---
title: Seata术语
keywords: Seata
description: Seata术语。
---
# Seata术语
#### TC (Transaction Coordinator) - 事务协调者
维护全局和分支事务的状态,驱动全局事务提交或回滚。
#### TM (Transaction Manager) - 事务管理器
定义全局事务的范围:开始全局事务、提交或回滚全局事务。
#### RM (Resource Manager) - 资源管理器
管理分支事务处理的资源与TC交谈以注册分支事务和报告分支事务的状态并驱动分支事务提交或回滚。

View File

@ -1,5 +1,5 @@
--- ---
title: Seata 是什么 title: Seata简介
keywords: Seata keywords: Seata
description: Seata 是一款开源的分布式事务解决方案致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案。 description: Seata 是一款开源的分布式事务解决方案致力于提供高性能和简单易用的分布式事务服务。Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案。
--- ---

View File

@ -0,0 +1,7 @@
---
title: AT模式进阶使用
keywords: AT,AT模式,进阶使用
description: 介绍AT模式的一些进阶用法
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: AT模式框架集成
keywords: AT,AT模式,框架集成
description: 介绍AT模式与热门框架的集成方案
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: AT模式快速入门
keywords: AT,AT模式,快速入门
description: AT模式快速入门
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: Saga模式进阶使用
keywords: Saga,Saga模式,进阶使用
description: Saga模式进阶使用
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: Saga模式框架集成
keywords: Saga,Saga模式,框架集成
description: Saga模式框架集成
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: Saga模式快速入门
keywords: Saga,Saga模式,快速入门
description: Saga模式快速入门
---
欢迎认领此文档

View File

@ -24,7 +24,7 @@ $ helm install seata-server ./seata-server
### 环境变量 ### 环境变量
支持的环境变量和 Docker 相同,可以参考 [使用 Docker 部署 Seata Server](./deploy-by-docker.md) 支持的环境变量和 Docker 相同,可以参考 [使用 Docker 部署 Seata Server](docs/zh-cn/quickstart/server-deploy/deploy-by-docker.md/server-deploy/deploy-by-docker.md)

View File

@ -77,7 +77,7 @@ $ kubectl apply -f seata-server.yaml
### 环境变量 ### 环境变量
支持的环境变量和 Docker 相同,可以参考 [使用 Docker 部署 Seata Server](./deploy-by-docker.md) 支持的环境变量和 Docker 相同,可以参考 [使用 Docker 部署 Seata Server](docs/zh-cn/quickstart/server-deploy/deploy-by-docker.md/server-deploy/deploy-by-docker.md)

View File

@ -48,8 +48,8 @@ $ sh ./bin/seata-server.sh -p 8091 -h 127.0.0.1 -m file
容器部署当前支持三种方式: 容器部署当前支持三种方式:
- [使用 Docker / Docker Compose 部署 ](./deploy-by-docker.md) - [使用 Docker / Docker Compose 部署 ](docs/zh-cn/quickstart/server-deploy/deploy-by-docker.md/server-deploy/deploy-by-docker.md)
- [使用 Kubernetes 部署 ](./deploy-by-kubernetes.md) - [使用 Kubernetes 部署 ](docs/zh-cn/quickstart/server-deploy/deploy-by-kubernetes.mdver-deploy/deploy-by-kubernetes.md)
- [使用 Helm 部署](./deploy-by-helm.md) - [使用 Helm 部署](docs/zh-cn/quickstart/server-deploy/deploy-by-helm.mdrt/server-deploy/deploy-by-helm.md)

View File

@ -0,0 +1,7 @@
---
title: Seata集成多数据源
keywords: 多数据源,常见解决方案
description: 介绍多数据源的解决方案
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: 分库分表集成ShardingSphere
keywords: ShardingSphere,分库分表,常见解决方案
description: 介绍分库分表的解决方案
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: TCC进阶使用
keywords: TCC,TCC模式,进阶使用
description: TCC进阶使用
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: TCC框架集成
keywords: TCC,TCC模式,框架集成
description: TCC框架集成
---
欢迎认领此文档

View File

@ -0,0 +1,7 @@
---
title: TCC快速入门
keywords: TCC,TCC模式,快速入门
description: TCC快速入门
---
欢迎认领此文档

Some files were not shown because too many files have changed in this diff Show More