SCB-1707 forward compensation only sends once a failure event if multiple retries fail
diff --git a/omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/DefaultRecovery.java b/omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/DefaultRecovery.java
index 3418f3a..19e7825 100644
--- a/omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/DefaultRecovery.java
+++ b/omega/omega-transaction/src/main/java/org/apache/servicecomb/pack/omega/transaction/DefaultRecovery.java
@@ -47,17 +47,17 @@
@Override
public Object applyTo(ProceedingJoinPoint joinPoint, Compensable compensable, CompensableInterceptor interceptor,
- OmegaContext context, String parentTxId, int retries) throws Throwable {
+ OmegaContext context, String parentTxId, int forwardRetries) throws Throwable {
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
LOG.debug("Intercepting compensable method {} with context {}", method.toString(), context);
String compensationSignature =
compensable.compensationMethod().isEmpty() ? "" : compensationMethodSignature(joinPoint, compensable, method);
- String retrySignature = (retries != 0 || compensationSignature.isEmpty()) ? method.toString() : "";
+ String retrySignature = (forwardRetries != 0 || compensationSignature.isEmpty()) ? method.toString() : "";
AlphaResponse response = interceptor.preIntercept(parentTxId, compensationSignature, compensable.forwardTimeout(),
- retrySignature, retries, joinPoint.getArgs());
+ retrySignature, forwardRetries, joinPoint.getArgs());
if (response.aborted()) {
String abortedLocalTxId = context.localTxId();
context.setLocalTxId(parentTxId);
@@ -71,7 +71,10 @@
return result;
} catch (Throwable throwable) {
- interceptor.onError(parentTxId, compensationSignature, throwable);
+ if (compensable.forwardRetries() == 0 || (compensable.forwardRetries() > 0
+ && forwardRetries == 1)) {
+ interceptor.onError(parentTxId, compensationSignature, throwable);
+ }
throw throwable;
}
}