I. AT Mode Overview
AT (Automatic Transaction) mode is the most commonly used distributed transaction pattern in Seata. It achieves transaction rollback by automatically generating reverse SQL, with minimal intrusion into business code.
II. Core Configuration Details
1. Global Configuration (registry.conf)
# Registry center configuration
registry {
type = "nacos" # Supports nacos, eureka, redis, zk, consul, etcd3, sofa
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
}
# Configuration center
config {
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
dataId = "seata-server.properties"
}
}
2. Client Configuration (application.yml)
seata:
enabled: true
application-id: order-service # Unique application identifier
tx-service-group: my_test_tx_group # Transaction group name
# Auto data-source proxy
enable-auto-data-source-proxy: true
data-source-proxy-mode: AT # AT mode
# Client configuration
config:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: ""
data-id: seata-client.properties
# Registry center configuration
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: ""
cluster: default
# Detailed client configuration
client:
rm:
# Async commit buffer queue length
async-commit-buffer-limit: 10000
# Retry count for reporting phase-1 result to TC
report-retry-count: 5
# Auto refresh table schema in cache
table-meta-check-enable: true
# Lock strategy when branch transaction conflicts with other global rollback transactions
report-success-enable: false
# Whether to report phase-1 success
saga-branch-register-enable: false
# saga json parser
saga-json-parser: fastjson
# Retry count for reporting phase-1 global commit result to TC
saga-retry-persist-mode-update: false
# Default false, true improves performance
saga-compensate-persist-mode-update: false
# TCC resource auto cleanup time (hours)
tcc-action-interceptor-order: -2147482648
tm:
# Retry count for reporting phase-1 global commit result to TC
commit-retry-count: 5
# Retry count for reporting phase-1 global rollback result to TC
rollback-retry-count: 5
# Default global transaction timeout (ms)
default-global-transaction-timeout: 60000
# Degrade switch, default false
degrade-check: false
# Service self-check period (ms)
degrade-check-period: 2000
# Minimum concurrent business count allowed for degrade check
degrade-check-allow-times: 10
# Duration to keep degrade open after self-check failure (ms)
interceptor-order: -2147482648
undo:
# Whether to enable phase-2 rollback image validation
data-validation: true
# Handling method when phase-2 rollback image validation fails
log-serialization: jackson
# undo serialization method: jackson, fastjson, kryo
log-table: undo_log
# Custom undo table name
only-care-update-columns: true
# Whether to generate images only for updated columns
compress:
enable: true
# Whether to compress undo_log
type: zip
# Compression type
threshold: 64k
# Compression threshold
# Load balancing configuration
load-balance:
type: RandomLoadBalance # Load balance type
virtual-nodes: 10 # Virtual node count
3. Server-side Configuration (Seata Server)
# Storage mode
store.mode=db # file, db, redis
# Database storage configuration
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useSSL=false
store.db.user=root
store.db.password=root
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
# Transaction, log storage configuration
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
III. Usage Example
1. Database Preparation
Each business database needs to create an undo_log table:
CodeBlock Loading...
2. Business Code
CodeBlock Loading...
IV. Underlying Implementation Principles
1. Core Component Architecture
CodeBlock Loading...
2. AT Mode Execution Flow
Phase One (Execute Business SQL)
CodeBlock Loading...
Core Data Structures
CodeBlock Loading...
Phase Two (Commit or Rollback)
Commit flow:
CodeBlock Loading...
Rollback flow:
CodeBlock Loading...
Reverse SQL Generation Logic
CodeBlock Loading...
3. Global Lock Mechanism
CodeBlock Loading...
V. Performance Optimization Configuration
CodeBlock Loading...
VI. Common Issues
- Dirty write problem: Solved by global locks and data validation
- Performance issues: Use async commit and undo_log compression
- undo_log bloat: Periodically clean historical data
CodeBlock Loading...
AT mode achieves a zero-intrusion distributed transaction solution for business code by automatically generating before/after images and reverse SQL, and is the most recommended mode in Seata.