kylin-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KYLIN-3263) AbstractExecutable's retry has problem
Date Fri, 23 Feb 2018 15:24:00 GMT

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

ASF GitHub Bot commented on KYLIN-3263:
---------------------------------------

yiming187 closed pull request #104: KYLIN-3263, bugfix with AbstractExecutable's retry.
URL: https://github.com/apache/kylin/pull/104
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java
b/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java
index 91283f0f2d..dbe11c2ea3 100644
--- a/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java
+++ b/core-job/src/main/java/org/apache/kylin/job/execution/AbstractExecutable.java
@@ -165,7 +165,7 @@ public final ExecuteResult execute(ExecutableContext executableContext)
throws E
                     exception = e;
                 }
                 retry++;
-            } while (needRetry(result, exception));
+            } while (needRetry(this.retry, exception)); //exception in ExecuteResult should
handle by user itself.
 
             if (exception != null) {
                 onExecuteError(exception, executableContext);
@@ -221,13 +221,6 @@ private boolean isMetaDataPersistException(Exception e) {
         return false;
     }
 
-    private boolean isRetryableExecutionResult(ExecuteResult result) {
-        if (result != null && result.getThrowable() != null && isRetrableException(result.getThrowable()))
{
-            return true;
-        }
-        return false;
-    }
-
     protected abstract ExecuteResult doWork(ExecutableContext context) throws ExecuteException;
 
     @Override
@@ -468,25 +461,20 @@ protected final boolean isPaused() {
         return status == ExecutableState.STOPPED;
     }
 
-    protected boolean isRetrableException(Throwable t) {
-        return ArrayUtils.contains(KylinConfig.getInstanceFromEnv().getJobRetryExceptions(),
t.getClass().getName());
-    }
-
     // Retry will happen in below cases:
     // 1) if property "kylin.job.retry-exception-classes" is not set or is null, all jobs
with exceptions will retry according to the retry times.
     // 2) if property "kylin.job.retry-exception-classes" is set and is not null, only jobs
with the specified exceptions will retry according to the retry times.
-    protected boolean needRetry(ExecuteResult result, Throwable e) {
-        if (this.retry > KylinConfig.getInstanceFromEnv().getJobRetry()) {
+    public static boolean needRetry(int retry, Throwable t) {
+        if (retry > KylinConfig.getInstanceFromEnv().getJobRetry() || t == null) {
             return false;
+        } else {
+            return isRetryableException(t.getClass().getName());
         }
-        String[] retryableEx = KylinConfig.getInstanceFromEnv().getJobRetryExceptions();
-        if (retryableEx == null || retryableEx.length == 0) {
-            return true;
-        }
-        if ((result != null && isRetryableExecutionResult(result)) || e != null &&
isRetrableException(e)) {
-            return true;
-        }
-        return false;
+    }
+
+    private static boolean isRetryableException(String exceptionName) {
+        String[] jobRetryExceptions = KylinConfig.getInstanceFromEnv().getJobRetryExceptions();
+        return ArrayUtils.isEmpty(jobRetryExceptions) || ArrayUtils.contains(jobRetryExceptions,
exceptionName);
     }
 
     @Override
diff --git a/core-job/src/test/java/org/apache/kylin/job/RetryableTestExecutable.java b/core-job/src/test/java/org/apache/kylin/job/RetryableTestExecutable.java
deleted file mode 100644
index f656c44058..0000000000
--- a/core-job/src/test/java/org/apache/kylin/job/RetryableTestExecutable.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.kylin.job;
-
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.job.execution.ExecutableContext;
-import org.apache.kylin.job.execution.ExecuteResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- */
-public class RetryableTestExecutable extends BaseTestExecutable {
-    private static final Logger logger = LoggerFactory.getLogger(RetryableTestExecutable.class);
-
-    public RetryableTestExecutable() {
-        super();
-    }
-
-    @Override
-    protected ExecuteResult doWork(ExecutableContext context) {
-        logger.debug("run retryable exception test. ");
-        String[] exceptions = KylinConfig.getInstanceFromEnv().getJobRetryExceptions();
-        Throwable ex = null;
-        if (exceptions != null && exceptions.length > 0) {
-            try {
-                ex = (Throwable) Class.forName(exceptions[0]).newInstance();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        return new ExecuteResult(ExecuteResult.State.ERROR, null, ex);
-    }
-}
diff --git a/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
b/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
index c7c69cd8d6..3b24fe635f 100644
--- a/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
+++ b/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
@@ -18,25 +18,16 @@
 
 package org.apache.kylin.job.impl.threadpool;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.job.BaseTestExecutable;
 import org.apache.kylin.job.ErrorTestExecutable;
 import org.apache.kylin.job.FailedTestExecutable;
 import org.apache.kylin.job.FiveSecondSucceedTestExecutable;
 import org.apache.kylin.job.NoErrorStatusExecutable;
-import org.apache.kylin.job.RetryableTestExecutable;
 import org.apache.kylin.job.RunningTestExecutable;
 import org.apache.kylin.job.SelfStopExecutable;
 import org.apache.kylin.job.SucceedTestExecutable;
+import org.apache.kylin.job.execution.AbstractExecutable;
 import org.apache.kylin.job.execution.DefaultChainedExecutable;
 import org.apache.kylin.job.execution.ExecutableManager;
 import org.apache.kylin.job.execution.ExecutableState;
@@ -48,11 +39,28 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.FileNotFoundException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
  */
 public class DefaultSchedulerTest extends BaseSchedulerTest {
     private static final Logger logger = LoggerFactory.getLogger(DefaultSchedulerTest.class);
 
+    @Override
+    public void after() throws Exception {
+        super.after();
+        System.clearProperty("kylin.job.retry");
+        System.clearProperty("kylin.job.retry-exception-classes");
+    }
+
     @Rule
     public ExpectedException thrown = ExpectedException.none();
 
@@ -227,19 +235,16 @@ public void testSchedulerRestart() throws Exception {
         Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(job.getId()).getState());
         Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task1.getId()).getState());
     }
-    
+
+    @Test
     public void testRetryableException() throws Exception {
-        System.setProperty("kylin.job.retry-exception-classes", "java.io.FileNotFoundException");
         System.setProperty("kylin.job.retry", "3");
-        DefaultChainedExecutable job = new DefaultChainedExecutable();
-        BaseTestExecutable task1 = new SucceedTestExecutable();
-        BaseTestExecutable task2 = new RetryableTestExecutable();
-        job.addTask(task1);
-        job.addTask(task2);
-        execMgr.addJob(job);
-        waitForJobFinish(job.getId(), 10000);
-        Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task1.getId()).getState());
-        Assert.assertEquals(ExecutableState.ERROR, execMgr.getOutput(task2.getId()).getState());
-        Assert.assertEquals(ExecutableState.ERROR, execMgr.getOutput(job.getId()).getState());
+        Assert.assertTrue(AbstractExecutable.needRetry(1, new Exception("")));
+        Assert.assertFalse(AbstractExecutable.needRetry(1, null));
+        Assert.assertFalse(AbstractExecutable.needRetry(4, new Exception("")));
+
+        System.setProperty("kylin.job.retry-exception-classes", "java.io.FileNotFoundException");
+        Assert.assertTrue(AbstractExecutable.needRetry(1, new FileNotFoundException()));
+        Assert.assertFalse(AbstractExecutable.needRetry(1, new Exception("")));
     }
 }


 

----------------------------------------------------------------
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:
users@infra.apache.org


> AbstractExecutable's retry has problem
> --------------------------------------
>
>                 Key: KYLIN-3263
>                 URL: https://issues.apache.org/jira/browse/KYLIN-3263
>             Project: Kylin
>          Issue Type: Bug
>            Reporter: jiatao.tao
>            Assignee: jiatao.tao
>            Priority: Major
>




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

Mime
View raw message