sohami commented on a change in pull request #1536: DRILL-6039: Fixed drillbit.sh script to do graceful shutdown URL: https://github.com/apache/drill/pull/1536#discussion_r235501156
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java ########## @@ -335,6 +351,50 @@ private void javaPropertiesToSystemOptions() { } } + + // Polls for graceful file to check if graceful shutdown is triggered from the script. + private static class PollShutdownThread extends Thread { + + private final Drillbit drillbit; + private final StackTrace stackTrace; + + public PollShutdownThread(final Drillbit drillbit, final StackTrace stackTrace) { + this.drillbit = drillbit; + this.stackTrace = stackTrace; + } + + @Override + public void run () { + try { + pollShutdown(drillbit); + } catch (Exception e) { + throw new RuntimeException("Caught exception while polling for shutdown\n" + stackTrace, e); + } + } + + private void pollShutdown(Drillbit drillbit) throws IOException, InterruptedException { + final Path path = FileSystems.getDefault().getPath(System.getenv("DRILL_PID_DIR")); + final String file = System.getenv("GRACEFUL_SIGFILE"); + boolean triggered_shutdown = false; + try (final WatchService watchService = FileSystems.getDefault().newWatchService()) { + path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE); + while (!triggered_shutdown) { + final WatchKey wk = watchService.take(); + for (WatchEvent<?> event : wk.pollEvents()) { + final Path changed = (Path) event.context(); Review comment: `event.context()` can be null (See [here](https://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchEvent.html#context())). please add a check 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 With regards, Apache Git Services