From b3bc94ebfd7cbf959bd33b8d85be80c4a8a46574 Mon Sep 17 00:00:00 2001 From: Hanisha Koneru Date: Tue, 29 Jan 2019 16:45:44 -0800 Subject: [PATCH] HDFS-14236. Lazy persist copy/ put fails with ViewFs. --- .../hadoop/fs/shell/CommandWithDestination.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java index 0bd48827f2..2421f06dd9 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java @@ -44,6 +44,7 @@ import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclUtil; import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.fs.viewfs.NotInMountpointException; import org.apache.hadoop.io.IOUtils; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT; @@ -494,6 +495,17 @@ FSDataOutputStream create(PathData item, boolean lazyPersist, throws IOException { try { if (lazyPersist) { + long defaultBlockSize; + try { + defaultBlockSize = getDefaultBlockSize(); + } catch (NotInMountpointException ex) { + // ViewFileSystem#getDefaultBlockSize() throws an exception as it + // needs a target FS to retrive the default block size from. + // Hence, for ViewFs, we should call getDefaultBlockSize with the + // target path. + defaultBlockSize = getDefaultBlockSize(item.path); + } + EnumSet createFlags = EnumSet.of(CREATE, LAZY_PERSIST); return create(item.path, FsPermission.getFileDefault().applyUMask( @@ -502,7 +514,7 @@ FSDataOutputStream create(PathData item, boolean lazyPersist, getConf().getInt(IO_FILE_BUFFER_SIZE_KEY, IO_FILE_BUFFER_SIZE_DEFAULT), (short) 1, - getDefaultBlockSize(), + defaultBlockSize, null, null); } else {