Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Integrating SEATA to support distributed transaction in TCC mode #1728

Merged
merged 18 commits into from
Sep 1, 2021
Merged

feature: Integrating SEATA to support distributed transaction in TCC mode #1728

merged 18 commits into from
Sep 1, 2021

Conversation

dk-lockdown
Copy link
Contributor

@dk-lockdown dk-lockdown commented Jul 15, 2021

Issues associated with this PR

集成 SEATA TCC 模式,初步实现 TransactionMesh,目前只支持 http1 协议

Solutions

TransactionManager:拦截请求,在请求开始之前,开启全局事务。在分支事务执行完毕,根据状态码,提交全局事务或回滚全局事务。
ResourceManager:拦截请求,在请求开始之前,向事务管理器注册事务分支。在分支事务执行完毕,根据状态码报告分支事务执行状态。

pkg/mosn/mosn.go Outdated Show resolved Hide resolved
pkg/config/v2/config.go Outdated Show resolved Hide resolved
@dk-lockdown
Copy link
Contributor Author

Kapture 2021-07-23 at 14 13 36
整个 transaction mesh 的原理如图所见,tc 会回调事务分支提交或回滚,所以需要在 mosn 上开一个端口

@nejisama nejisama modified the milestones: 0.24.0, 0.25.0 Jul 28, 2021
pkg/config/v2/filter.go Outdated Show resolved Hide resolved
pkg/config/v2/grpc.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 9, 2021

Codecov Report

Merging #1728 (3618c56) into master (8ea72ae) will decrease coverage by 0.06%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1728      +/-   ##
==========================================
- Coverage   60.98%   60.92%   -0.07%     
==========================================
  Files         380      380              
  Lines       33447    33450       +3     
==========================================
- Hits        20399    20380      -19     
- Misses      11064    11081      +17     
- Partials     1984     1989       +5     
Impacted Files Coverage Δ
pkg/config/v2/config.go 80.00% <ø> (ø)
pkg/config/v2/grpc.go 0.00% <ø> (ø)
pkg/configmanager/parser.go 65.04% <0.00%> (ø)
pkg/filter/stream/gzip/gzip.go 76.78% <ø> (ø)
pkg/filter/stream/jwtauthn/filter.go 54.16% <ø> (ø)
pkg/log/accesslog.go 81.81% <ø> (ø)
pkg/network/eventloop.go 14.28% <ø> (ø)
pkg/upstream/servicediscovery/dubbod/bootstrap.go 62.50% <ø> (-6.25%) ⬇️
pkg/upstream/servicediscovery/dubbod/common.go 85.71% <ø> (ø)
pkg/upstream/servicediscovery/dubbod/notify.go 94.73% <ø> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ea72ae...3618c56. Read the comment docs.

go.mod Outdated Show resolved Hide resolved
nejisama
nejisama previously approved these changes Aug 18, 2021
@nobodyiam
Copy link
Member

Is this feature appropriate in layotto? cc @zhenjunMa @seeflood

@seeflood
Copy link
Member

Is this feature appropriate in layotto? cc @zhenjunMa @seeflood

IMO,currently it might be inappropiate to integrate it as a runtime API in Layotto.

  1. TCC and SAGA patterns force users to change their programming model and must be implemented with a fat SDK, so it's more appropriate to make the SDK API vendor-neutral, not sidecar grpc API
  2. With this fat SDK,applications can communicate with transaction coordinator directly, and the sidecar seems not necessary.

I haven't read through this pr, and I'm curious in what scenarios does the user want to use TCC via a sidecar?

@dk-lockdown
Copy link
Contributor Author

Is this feature appropriate in layotto? cc @zhenjunMa @seeflood

IMO,currently it might be inappropiate to integrate it as a runtime API in Layotto.

  1. TCC and SAGA patterns force users to change their programming model and must be implemented with a fat SDK, so it's more appropriate to make the SDK API vendor-neutral, not sidecar grpc API
  2. With this fat SDK,applications can communicate with transaction coordinator directly, and the sidecar seems not necessary.

I haven't read through this pr, and I'm curious in what scenarios does the user want to use TCC via a sidecar?

这个 pr 拦截代理用户的请求,通过状态码判断是否提交回滚。通过在 sidecar 中集成 TCC,使那些没有 sdk 的语言,如 .net\node,用这些语言写的微服务也能使用 TCC 模式来协调分布式事务。整个过程要抽象成适合 layotto 的 grpc api 比较难,它更适合集成在 mosn 中。用户只需要写他的 TCC 接口,协调工作由 sidecar 完成。交互逻辑见上面贴的动图。

@seeflood
Copy link
Member

通过在 sidecar 中集成 TCC,使那些没有 sdk 的语言,如 .net\node,用这些语言写的微服务也能使用 TCC 模式来协调分布式事务

@dk-lockdown 噢噢,用户场景是让没有sdk的语言也能用TCC对吧?
我记得TCC要回调APP、给APP一个事务id让APP根据事务id调用commit和rollback的代码(如果我记错了还请指正),那么APP内部要有维护事务id和commit/rollback代码映射关系的逻辑,这个逻辑还是要写在sdk里吧?

@dk-lockdown
Copy link
Contributor Author

通过在 sidecar 中集成 TCC,使那些没有 sdk 的语言,如 .net\node,用这些语言写的微服务也能使用 TCC 模式来协调分布式事务

@dk-lockdown 噢噢,用户场景是让没有sdk的语言也能用TCC对吧?
我记得TCC要回调APP、给APP一个事务id让APP根据事务id调用commit和rollback的代码(如果我记错了还请指正),那么APP内部要有维护事务id和commit/rollback代码映射关系的逻辑,这个逻辑还是要写在sdk里吧?

这个是 TC 的工作,TM 发起全局事务提交或者回滚,TC 根据 xid 找到全局事务注册的所有事务分支,通知他们提交或者回滚。所以这个 pr 还需要一个 TC 事务协调器。只用 mosn sidecar 是不能解决分布式事务问题的。

Copy link
Contributor

@taoyuanyuan taoyuanyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@taoyuanyuan
Copy link
Contributor

thanks for your contribution!

@nejisama nejisama merged commit b481e09 into mosn:master Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants