diff --git a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCp.java b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCp.java index 892bffa7db9..141f45d61f3 100644 --- a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCp.java +++ b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/DistCp.java @@ -473,13 +473,18 @@ public class DistCp extends Configured implements Tool { return config; } - private synchronized void cleanup() { + /** + * Clean the staging folder created by distcp. + */ + protected synchronized void cleanup() { try { if (metaFolder != null) { - if (jobFS != null) { - jobFS.delete(metaFolder, true); + synchronized (this) { + if (jobFS != null) { + jobFS.delete(metaFolder, true); + } + metaFolder = null; } - metaFolder = null; } } catch (IOException e) { LOG.error("Unable to cleanup meta folder: " + metaFolder, e);