From 1fc1b346336bea372b2d5d97756b121d732bfae6 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Mon, 7 Sep 2020 11:36:13 -0700 Subject: [PATCH] HDFS-15558: ViewDistributedFileSystem#recoverLease should call super.recoverLease when there are no mounts configured (#2275) Contributed by Uma Maheswara Rao G. --- .../hdfs/ViewDistributedFileSystem.java | 7 ++++++ .../apache/hadoop/hdfs/TestLeaseRecovery.java | 16 ++++++++++++- .../hdfs/TestViewDistributedFileSystem.java | 23 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java index 0a681693a4..1afb5d9dc2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java @@ -266,6 +266,10 @@ public void setVerifyChecksum(final boolean verifyChecksum) { @Override public boolean recoverLease(final Path f) throws IOException { + if (this.vfs == null) { + return super.recoverLease(f); + } + ViewFileSystemOverloadScheme.MountPathInfo mountPathInfo = this.vfs.getMountPathInfo(f, getConf()); checkDFS(mountPathInfo.getTargetFs(), "recoverLease"); @@ -286,6 +290,9 @@ public FSDataInputStream open(final Path f, final int bufferSize) @Override public FSDataInputStream open(PathHandle fd, int bufferSize) throws IOException { + if (this.vfs == null) { + return super.open(fd, bufferSize); + } return this.vfs.open(fd, bufferSize); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRecovery.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRecovery.java index a1cce3effa..399aa1edaf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRecovery.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestLeaseRecovery.java @@ -280,8 +280,22 @@ public void testBlockRecoveryRetryAfterFailedRecovery() throws Exception { */ @Test public void testLeaseRecoveryAndAppend() throws Exception { + testLeaseRecoveryAndAppend(new Configuration()); + } + + /** + * Recover the lease on a file and append file from another client with + * ViewDFS enabled. + */ + @Test + public void testLeaseRecoveryAndAppendWithViewDFS() throws Exception { Configuration conf = new Configuration(); - try{ + conf.set("fs.hdfs.impl", ViewDistributedFileSystem.class.getName()); + testLeaseRecoveryAndAppend(conf); + } + + private void testLeaseRecoveryAndAppend(Configuration conf) throws Exception { + try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); Path file = new Path("/testLeaseRecovery"); DistributedFileSystem dfs = cluster.getFileSystem(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java index 3c5a0be303..0ba084131b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java @@ -17,9 +17,13 @@ */ package org.apache.hadoop.hdfs; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.PathHandle; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.test.Whitebox; +import org.junit.Test; import java.io.IOException; @@ -44,4 +48,23 @@ public void testStatistics() throws IOException { data.set(null); super.testStatistics(); } + + @Test + public void testOpenWithPathHandle() throws Exception { + Configuration conf = getTestConfiguration(); + MiniDFSCluster cluster = null; + try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); + FileSystem fileSys = cluster.getFileSystem(); + Path openTestPath = new Path("/testOpen"); + fileSys.create(openTestPath).close(); + PathHandle pathHandle = + fileSys.getPathHandle(fileSys.getFileStatus(openTestPath)); + fileSys.open(pathHandle, 1024).close(); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } }