You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by GitBox <gi...@apache.org> on 2020/10/28 01:49:56 UTC

[GitHub] [kylin] zhangayqian opened a new pull request #1464: KYLIN-4800 Add canary tool for sparder-context

zhangayqian opened a new pull request #1464:
URL: https://github.com/apache/kylin/pull/1464


   ## Proposed changes
   
   Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
   
   ## Types of changes
   
   What types of changes does your code introduce to Kylin?
   _Put an `x` in the boxes that apply_
   
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] Documentation Update (if none of the other choices apply)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [ ] I have create an issue on [Kylin's jira](https://issues.apache.org/jira/browse/KYLIN), and have described the bug/feature there in detail
   - [ ] Commit messages in my PR start with the related jira ID, like "KYLIN-0000 Make Kylin project open-source"
   - [ ] Compiling and unit tests pass locally with my changes
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] If this change need a document change, I will prepare another pr against the `document` branch
   - [ ] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at user@kylin or dev@kylin by explaining why you chose the solution you did and what alternatives you considered, etc...
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus merged pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus merged pull request #1464:
URL: https://github.com/apache/kylin/pull/1464


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513218360



##########
File path: kylin-spark-project/kylin-spark-query/src/main/java/org/apache/kylin/query/monitor/SparderContextCanary.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.query.monitor;
+
+import org.apache.kylin.common.KylinConfig;
+import org.apache.spark.api.java.JavaFutureAction;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.KylinSparkEnv;
+import org.apache.spark.sql.SparderContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class SparderContextCanary {
+    private static final Logger logger = LoggerFactory.getLogger(SparderContextCanary.class);
+    private static volatile boolean isStarted = false;
+
+    private static final int THRESHOLD_TO_RESTART_SPARK = KylinConfig.getInstanceFromEnv().getThresholdToRestartSparder();
+    private static final int PERIOD_MINUTES = KylinConfig.getInstanceFromEnv().getSparderCanaryPeriodMinutes();
+
+    private static volatile int errorAccumulated = 0;
+    private static volatile long lastResponseTime = -1;
+    private static volatile boolean sparderRestarting = false;
+
+    private SparderContextCanary() {
+    }
+
+    public static int getErrorAccumulated() {

Review comment:
       Add `@SuppressWarnings("unused")` to suppress warning in IDE, or remove this method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513219639



##########
File path: core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
##########
@@ -2879,6 +2879,18 @@ public boolean isAutoStartSparder() {
         return Boolean.parseBoolean(this.getOptional("kylin.query.auto-sparder-context", "false"));
     }
 
+    public int getSparderCanaryErrorResponseMs() {

Review comment:
       I wonder if we can see any short but clear comments here for Kylin user.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513215189



##########
File path: kylin-spark-project/kylin-spark-query/src/main/scala/org/apache/spark/sql/SparderContext.scala
##########
@@ -194,6 +195,10 @@ object SparderContext extends Logging {
         logInfo("Initializing Spark, waiting for done.")
         initializingThread.join()
       }
+
+      if (System.getProperty("spark.local") ne "true")
+      //monitor sparder
+      SparderContextCanary.init()

Review comment:
       This line should be indented .




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513218905



##########
File path: kylin-spark-project/kylin-spark-query/src/main/java/org/apache/kylin/query/monitor/SparderContextCanary.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.query.monitor;
+
+import org.apache.kylin.common.KylinConfig;
+import org.apache.spark.api.java.JavaFutureAction;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.KylinSparkEnv;
+import org.apache.spark.sql.SparderContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class SparderContextCanary {
+    private static final Logger logger = LoggerFactory.getLogger(SparderContextCanary.class);
+    private static volatile boolean isStarted = false;
+
+    private static final int THRESHOLD_TO_RESTART_SPARK = KylinConfig.getInstanceFromEnv().getThresholdToRestartSparder();
+    private static final int PERIOD_MINUTES = KylinConfig.getInstanceFromEnv().getSparderCanaryPeriodMinutes();
+
+    private static volatile int errorAccumulated = 0;
+    private static volatile long lastResponseTime = -1;
+    private static volatile boolean sparderRestarting = false;
+
+    private SparderContextCanary() {
+    }
+
+    public static int getErrorAccumulated() {
+        return errorAccumulated;
+    }
+
+    public long getLastResponseTime() {
+        return lastResponseTime;
+    }
+
+    public boolean isSparderRestarting() {
+        return sparderRestarting;
+    }
+
+    public static void init() {
+        if (!isStarted) {
+            synchronized (SparderContextCanary.class) {
+                if (!isStarted) {
+                    isStarted = true;
+                    logger.info("Start monitoring Sparder");
+                    Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(SparderContextCanary::monitor,
+                            PERIOD_MINUTES, PERIOD_MINUTES, TimeUnit.MINUTES);
+                }
+            }
+        }
+    }
+
+    public static boolean isError() {
+        return errorAccumulated >= THRESHOLD_TO_RESTART_SPARK;
+    }
+
+    public static void monitor() {
+        try {
+            long startTime = System.currentTimeMillis();
+            // check sparder context
+            if (!SparderContext.isSparkAvailable()) {
+                logger.info("Sparder is unavailable, need to restart immediately.");
+                errorAccumulated = Math.max(errorAccumulated + 1, THRESHOLD_TO_RESTART_SPARK);
+            } else {
+                try {
+                    JavaSparkContext jsc = JavaSparkContext.fromSparkContext(SparderContext.getSparkSession().sparkContext());
+                    jsc.setLocalProperty("spark.scheduler.pool", "vip_tasks");
+
+                    long t = System.currentTimeMillis();
+                    long ret = numberCount(jsc).get(KylinConfig.getInstanceFromEnv().getSparderCanaryErrorResponseMs(),
+                            TimeUnit.MILLISECONDS);
+                    logger.info("SparderContextCanary numberCount returned successfully with value {}, takes {} ms.", ret,
+                            (System.currentTimeMillis() - t));
+                    // reset errorAccumulated once good context is confirmed
+                    errorAccumulated = 0;
+                } catch (TimeoutException te) {
+                    errorAccumulated++;
+                    logger.error("SparderContextCanary numberCount timeout, didn't return in {} ms, error {} times.",
+                            KylinConfig.getInstanceFromEnv().getSparderCanaryErrorResponseMs(), errorAccumulated);
+                } catch (ExecutionException ee) {
+                    logger.error("SparderContextCanary numberCount occurs exception, need to restart immediately.", ee);
+                    errorAccumulated = Math.max(errorAccumulated + 1, THRESHOLD_TO_RESTART_SPARK);
+                } catch (Exception e) {
+                    errorAccumulated++;
+                    logger.error("SparderContextCanary numberCount occurs exception.", e);
+                }
+            }
+
+            lastResponseTime = System.currentTimeMillis() - startTime;
+            logger.debug("Sparder context errorAccumulated:{}", errorAccumulated);
+
+            if (isError()) {
+                sparderRestarting = true;
+                try {
+                    // Take repair action if error accumulated exceeds threshold
+                    logger.warn("Repairing sparder context");
+                    if (System.getProperty("spark.local") == "true") {

Review comment:
       Use `==` or `equals` ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513216412



##########
File path: kylin-spark-project/kylin-spark-query/src/main/java/org/apache/kylin/query/monitor/SparderContextCanary.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.query.monitor;
+
+import org.apache.kylin.common.KylinConfig;
+import org.apache.spark.api.java.JavaFutureAction;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.KylinSparkEnv;
+import org.apache.spark.sql.SparderContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class SparderContextCanary {
+    private static final Logger logger = LoggerFactory.getLogger(SparderContextCanary.class);
+    private static volatile boolean isStarted = false;
+
+    private static final int THRESHOLD_TO_RESTART_SPARK = KylinConfig.getInstanceFromEnv().getThresholdToRestartSparder();
+    private static final int PERIOD_MINUTES = KylinConfig.getInstanceFromEnv().getSparderCanaryPeriodMinutes();
+
+    private static volatile int errorAccumulated = 0;
+    private static volatile long lastResponseTime = -1;
+    private static volatile boolean sparderRestarting = false;
+
+    private SparderContextCanary() {
+    }
+
+    public static int getErrorAccumulated() {
+        return errorAccumulated;
+    }
+
+    public long getLastResponseTime() {
+        return lastResponseTime;
+    }
+
+    public boolean isSparderRestarting() {
+        return sparderRestarting;
+    }
+
+    public static void init() {
+        if (!isStarted) {
+            synchronized (SparderContextCanary.class) {
+                if (!isStarted) {
+                    isStarted = true;
+                    logger.info("Start monitoring Sparder");
+                    Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(SparderContextCanary::monitor,
+                            PERIOD_MINUTES, PERIOD_MINUTES, TimeUnit.MINUTES);
+                }
+            }
+        }
+    }
+
+    public static boolean isError() {
+        return errorAccumulated >= THRESHOLD_TO_RESTART_SPARK;
+    }
+
+    public static void monitor() {
+        try {
+            long startTime = System.currentTimeMillis();
+            // check sparder context
+            if (!SparderContext.isSparkAvailable()) {
+                logger.info("Sparder is unavailable, need to restart immediately.");
+                errorAccumulated = Math.max(errorAccumulated + 1, THRESHOLD_TO_RESTART_SPARK);
+            } else {
+                try {
+                    JavaSparkContext jsc = JavaSparkContext.fromSparkContext(SparderContext.getSparkSession().sparkContext());
+                    jsc.setLocalProperty("spark.scheduler.pool", "vip_tasks");
+
+                    long t = System.currentTimeMillis();
+                    long ret = numberCount(jsc).get(KylinConfig.getInstanceFromEnv().getSparderCanaryErrorResponseMs(),
+                            TimeUnit.MILLISECONDS);
+                    logger.info("SparderContextCanary numberCount returned successfully with value {}, takes {} ms.", ret,
+                            (System.currentTimeMillis() - t));
+                    // reset errorAccumulated once good context is confirmed
+                    errorAccumulated = 0;
+                } catch (TimeoutException te) {
+                    errorAccumulated++;
+                    logger.error("SparderContextCanary numberCount timeout, didn't return in {} ms, error {} times.",
+                            KylinConfig.getInstanceFromEnv().getSparderCanaryErrorResponseMs(), errorAccumulated);
+                } catch (ExecutionException ee) {
+                    logger.error("SparderContextCanary numberCount occurs exception, need to restart immediately.", ee);
+                    errorAccumulated = Math.max(errorAccumulated + 1, THRESHOLD_TO_RESTART_SPARK);
+                } catch (Exception e) {
+                    errorAccumulated++;
+                    logger.error("SparderContextCanary numberCount occurs exception.", e);
+                }
+            }
+
+            lastResponseTime = System.currentTimeMillis() - startTime;
+            logger.debug("Sparder context errorAccumulated:{}", errorAccumulated);
+
+            if (isError()) {
+                sparderRestarting = true;
+                try {
+                    // Take repair action if error accumulated exceeds threshold
+                    logger.warn("Repairing sparder context");
+                    if (System.getProperty("spark.local") == "true") {
+                        SparderContext.setSparkSession(KylinSparkEnv.getSparkSession());
+                    } else {
+                        SparderContext.restartSpark();
+                    }
+                } catch (Throwable th) {
+                    logger.error("Restart sparder context failed.", th);
+                }
+                sparderRestarting = false;
+            }
+        } catch (Throwable th) {
+            logger.error("Error when monitoring Sparder.", th);
+        }
+    }
+
+    // for canary
+    private static JavaFutureAction<Long> numberCount(JavaSparkContext jsc) {
+        List<Integer> list = new ArrayList();

Review comment:
       Use `new ArrayList<>()` instead.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [kylin] hit-lacus commented on a change in pull request #1464: KYLIN-4800 Add canary tool for sparder-context

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1464:
URL: https://github.com/apache/kylin/pull/1464#discussion_r513218472



##########
File path: kylin-spark-project/kylin-spark-query/src/main/java/org/apache/kylin/query/monitor/SparderContextCanary.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.query.monitor;
+
+import org.apache.kylin.common.KylinConfig;
+import org.apache.spark.api.java.JavaFutureAction;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.apache.spark.sql.KylinSparkEnv;
+import org.apache.spark.sql.SparderContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class SparderContextCanary {
+    private static final Logger logger = LoggerFactory.getLogger(SparderContextCanary.class);
+    private static volatile boolean isStarted = false;
+
+    private static final int THRESHOLD_TO_RESTART_SPARK = KylinConfig.getInstanceFromEnv().getThresholdToRestartSparder();
+    private static final int PERIOD_MINUTES = KylinConfig.getInstanceFromEnv().getSparderCanaryPeriodMinutes();
+
+    private static volatile int errorAccumulated = 0;
+    private static volatile long lastResponseTime = -1;
+    private static volatile boolean sparderRestarting = false;
+
+    private SparderContextCanary() {
+    }
+
+    public static int getErrorAccumulated() {
+        return errorAccumulated;
+    }
+
+    public long getLastResponseTime() {

Review comment:
       Same here~




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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