kgyrtkirk commented on a change in pull request #1577:
URL: https://github.com/apache/hive/pull/1577#discussion_r507744113



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/PathCleaner.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.hadoop.hive.ql;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.BlockingDeque;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * This class is used to asynchronously remove directories after query 
execution
+ */
+public class PathCleaner {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(PathCleaner.class.getName());
+  private static final AsyncDeleteAction END_OF_PROCESS = new 
AsyncDeleteAction(null, null);
+
+  private final BlockingDeque<AsyncDeleteAction> deleteActions = new 
LinkedBlockingDeque<>();
+  private final AtomicBoolean isShutdown = new AtomicBoolean();

Review comment:
       note: all usages are negated for this boolean - instead of using 
negative logic (shutdown) ; using a positive name like "run" might make things 
easier to read/follow

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/Context.java
##########
@@ -673,22 +673,27 @@ public void removeScratchDir() {
     if(this.fsResultCacheDirs != null) {
       resultCacheDir = this.fsResultCacheDirs.toUri().getPath();
     }
-    for (Map.Entry<String, Path> entry : fsScratchDirs.entrySet()) {
+    SessionState sessionState = SessionState.get();
+    for (Path p: fsScratchDirs.values()) {
       try {
-        Path p = entry.getValue();
         if (p.toUri().getPath().contains(stagingDir) && subDirOf(p, 
fsScratchDirs.values())  ) {
           LOG.debug("Skip deleting stagingDir: " + p);
           FileSystem fs = p.getFileSystem(conf);
           fs.cancelDeleteOnExit(p);
           continue; // staging dir is deleted when deleting the scratch dir
         }
-        if(resultCacheDir == null || 
!p.toUri().getPath().contains(resultCacheDir)) {
+        if (resultCacheDir == null || 
!p.toUri().getPath().contains(resultCacheDir)) {
           // delete only the paths which aren't result cache dir path
           // because that will be taken care by removeResultCacheDir
-        FileSystem fs = p.getFileSystem(conf);
-        LOG.debug("Deleting scratch dir: {}",  p);
-        fs.delete(p, true);
-        fs.cancelDeleteOnExit(p);
+          FileSystem fs = p.getFileSystem(conf);
+          if (sessionState.isSyncContextCleanup()) {

Review comment:
       I think another approach could be to create 2 PathCleaner 
implementations - the existing Async and the synch one; that could create a 
tighter contract seal between the usage and the implementations.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/DriverUtils.java
##########
@@ -61,6 +61,7 @@ public static void runOnDriver(HiveConf conf, String user,
       throw new 
IllegalArgumentException(JavaUtils.txnIdToString(compactorTxnId) +
           " is not valid. Context: " + query);
     }
+    sessionState.setSyncCleanup();

Review comment:
       this is a one-way switch; so there is no way to switch back to the 
earlier behaviour

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
##########
@@ -388,6 +397,19 @@ public boolean getIsQtestLogging() {
     return isQtestLogging;
   }
 
+  public PathCleaner getPathCleaner() {
+    if (pathCleaner == null) {
+      pathCleaner = new PathCleaner(getSessionId());
+      pathCleaner.start();
+    }
+    return pathCleaner;
+  }
+
+  public void setSyncCleanup() {
+    pathCleaner = null;

Review comment:
       I think in case `pathCleaner` is initialized - after calling this a 
thread will be left running in the background




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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to