incubator-seata-go
incubator-seata-go copied to clipboard
feature add fence for tcc, and add fence sample in tcc local mod.
this pr will close #139 and #140
在Golang中由于没有诸如spring这样的容器框架,因此在一些功能实现上必然会有别于seata-java版本的,如TCC 防悬挂实现中我想到了两种实现方式,它们分别如下:
1,本pr提供了fence.WithFence接口作为防悬挂的一种使用方式,接口的详情如下:
fence.WithFence(ctx, tx, business func() error), 其中用户只需要将业务方法prepare等作为参数调用WithFence即可使用防悬挂功能。该方式已在本pr中实现,其优点如下:
以分支事务为细粒度启用防悬挂:在防悬挂中会涉及到数据库操作,因此是一项牺牲性能来保证安全性的措施,特别例如rollback fence中还会使用for update来进行锁操作,效率是非常低的,在seata-java中只要配置了USE_TCC_FENCE配置参数,一个全局事务的每个分支事务都会进行防悬挂的数据库操作,用户不能根据自己的想法定义某些分支事务启用防悬挂操作。而WithFence接口可以很好得解决这一点,用户可以自行选择哪个分支事务使用该接口(即代表开启防悬挂)。这样一来便能让以性能标榜的TCC模式在开启防悬挂后性能不会下降太多。
seata-go:
seata-java:

2,使用feature/datasource_at中数据源代理的方式在开启事务结束事务的代理流程中完成防悬挂操作 。本方案暂未实现
其中两种方式在使用过程中 WithFence对用户业务有些许侵入,但是可以优化防悬挂的使用细粒度,数据源代理的实现方式在使用过程中也会有些许侵入,但是相较于WithFence会好一点,不过该方式在防悬挂的使用细粒度而言是不如WithFence接口的。
考虑到seata-go是以SDK形式提供给用户使用的,因此我认为两种方式都可以实现,将使用的决定权交给用户,让用户来权衡侵入性与性能的利弊。
I don't know much about golang,there are something have to be aware of.
- All pre、commit、rollback need to be completed in one transaction.
- Each resource could has a unique configuration of fence. If we have done these things, please ignore.
I don't know much about golang,there are something have to be aware of.
- All pre、commit、rollback need to be completed in one transaction.
- Each resource could has a unique configuration of fence. If we have done these things, please ignore.
I don't know much about golang,there are something have to be aware of.
- All pre、commit、rollback need to be completed in one transaction.
- Each resource could has a unique configuration of fence. If we have done these things, please ignore.
Well, Both have done
Codecov Report
Merging #191 (f7afc9a) into master (94225ea) will increase coverage by
0.07%. The diff coverage is54.89%.
@@ Coverage Diff @@
## master #191 +/- ##
==========================================
+ Coverage 50.99% 51.06% +0.07%
==========================================
Files 61 63 +2
Lines 3106 3276 +170
==========================================
+ Hits 1584 1673 +89
- Misses 1445 1512 +67
- Partials 77 91 +14
| Impacted Files | Coverage Δ | |
|---|---|---|
| pkg/protocol/message/response_message.go | 100.00% <ø> (ø) |
|
| pkg/rm/tcc/tcc_resource.go | 32.43% <0.00%> (-5.47%) |
:arrow_down: |
| pkg/rm/tcc/tcc_service.go | 70.80% <0.00%> (-0.45%) |
:arrow_down: |
| pkg/rm/tcc/fence/fence_api.go | 55.55% <55.55%> (ø) |
|
| pkg/rm/tcc/fence/store/db/dao/tcc_fence_db.go | 55.65% <55.65%> (ø) |
|
| pkg/tm/context.go | 79.34% <90.90%> (+1.57%) |
:arrow_up: |
| pkg/protocol/codec/branch_commit_response_codec.go | 91.42% <100.00%> (ø) |
|
| ...g/protocol/codec/branch_register_response_codec.go | 90.32% <100.00%> (ø) |
|
| ...g/protocol/codec/branch_rollback_response_codec.go | 91.42% <100.00%> (ø) |
|
| ...protocol/codec/common_global_end_response_codec.go | 88.88% <100.00%> (ø) |
|
| ... and 3 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.