fix cleanup of tmp dir in HdfsDataSegmentPusher (#3636)

This commit is contained in:
Himanshu 2016-11-01 12:45:38 -05:00 committed by Parag Jain
parent f1dee037d6
commit eb70a12e43
1 changed files with 8 additions and 4 deletions

View File

@ -116,11 +116,7 @@ public class HdfsDataSegmentPusher implements DataSegmentPusher
// Create parent if it does not exist, recreation is not an error // Create parent if it does not exist, recreation is not an error
fs.mkdirs(outDir.getParent()); fs.mkdirs(outDir.getParent());
if (!fs.rename(tmpFile.getParent(), outDir)) { 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)) { if (fs.exists(outDir)) {
log.info( log.info(
"Unable to rename temp directory[%s] to segment directory[%s]. It is already pushed by a replica task.", "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; return dataSegment;