You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vi...@apache.org on 2018/12/10 14:04:32 UTC

[drill] 01/02: DRILL-6877: NPE when starting Drillbit

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

vitalii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit 788eb7effe72d838427d42fabbf167fa424bf88c
Author: Venkata Jyothsna Donapati <jy...@gmail.com>
AuthorDate: Mon Dec 3 10:19:06 2018 -0800

    DRILL-6877: NPE when starting Drillbit
    
    closes #1560
---
 distribution/src/resources/drillbit.sh             |  2 +-
 .../org/apache/drill/exec/server/Drillbit.java     | 28 +++++++++++++++++-----
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/distribution/src/resources/drillbit.sh b/distribution/src/resources/drillbit.sh
index 5ad87b1..404c6f8 100755
--- a/distribution/src/resources/drillbit.sh
+++ b/distribution/src/resources/drillbit.sh
@@ -87,7 +87,7 @@ export args
 
 # Set default scheduling priority
 DRILL_NICENESS=${DRILL_NICENESS:-0}
-GRACEFUL_FILE=$DRILL_PID_DIR/$GRACEFUL_SIGFILE
+GRACEFUL_FILE=$DRILL_HOME/$GRACEFUL_SIGFILE
 
 waitForProcessEnd()
 {
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
index 3e78f03..4c595a2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
@@ -18,8 +18,9 @@
 package org.apache.drill.exec.server;
 
 import java.io.IOException;
-import java.nio.file.FileSystems;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.file.StandardWatchEventKinds;
 import java.nio.file.WatchEvent;
 import java.nio.file.WatchKey;
@@ -373,18 +374,33 @@ public class Drillbit implements AutoCloseable {
       }
     }
 
+    /*
+     * Poll for the graceful file, if the file is found cloase the drillbit. In case if the DRILL_HOME path is not
+     * set, graceful shutdown will not be supported from the command line.
+     */
     private void pollShutdown(Drillbit drillbit) throws IOException, InterruptedException {
-      final Path drillPidDirPath = FileSystems.getDefault().getPath(System.getenv("DRILL_PID_DIR"));
-      final String gracefulFileName = System.getenv("GRACEFUL_SIGFILE");
+      final String drillHome = System.getenv("DRILL_HOME");
+      final String gracefulFile = System.getenv("GRACEFUL_SIGFILE");
+      final Path drillHomePath;
+      if (drillHome == null || gracefulFile == null) {
+        logger.warn("Cannot access graceful file. Graceful shutdown from command line will not be supported.");
+        return;
+      }
+      try {
+        drillHomePath = Paths.get(drillHome);
+      } catch (InvalidPathException e) {
+        logger.warn("Cannot access graceful file. Graceful shutdown from command line will not be supported.");
+        return;
+      }
       boolean triggered_shutdown = false;
       WatchKey wk = null;
-      try (final WatchService watchService = FileSystems.getDefault().newWatchService()) {
-        drillPidDirPath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE);
+      try (final WatchService watchService = drillHomePath.getFileSystem().newWatchService()) {
+        drillHomePath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE);
         while (!triggered_shutdown) {
           wk = watchService.take();
           for (WatchEvent<?> event : wk.pollEvents()) {
             final Path changed = (Path) event.context();
-            if (changed != null && changed.endsWith(gracefulFileName)) {
+            if (changed != null && changed.endsWith(gracefulFile)) {
               drillbit.interruptPollShutdown = false;
               triggered_shutdown = true;
               drillbit.close();