- Define Transaction Manager as TM, define Resource Manager as RM
- Business send request to TM to start a new transaction
- TM send msg to RM to prepare a transaction
- if all RM response ok, go to next step; if any RM fails, TM will send rollback to all RM
- TM send commit to all RM, if any RM fails, TM will send rollback to all RM
- All RM commited transaction
- Define Transaction Manager as TM, define Resource Manager as RM
- Business send request to TM to start a new transaction
- TM send
canCommit
to all RM, TM switch towaiting
state. - If RM agree, return YES to TM and switch to
prepared
state, if exception ocurrs, switch toabort
- TM receives response from all RM, if ok, TM send
preCommit
to all RMs, and switch toprepared
state; if not ok, send abort to all RMs - RMs receive
preCommit
, responses ACK to TM. - TM receives most part of RMs' ACK, switch to
commit
state, and senddoCommit
to all RMs, if timeout occurs to wait an ACK from RMs, TM will abort the whole transaction - RMs receive
doCommit
and send ACK to TM, if RMs cannot receive adoCommit
, it'll also commit the local transaction.
- client query for state
- service query mysql, if record found, and then response to client; if no record found, send a synchronous request to downstream, record response status
quering
,succeed
orfailed
. - if failed, retry, if succeed, update record to
succeed
- Business start transaction, write to message service with
init
- Business Operation
- Business Commit transaction, and modified message status to
wait
- Message service use Timing Polling to handle:
init
, it maybe timeout transaction, cancel it and notice Business servicewait
, send to MQ(kafka)- Kafka consumer pull msg and execute, need to ensure Idepotence
- Once consumer succeed, return ACK to Kafka and to message service
- Message service modified message status to
succeed
- Business start transaction
- Business operation
- Write to local msg table with
wait
- Commit transaction
- Business start a timing polling thread to poll local msg table
- Timing polling thread find the record with
wait
status, send it to Kafka - Kafka consumer pull msg and execute, need to ensure Idepotence
- Once consumer succeed, return ACK to Kafka and to business service
- business service modified msg to
succeed
if there is a fail at any moment, just do a rollback
- Primary business send
TryRequest
to secondary business - Secondary business execute local transaction and commit, response to Primary business
- If TryRequest succeed, Primary send
confirm
to secondary business; if failed, Primary sendCancel
to secondary business - Secondary execute a compensation transaction to withdral the resource in TryRequest