From eb70a12e436946f2857eba16f710c3f6d0c4ff06 Mon Sep 17 00:00:00 2001 From: Himanshu Date: Tue, 1 Nov 2016 12:45:38 -0500 Subject: [PATCH] fix cleanup of tmp dir in HdfsDataSegmentPusher (#3636) --- .../io/druid/storage/hdfs/HdfsDataSegmentPusher.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsDataSegmentPusher.java b/extensions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsDataSegmentPusher.java index 9955141e0c9..abc55e5ab67 100644 --- a/extensions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsDataSegmentPusher.java +++ b/extensions-core/hdfs-storage/src/main/java/io/druid/storage/hdfs/HdfsDataSegmentPusher.java @@ -116,11 +116,7 @@ public class HdfsDataSegmentPusher implements DataSegmentPusher // Create parent if it does not exist, recreation is not an error fs.mkdirs(outDir.getParent()); - if (!fs.rename(tmpFile.getParent(), outDir)) { - if (!fs.delete(tmpFile.getParent(), true)) { - log.error("Failed to delete temp directory[%s]", tmpFile.getParent()); - } if (fs.exists(outDir)) { log.info( "Unable to rename temp directory[%s] to segment directory[%s]. It is already pushed by a replica task.", @@ -135,6 +131,14 @@ public class HdfsDataSegmentPusher implements DataSegmentPusher )); } } + } finally { + try { + if (fs.exists(tmpFile.getParent()) && !fs.delete(tmpFile.getParent(), true)) { + log.error("Failed to delete temp directory[%s]", tmpFile.getParent()); + } + } catch(IOException ex) { + log.error(ex, "Failed to delete temp directory[%s]", tmpFile.getParent()); + } } return dataSegment;