[ https://issues.apache.org/jira/browse/HIVE-24270?focusedWorklogId=502191&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-502191 ]
ASF GitHub Bot logged work on HIVE-24270: ----------------------------------------- Author: ASF GitHub Bot Created on: 19/Oct/20 13:31 Start Date: 19/Oct/20 13:31 Worklog Time Spent: 10m Work Description: 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 Issue Time Tracking ------------------- Worklog Id: (was: 502191) Time Spent: 40m (was: 0.5h) > Move scratchdir cleanup to background > ------------------------------------- > > Key: HIVE-24270 > URL: https://issues.apache.org/jira/browse/HIVE-24270 > Project: Hive > Issue Type: Improvement > Reporter: Mustafa Iman > Assignee: Mustafa Iman > Priority: Major > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > In cloud environment, scratchdir cleaning at the end of the query may take > long time. This causes client to hang up to 1 minute even after the results > were streamed back. During this time client just waits for cleanup to finish. > Cleanup can take place in the background in HiveServer. -- This message was sent by Atlassian Jira (v8.3.4#803005)