[ 
https://issues.apache.org/jira/browse/SCB-224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16395346#comment-16395346
 ] 

ASF GitHub Bot commented on SCB-224:
------------------------------------

WillemJiang commented on a change in pull request #138: [WIP] SCB-224 retry 
sub-transaction on failure
URL: 
https://github.com/apache/incubator-servicecomb-saga/pull/138#discussion_r173799851
 
 

 ##########
 File path: 
omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/ForwardRecovery.java
 ##########
 @@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.omega.transaction;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Method;
+
+import javax.transaction.InvalidTransactionException;
+
+import org.apache.servicecomb.saga.omega.context.OmegaContext;
+import org.apache.servicecomb.saga.omega.transaction.annotations.Compensable;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ForwardRecovery extends DefaultRecovery {
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  // TODO: 2018/03/10 we do not support retry with timeout yet
+  @Override
+  public Object apply(ProceedingJoinPoint joinPoint, Compensable compensable, 
CompensableInterceptor interceptor,
+      OmegaContext context, String parentTxId, int retries) throws Throwable {
+    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
+    int remains = retries;
+    try {
+      while (true) {
+        try {
+          return super.apply(joinPoint, compensable, interceptor, context, 
parentTxId, remains);
+        } catch (Throwable throwable) {
+          if (throwable instanceof InvalidTransactionException) {
+            throw throwable;
+          }
+
+          remains = remains == -1 ? -1 : remains - 1;
+          if (remains == 0) {
+            log.error(
+                "Retried sub tx failed maximum times, global tx id: {}, local 
tx id: {}, method: {}, retried times: {}",
+                context.globalTxId(), context.localTxId(), method.toString(), 
retries);
+            throw throwable;
+          }
+
+          log.warn("Retrying sub tx failed, global tx id: {}, local tx id: {}, 
method: {}, remains: {}",
+              context.globalTxId(), context.localTxId(), method.toString(), 
remains);
+          Thread.sleep(compensable.retryDelayInMilliseconds());
 
 Review comment:
   It may cause some performance issue by using Thread.sleep here.
   we may need to consider to use scheduler for it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [pack] retry sub-transaction on failure
> ---------------------------------------
>
>                 Key: SCB-224
>                 URL: https://issues.apache.org/jira/browse/SCB-224
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>          Components: Saga
>            Reporter: Yin Xiang
>            Assignee: Eric Lee
>            Priority: Major
>             Fix For: saga-0.2.0
>
>
> as a user, i want to retry transaction in my service, so that it can always 
> be done eventually.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to