wangchenxuya opened a new pull request, #104:
URL: https://github.com/apache/incubator-seata-go-samples/pull/104

   **What this PR does**:
   
   Adds a runnable TCC (Try-Confirm-Cancel) sample under `tcc/ride-order/` that 
models a
   ride-hailing order spanning five independent services, coordinated by 
seata-go.
   
   A passenger requests a ride; creating a valid order requires five services 
to each reserve
   their own resource first (Try). Only if all reservations succeed are they 
committed together
   (Confirm); if any one fails, every already-reserved resource is explicitly 
released (Cancel).
   
   Each service implements Try / Confirm / Cancel:
   
   | Service | Port | Try | Confirm | Cancel |
   |---|---|---|---|---|
   | order-service | 8001 | create pending order | mark confirmed | mark 
cancelled |
   | dispatch-service | 8002 | reserve a driver | mark driver busy | release 
driver |
   | pricing-service | 8003 | lock estimated fare | confirm lock | release lock 
|
   | coupon-service | 8004 | freeze an available coupon | mark used | unfreeze |
   | capacity-service | 8005 | reserve a vehicle slot (+1) | keep reservation | 
release slot (-1) |
   
   `initiator` (ride-order-service) is the global-transaction initiator (TM): 
it opens a global
   transaction via `tm.WithGlobalTx`, propagates the XID over HTTP to each 
service's `/prepare`,
   and the Seata TC then drives Confirm/Cancel on the registered branches.
   
   Includes the required failure simulation: dispatch-service fails to find a 
driver at the Try
   phase, triggering a global rollback so coupon / capacity / pricing / order 
all run their Cancel
   and restore their resources. All Confirm/Cancel methods are idempotent 
(status-guarded SQL +
   per-XID dedup; empty rollback handled). The README documents the in-memory 
limitation and
   points to the `tcc/fence` sample for crash-safe idempotency.
   
   Deliverables: 5 runnable Go services + 1 initiator, `docker-compose` (MySQL 
+ Seata server),
   seed SQL, and a README explaining the TCC lifecycle and how to run.
   
   **Verified end-to-end** against MySQL 8 + Seata server:
   
   - Scenario 1 (all succeed): five Try -> five Confirm; order confirmed, 
coupon used, driver busy.
   - Scenario 2 (dispatch Try fails): four Try succeed, dispatch returns "no 
available driver",
     and the TC issues Cancel to every branch:
   
     ```
     [Dispatch-Cancel] no record ... idempotent skip   (empty rollback)
     [Capacity-Cancel] slot released
     [Coupon-Cancel]   coupon unfrozen
     [Pricing-Cancel]  fare lock released
     [Order-Cancel]    order cancelled
     ```
   
     Final DB state confirms all resources restored (order cancelled, coupon 
available again,
     fare lock released, slot released, driver untouched).
   
   **Which issue(s) this PR fixes**:
   Fixes #92
   
   **The related PR of seata-go**:
   N/A -- uses released seata-go (`v1.2.1-...`); no seata-go change required.
   
   **You should pay attention to items below to ensure your pr passes our ci 
test**
   
   - [x] All ut passed -- sample adds no unit tests; `go test 
./tcc/ride-order/...` is clean, packages build & `go vet` clean.
   - [x] After go-fmt ed -- `gofmt -l tcc/ride-order/` reports nothing.
   - [ ] Golangci-lint passed -- please rely on CI or run `sudo golangci-lint 
run`.
   - [x] New files carry the Apache license header (verified on all 21 files).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to