diff --git a/dora/integration/fuse/src/main/java/alluxio/fuse/AlluxioFuse.java b/dora/integration/fuse/src/main/java/alluxio/fuse/AlluxioFuse.java index d48173d0681b..cfd4574472bd 100644 --- a/dora/integration/fuse/src/main/java/alluxio/fuse/AlluxioFuse.java +++ b/dora/integration/fuse/src/main/java/alluxio/fuse/AlluxioFuse.java @@ -55,6 +55,7 @@ import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.annotation.concurrent.ThreadSafe; @@ -106,12 +107,20 @@ protected void startCommon(AlluxioConfiguration conf, setupFuseFileSystem(fuseFileSystem); launchFuse(fuseFileSystem, fsContext, fuseOptions, true); // This will block until umount } catch (Throwable t) { - if (executor != null) { - executor.shutdown(); - } // TODO(lu) FUSE unmount gracefully LOG.error("Failed to launch FUSE", t); System.exit(-1); + } finally { + if (executor != null) { + executor.shutdown(); + try { + executor.awaitTermination(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + LOG.warn("Interrupted while terminating the update checker thread"); + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } } } @@ -132,19 +141,20 @@ protected void stopCommon() { * @param conf configuration * @throws ParseException */ - public void start(AlluxioConfiguration conf) throws ParseException { + public void start(AlluxioConfiguration conf) throws ParseException, IOException { FuseOptions fuseOptions = FuseOptions.Builder.fromConfig(conf).build(); - FileSystemContext fsContext = FileSystemContext.create(conf); - if (!fuseOptions.getFileSystemOptions().getUfsFileSystemOptions().isPresent() - && !fuseOptions.getFileSystemOptions().isDoraCacheEnabled()) { - // cases other than standalone fuse sdk - conf = AlluxioFuseUtils.tryLoadingConfigFromMaster(fsContext); - } + try (FileSystemContext fsContext = FileSystemContext.create(conf)) { + if (!fuseOptions.getFileSystemOptions().getUfsFileSystemOptions().isPresent() + && !fuseOptions.getFileSystemOptions().isDoraCacheEnabled()) { + // cases other than standalone fuse sdk + conf = AlluxioFuseUtils.tryLoadingConfigFromMaster(fsContext); + } - startCommon(conf, fuseOptions, fsContext); // This will be blocked until quitting + startCommon(conf, fuseOptions, fsContext); // This will be blocked until quitting - stopCommon(); + stopCommon(); + } } /** @@ -154,7 +164,7 @@ public void start(AlluxioConfiguration conf) throws ParseException { * * @param args arguments to run the command line */ - public static void main(String[] args) throws ParseException { + public static void main(String[] args) throws ParseException, IOException { AlluxioFuse alluxioFuse = new AlluxioFuse(); FuseCliOptions fuseCliOptions = new FuseCliOptions(); JCommander jCommander = JCommander.newBuilder()