Seadt: Financial Level Distributed Transaction Solution (III) - SAGA Design and Implementation
AD |
seadt Shopee Financial Products GolangTCCseadt TCCseadt TCCseadt-SAGAseadtTCCSAGASAGATCCSAGA1. SAGASAGASagasSAGASAGASAGA1 SAGAT C SAGA/SAGASAGA1
seadt Shopee Financial Products Golang
TCCseadt TCCseadt TCCseadt-SAGA
seadtTCCSAGASAGATCCSAGA
1. SAGA
SAGASagasSAGASAGASAGA
1 SAGA
T C SAGA/SAGASAGA
1.1 SAGA-
TCCSAGAATseadtTCCTCCSAGA
TCC | SAGA | |
& | ||
TryConfirmCancel | ||
TCC
SAGA
SAGASAGASAGASAGASAGASAGA
1.2 SAGA-
SAGASAGA
1.2.1
SAGADSLTCTCTCSAGA
2
- SAGA
- TMTCSAGA
- TCDSLQuotaA
- 3TCDSLQuotaASAGA
- 3TCDSLPromotionB
- 5TCDSLPromotionB4
- 5SAGA
import seadtfunc BizFunc() { sagaTxId := "BizTrans" seadt.StartSAGATx(ctx, seadt_name, req_id)}
// DSL{ "seadt_name":"BizTrans", "tx_seq":[ { "sub_tx_id": "UseQuota", "commit_method": "/Module_Name/UseQuota", "callback_method": "/Module_Name/UnUseQuota", "pre_step":"Start", "next_step":"UseCoupon" }, { "sub_tx_id": "UseCoupon", "commit_method": "/Module_Name/UseCoupon", "callback_method": "/Module_Name/UnUseCoupon", "pre_step":"UseQuota", "next_step":"End" } ]}
- DSL
- /
- SAGA
- DSL
- DSL
DSL(domain-specific language)HTMLDSL
1.2.2
SAGASDKTMSAGATMSAGASAGATCSAGA
3
- SAGA
- QuotaA
- 2TMTCTCQuotaASAGA
- 2PromotionB
- 4TMTCTCQuotaPromotionSAGA
- 4SAGA
func BizTrans(ctx context.Context, userId, loanId, couponIdPrincipal string) { saga.WithGlobalTransaction(ctx, func(ctx context.Context) { // biz.RefAccount().UseQuota(ctx, userId, loanId, Principal) // biz.RefPromotion().UseCoupon(ctx, userId, couponId) // local db op dao.ClFileAuthDAO().Insert(ctx, record) }, &seadt_model.Option{ TimeOutSecond: 10, TransactionName: "loan_apply", })
seadt TCCTCC10/
- TC
SAGA | SAGA | |
-TC / SDK-TC
- SAGA
- SDK-TCTCTMRMSDK
- -TCTC
SDKTC
SDK-TC | -TC | |
SDK | ||
SDK | ||
DB | ||
TM |
TCTCTCTCseadt TC
1.3
1.2SAGA
seadt-SAGA
seadt
SAGASAGA
DSL | ||
seadt TCC |
seadtTC
2. seadt-SAGA
2.1
seadt-SAGA
4 seadt-SAGA
2.2
seadt-SAGA
5 seadt-SAGA
- TM TC
- RM
- RM
- TM
- ConfirmTC
- CancelTCCancel RM Unuse/
2.3
1.2.2
6
seadt-SAGAseadt-TCCseadt-SDK SAGA Compensate API pbForward Forward pb
// saga_manager.govar quotaUseProxySagaRef *saga.SagaResourceServiceProxyfunc init() { quotaUseProxySagaRef = saga.RegisterSagaResourceService(new(QuotaUseSagaImpl))}func GetQuotaUseSagaRef() *saga.SagaResourceServiceProxy { return quotaUseProxySagaRef}
// saga_resource_impl.gotype QuotaUseSagaImpl struct {}func (t *QuotaUseSagaImpl) Forward(ctx context.Context, payload interface{}) (bool, error) { biz.UseQuota(ctx, payload) return true,nil}func (t *QuotaUseSagaImpl) Compensate(ctx context.Context, payload interface{}) bool { biz.UnUseQuota(ctx, payload) return true}
// service.gofunc UseQuota(ctx context.Context, req *api.UseQuotaReq, resp *api.UseQuotaResp) error { db.WithTransaction(ctx, func(ctx context.Context) { resp, err := seadt.GetQuotaUseSagaRef().Forward(ctx, req) if err != nil { panic(err) } }) return nil}
2.4
TCCSAGA
7
8
SAGATCCSAGACommitCommitCommitted
SAGATCCSAGA: PreparedConfirmedCanceledConfirmedCanceled
TM RM
Prepared | Committing | Committed | SRollbacking | Rollbacked | ||
- | Y | N | N | Y | N | |
Prepared | N | Y | N | N | Y | N |
Confirmed | N | N | Y | Y | Y | N |
Canceled | N | N | N | N | Y | Y |
RM RM
Prepared | Committed | Canceled | ||
Y | Y | Y | Y | |
Prepared | Y | Y | Y | Y |
Confirmed | Y | Y | Y | Y |
Canceled | Y | Y | Y | Y |
SAGARollbackingConfirmedCanceledSAGACanceled
- Rollbacking
SAGA
SAGA-TC
SAGASAGAseadt
-
SAGA
Backward crash recovery for parallel sagas is similar to that for sequential sagas. Within each process of the parallel saga, transactions are compensated for (or undone) in reverse order just as with sequential sagas. In addition all compensations in a child process must occur before any compensations for transactions in the parent that were executed before the child was created (forked). (Note that only transaction execution order within a process and fork and join information constrain the order of compensation. If T1 and T2 have executed in parallel processes and T2 has read data written by T1, compensating for T1 does not force us to compensate for T2 first.) : Hector Garcaa-Molrna, Kenneth Salem. SAGAS
9 SAGA
SAGA
Happened-before
In computer science, the happened-before relation (denoted: ->) is a relation between the result of two events, such that if one event should happen before another event, the result must reflect that, even if those events are in reality executed out of order (usually to optimize program flow). This involves ordering events based on the potential causal relationship of pairs of events in a concurrent system, especially asynchronous distributed systems. It was formulated by Leslie Lamport.
The happened-before relation is formally defined as the least strict partial order on events such that:
- If events a and b occur on the same process, a -> b if the occurrence of event a preceded the occurrence of event b.
- If event a is the sending of a message and event b is the reception of the message sent in event a, a -> b.
- If two events happen in different isolated processes (that do not exchange messages directly or indirectly via third-party processes), then the two processes are said to be concurrent, that is neither a -> b nor b -> a is true.
: Happened-before wiki
Happened-beforeHappened-before
Happened-before
SAGAHappened-before
- -
TCDSLSAGAHappened-before
- -
SAGASAGATCHappened-beforeHappened-before
Happened-before
Happened-before
VC n n
- P i V C i = [ 0 , , 0 ]
- P i i V C i [ i ] + = 1
- P i P j V C i
- P j [ 0 , n ) k V C j [ k ] = M a x ( V C j [ k ] , V C i [ k ] ) 2V C j [ j ] + = 1
1TM(Trans)RMQuotaPromotion
- TransP0QuotaP1PromotionP2
- TMRMVCi = [0,0,0]
- TransATrans[1,0,0]
- TransQuotaQuotaBQuota[2,1,0]
- TransQuotaPromotionPromotionCPromotion[4.2,1]
10
TCTCABCHappened-beforeA[1,0,0] < B[2,1,0] < C[4.2,1] => A -> B -> C
Happened-before
PiHashMapKeyValue
11
Happened-before
SAGASAGA
12
seadtTCTC
- ASeq-a < BSeq-bABABABASeq-a < BSeq-b
(TC)()SAGA
Happened-before
Happened-beforeseadtseadt-sdk
seadtseadt-sdkseadt-tc
- sagahttps://github.com/mltds/sagas-report
- https://zh.wikipedia.org/wiki/%E5%81%8F%E5%BA%8F%E5%85%B3%E7%B3%BB
- https://zh.wikipedia.org/wiki/%E5%85%A8%E5%BA%8F%E5%85%B3%E7%B3%BB
- Happened-beforehttps://en.wikipedia.org/wiki/Happened-before
- https://writings.sh/post/logical-clocks
:Yongchang
::Shopee
:https://mp.weixin.qq.com/s/VGz3YIHPzkniCWNDsc8Xgw
Disclaimer: The content of this article is sourced from the internet. The copyright of the text, images, and other materials belongs to the original author. The platform reprints the materials for the purpose of conveying more information. The content of the article is for reference and learning only, and should not be used for commercial purposes. If it infringes on your legitimate rights and interests, please contact us promptly and we will handle it as soon as possible! We respect copyright and are committed to protecting it. Thank you for sharing.(Email:[email protected])
Mobile advertising space rental |
Tag: Seadt Financial Level Distributed Transaction Solution III SAGA Design
Has the prophecy of nine experts regarding the Three Gorges Dam really come true now?
NextCrazy Internet: Why Are Choppers Named Heroes?
Guess you like
-
The 2025 Chinese New Year (Spring Festival) film box office has exploded, exceeding 3 billion RMB and setting a new record for presales!Detail
2025-01-29 11:55:06 1
-
Seres and Beihang University Join Hands to Build an Innovative Ecosystem, Deepening Industry-Academia-Research Collaboration and Promoting Technological TransformationDetail
2025-01-28 14:46:18 1
-
Douyin 2024 Platform Governance Report: Safeguarding Security, Building a Better CommunityDetail
2025-01-28 14:25:55 1
-
Chinese Scientists Develop a Lightweight Bionic Dexterous Hand with 19 Degrees of Freedom, Promising to Revolutionize Prosthetic and Robotics TechnologyDetail
2025-01-28 14:16:39 1
-
DeepSeek: A Chinese AI Startup's Meteoric Rise Shakes Up Global Tech and Sends US Stocks PlungingDetail
2025-01-28 14:13:23 1
-
WeChat's New Year's Red Envelope Feature Gets a Voice Message Upgrade for Warmer Wishes!Detail
2025-01-26 11:37:36 1
-
360 Digital Security Group and Zhibangyang Education Technology Join Forces to Build a New Ecosystem for Cybersecurity and AI Talent CultivationDetail
2025-01-24 15:09:51 1
-
Visionox Achieves Mass Production of AMOLED with Solid-State Laser Annealing (SLA) Technology, Ushering in a New Era for the Display IndustryDetail
2025-01-24 14:34:23 1
-
Seres at the Davos Forum: The Path to Globalizing New Energy Vehicles Through Cooperation in the Intelligent EraDetail
2025-01-23 13:28:12 1
-
Amazon to Close All French-Speaking Quebec Warehouses, Laying Off Nearly 2,000 EmployeesDetail
2025-01-23 10:51:23 1
-
The official launch of the 2025 Electric Bicycle Trade-in Policy: Upgraded Subsidy Standards, Procedures, and PromotionDetail
2025-01-23 10:48:52 1
-
Xbox Series X|S Officially Supports External Hard Drives Larger Than 16TB: Saying Goodbye to Storage WorriesDetail
2025-01-23 10:39:19 1
-
Leaders from the Beijing Chaoyang District CPPCC Visited Quantum Leap Group, Affirming its Contributions and Future Prospects in the Silver Hair EconomyDetail
2025-01-22 17:06:56 1
-
China's Car Imports Remain Sluggish in 2024: 12% Decline, Sharp Drop in New Energy VehiclesDetail
2025-01-22 11:37:25 1
-
China Railway Group Limited (CRGL) officially debunks "speed-up" ticket booking software: Not a shortcut, but a pathway to riskDetail
2025-01-22 11:36:09 1
-
Dago Bio Completes Over $20 Million A+ Round Funding to Accelerate Novel Molecular Glue Drug DevelopmentDetail
2025-01-22 11:34:05 11
-
Rapid Degradation of Global Lake Submerged Vegetation: Satellite Observations Reveal a Critical Period of Ecosystem ShiftDetail
2025-01-22 11:29:03 1
-
Star Ace Capital Group and Abu Dhabi Investment Office Partner to Build a Global Esports Industry BenchmarkDetail
2025-01-22 11:27:50 1
-
Hisense Television Leads the 100-Inch Large-Screen Market in 2024, Achieving an Unparalleled Industry LegacyDetail
2025-01-22 11:12:49 1
-
WeChat Launches "Gifts" Feature: Streamlining Gift-Giving and Powering Social Commerce GrowthDetail
2025-01-21 16:05:45 1