create parent dir on HDFS if it does not exist (#3547)

This commit is contained in:
Parag Jain 2016-10-06 18:14:00 -05:00 committed by Slim
parent 76e77cb610
commit 76a60a007e
1 changed files with 7 additions and 3 deletions

View File

@ -111,20 +111,24 @@ public class HdfsDataSegmentPusher implements DataSegmentPusher
fs fs
); );
Path outDir = new Path(String.format("%s/%s", config.getStorageDirectory(), storageDir)); Path outDir = new Path(String.format("%s/%s", config.getStorageDirectory(), storageDir));
// Create parent if it does not exist, recreation is not an error
fs.mkdirs(outDir.getParent());
if (!fs.rename(tmpFile.getParent(), outDir)) { if (!fs.rename(tmpFile.getParent(), outDir)) {
if (!fs.delete(tmpFile.getParent(), true)) { if (!fs.delete(tmpFile.getParent(), true)) {
log.error("Failed to delete temp directory[%s]", tmpFile); 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.",
tmpFile, tmpFile.getParent(),
outDir outDir
); );
} else { } else {
throw new IOException(String.format( throw new IOException(String.format(
"Failed to rename temp directory[%s] and segment directory[%s] is not present.", "Failed to rename temp directory[%s] and segment directory[%s] is not present.",
tmpFile, tmpFile.getParent(),
outDir outDir
)); ));
} }