- 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
canCommitto all RM, TM switch towaitingstate. - If RM agree, return YES to TM and switch to
preparedstate, if exception ocurrs, switch toabort - TM receives response from all RM, if ok, TM send
preCommitto all RMs, and switch topreparedstate; if not ok, send abort to all RMs - RMs receive
preCommit, responses ACK to TM. - TM receives most part of RMs' ACK, switch to
commitstate, and senddoCommitto all RMs, if timeout occurs to wait an ACK from RMs, TM will abort the whole transaction - RMs receive
doCommitand 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,succeedorfailed. - 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
waitstatus, 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
TryRequestto secondary business - Secondary business execute local transaction and commit, response to Primary business
- If TryRequest succeed, Primary send
confirmto secondary business; if failed, Primary sendCancelto secondary business - Secondary execute a compensation transaction to withdral the resource in TryRequest