You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2020/01/09 14:27:01 UTC

[servicecomb-pack] 01/03: SCB-1707 forward compensation only sends once a failure event if multiple retries fail

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit cac096b3a4e24aa5b5c8b631c0b5ff3dcae4d73e
Author: Lei Zhang <zh...@apache.org>
AuthorDate: Wed Jan 8 10:06:47 2020 +0800

    SCB-1707 forward compensation only sends once a failure event if multiple retries fail
---
 .../servicecomb/pack/omega/transaction/DefaultRecovery.java   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

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 @@ public class DefaultRecovery extends AbstractRecoveryPolicy {
 
   @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 @@ public class DefaultRecovery extends AbstractRecoveryPolicy {
 
       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;
     }
   }