技术标签: 分布式事务
SeaTa 是阿里开源的可供商用的分布式事务框架 前身Fescar , java程序
https://seata.io/zh-cn/docs/user/configurations.html
这些操作都需要一次远程通讯RPC,而且是同步的。另外undo log写入时blob字段的插入性能也是不高的。每条写SQL都会增加这么多开销,粗略估计会增加5倍响应时间(二阶段虽然是异步的,但其实也会占用系统资源,网络、线程、数据库)
## transaction log store, only used in seata-server
store {
## store mode: file、db 事务日志存储模式
mode = "db"
# 服务端配置
service {
# 分组名称 需要和client端一致 chuangqi-steata
vgroup_mapping.chuangqi-steata = "chuangqi-steata"
chuangqi-steata.grouplist = "127.0.0.1:8091"
# 降级开关 默认关闭
enableDegrade = false
disable = false
max.commit.retry.timeout = "-1"
max.rollback.retry.timeout = "-1"
}
## file store property
file {
## store location dir
dir = "sessionStore"
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
maxBranchSessionSize = 16384
# globe session size , if exceeded throws exceptions
maxGlobalSessionSize = 512
# file buffer size , if exceeded allocate new buffer
fileWriteBufferCacheSize = 16384
# when recover batch read size
sessionReloadReadSize = 100
# async, sync
flushDiskMode = async
}
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
datasource = "dbcp"
## mysql/oracle/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/seata"
user = "root"
password = "root"
minConn = 1
maxConn = 10
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "file"
nacos {
serverAddr = "localhost"
namespace = ""
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
nacos {
serverAddr = "localhost"
namespace = ""
group = "SEATA_GROUP"
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
app.id = "seata-server"
apollo.meta = "http://192.168.1.204:8801"
namespace = "application"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
seata/bin/seata-server.sh
nohup sh seata-server.sh -h xx.xx.xx.xx -p 8091 -m db -n 1 -e test &
-h: 注册到注册中心的ip
-p: Server rpc 监听端口
-m: 全局事务会话信息存储模式,file、db,优先读取启动参数
-n: Server node,多个Server时,需区分各自节点,用于生成不同区间的transactionId,以免冲突
-e: 多环境配置参考 http://seata.io/en-us/docs/ops/multi-configuration-isolation.html
seata:
enabled: true
application-id: account-api # 项目标识
tx-service-group: chuangqi-steat # seata分组名称
enable-auto-data-source-proxy: true # 开启数据源自动代理
use-jdk-proxy: false # 使用的代理方式
client:
rm:
async-commit-buffer-limit: 1000
report-retry-count: 5
table-meta-check-enable: false
report-success-enable: false
lock:
retry-interval: 10
retry-times: 30
retry-policy-branch-rollback-on-conflict: true
tm:
commit-retry-count: 5
rollback-retry-count: 5
undo:
data-validation: true
log-serialization: jackson
log-table: undo_log
log:
exceptionRate: 100
service:
vgroup-mapping:
my_test_tx_group: default
grouplist:
default: 127.0.0.1:8091
#enable-degrade: false
#disable-global-transaction: false
transport:
shutdown:
wait: 3
thread-factory:
boss-thread-prefix: NettyBoss
worker-thread-prefix: NettyServerNIOWorker
server-executor-thread-prefix: NettyServerBizHandler
share-boss-worker: false
client-selector-thread-prefix: NettyClientSelector
client-selector-thread-size: 1
client-worker-thread-prefix: NettyClientWorkerThread
worker-thread-size: default
boss-thread-size: 1
type: TCP
server: NIO
heartbeat: true
serialization: seata
compressor: none
enable-client-batch-send-request: true
config:
type: file
consul:
server-addr: 127.0.0.1:8500
apollo:
apollo-meta: http://192.168.1.204:8801
app-id: seata-server
namespace: application
etcd3:
server-addr: http://localhost:2379
nacos:
namespace:
serverAddr: localhost
group: SEATA_GROUP
zk:
server-addr: 127.0.0.1:2181
session-timeout: 6000
connect-timeout: 2000
username: ""
password: ""
registry:
type: file
consul:
cluster: default
server-addr: 127.0.0.1:8500
etcd3:
cluster: default
serverAddr: http://localhost:2379
eureka:
application: default
weight: 1
service-url: http://localhost:8761/eureka
nacos:
cluster: default
server-addr: localhost
namespace:
redis:
server-addr: localhost:6379
db: 0
password:
cluster: default
timeout: 0
sofa:
server-addr: 127.0.0.1:9603
application: default
region: DEFAULT_ZONE
datacenter: DefaultDataCenter
cluster: default
group: SEATA_GROUP
addressWaitTime: 3000
zk:
cluster: default
server-addr: 127.0.0.1:2181
session-timeout: 6000
connect-timeout: 2000
username: ""
password: ""
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
@Bean
@Autowired
public SqlSessionFactory sqlsessionfactory(HikariDataSource dataSource, Configuration configuration) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setPlugins(new Interceptor[]{new PageInterceptor()});
sqlSessionFactoryBean.setConfiguration(configuration);
return sqlSessionFactoryBean.getObject();
}
@Bean
@ConfigurationProperties(prefix = "spring.datasource.hikari")
public HikariDataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
@Primary
@Bean("dataSource")
public DataSourceProxy dataSource(DataSource druidDataSource){
return new DataSourceProxy(druidDataSource);
}
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);
}
1.写隔离
2.读隔离
# 分支事务的sql
update product set name = 'GTS' where name = 'TXC';
一阶段
{
"branchId": 641789253,
"undoItems": [{
"afterImage": {
"rows": [{
"fields": [{
"name": "id",
"type": 4,
"value": 1
}, {
"name": "name",
"type": 12,
"value": "GTS"
}, {
"name": "since",
"type": 12,
"value": "2014"
}]
}],
"tableName": "product"
},
"beforeImage": {
"rows": [{
"fields": [{
"name": "id",
"type": 4,
"value": 1
}, {
"name": "name",
"type": 12,
"value": "TXC"
}, {
"name": "since",
"type": 12,
"value": "2014"
}]
}],
"tableName": "product"
},
"sqlType": "UPDATE"
}],
"xid": "xid:xxx"
}
二阶段-回滚
update product set name = 'TXC' where id = 1;
二阶段-提交
3.3实现
文章浏览阅读2.1k次,点赞21次,收藏29次。[_sam-med2d
文章浏览阅读126次。深圳Java培训:Javaweb现在流行用什么框架?Java是开源的,框架很多,这些框架都能解决特定的问题,提高开发效率、简化我们的代码复杂度,现在除了很多大家通用的一些主流框架外,很多公司针对自己的业务会自定义一些公司内部的框架,当然作为学习者我们首先要清楚Javaweb都有哪些框架需要学习。回答这个问题首先要看我们的项目规模,对于”体量”较小的单应用项目,和需要处理海量数据、高并发的分布式..._深圳流行开发框架
文章浏览阅读107次。_云卷云舒任逍遥 博客
文章浏览阅读1.6k次。esp32 蓝牙播放mp3_esp32 蓝牙音频
文章浏览阅读797次,点赞24次,收藏27次。Map():创建一个空映射,返回空映射对象;put(key, val):将key‐val关联对加入映射中,如果key已存在,将val替换旧关联值;get(key):给定key,返回关联的数据值,如不存在,则返回None;del:通过del map[key]的语句形式删除key‐val关联;len():返回映射中key‐val关联的数目;in:通过key in map的语句形式,返回key是否存在于关联中,布尔值#我们用一个HashTable类来实现ADT Map,该类包含了两个列表作为成员。
文章浏览阅读440次。学习记录,打卡。卷起来! (-:
文章浏览阅读1.1k次。RSA的运用和前后端签名的一些看法RSA在验签过程的使用场景分析不按照上述方式验签会造成的问题日常前后端交互简化版的RSA应用分析RSA在验签过程的使用场景分析 RSA的文章有很多。原理性学术性的对于我这样普通的码农毫无意义,对于我来说,我只想知道为什么我们要用RSA,以及什么 情况下我们需要使用它?这是一篇粗浅且迅速入门的文章。首先,我要介绍RSA验签的流程,稍后再分析为啥要这样做。..._rsa puk pvk
文章浏览阅读230次。SpringMVC Ajax请求参数为json时的几个注意事项如果请求参数为json,请求时必须加上contentType:‘application/json;charset=UTF-8’① data写成标准json字符串格式*’{’‘name:“tom”,“age”:39}’*,key必须加引号,单引号/双引号均可,但必须得加,大括号外边也必须加上引号否则会报错,控制台会报错,报错如下警告 [http-nio-8082-exec-12] org.springframework.web.ser_ajax json请求对参数有要求吗
文章浏览阅读130次。数组函数一、数组操作的基本函数数组的键名和值array_values($arr); 获得数组的值array_keys($arr); 获得数组的键名array_flip($arr); 数组中的值与键名互换(如果有重复前面的会被后面的覆盖)in_array("apple",$arr); 在数组中检索applearray_search("apple",$arr); 在数组中检索apple ,如...
文章浏览阅读341次。1、改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"mysql-uroot-pvmwaremysql>usemysql;mysql>updateusersethost='%'w...
文章浏览阅读334次。python函数修饰符@的作用是为现有函数增加额外的功能,常用于插入日志、性能测试、事务处理等等。创建函数修饰符的规则:(1)修饰符是一个函数(2)修饰符取被修饰函数为参数(3)修饰符返回一个新函数(4)修饰符维护被维护函数的签名例子1:被修饰函数不带参数def log(func):def wrapper():print('log开始 ...')func()print('log结束 ...')re...
文章浏览阅读4.4k次。下载地址:https://download.csdn.net/download/u012443049/10556049_福州十三水源码下载