Hi, Pack Team

I recently looked at some forward compensation processing logic and have
some questions

1. forward compensation will retry after the call fails until the maximum
number of retries is exceeded. It calls the reverse compensate applyTo
method with each retry. This will cause multiple TxStartedEvent and
TxAbortEvent to be sent. Test case [1] proves this.

For example, retries=2, the first failure and the second success, Alpha
will receive the following events

TxStartedEvent-tx1 (first)
TxAbortEvent-tx1(This will trigger the compensation operation)
TxStartedEvent-tx1 (second)
TxEndedEvent-tx1 (tx1 will be submitted)

I suggest sending the TxAbortEvent event only if the last forward retry
failed. The modified event list looks as follows

Example 1: retries=3 and retry all failed

TxStartedEvent-tx1
TxStartedEvent-tx1
TxStartedEvent-tx1
TxAbortEvent-tx1(Trigger compensation operation)

Example 2: retries=3 and and last retry succeeded

TxStartedEvent-tx1
TxStartedEvent-tx1
TxStartedEvent-tx1
TxEndedEvent-tx1

2. I suggest remove retires is -1 option, reasonable use of parameters
retries and retryDelayInMilliseconds can meet most scenarios

[1]
https://github.com/apache/servicecomb-pack/blob/133a2fa7247b2ba00a380762a38369849390560e/omega/omega-transaction/src/test/java/org/apache/servicecomb/pack/omega/transaction/TransactionAspectTest.java#L309

[2]
https://github.com/apache/servicecomb-pack/blob/a8b24100a59a8ec9c917f89b1aa6978cc81e10df/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/pack/omega/transaction/spring/TransactionInterceptionTest.java#L199

[3]
https://github.com/apache/servicecomb-pack/blob/133a2fa7247b2ba00a380762a38369849390560e/omega/omega-transaction/src/test/java/org/apache/servicecomb/pack/omega/transaction/TransactionAspectTest.java#L353

Best regards,
Lei Zhang

Reply via email to