From 52c77bc1607421037f6f84f695f607bb89b97cb6 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Thu, 22 Aug 2019 08:57:22 +0530 Subject: [PATCH] HDFS-14741. RBF: RecoverLease should be return false when the file is open in multiple destination. Contributed by xuzq --- .../router/RouterClientProtocol.java | 2 +- .../router/TestRouterRpcMultiDestination.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java index 4d8527f906..95787a1b01 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java @@ -363,7 +363,7 @@ public boolean recoverLease(String src, String clientName) new Class[] {String.class, String.class}, new RemoteParam(), clientName); Object result = rpcClient.invokeSequential( - locations, method, Boolean.class, Boolean.TRUE); + locations, method, Boolean.class, null); return (boolean) result; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java index 306a455506..62e90770eb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java @@ -20,6 +20,7 @@ import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.createFile; import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.verifyFileExists; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -38,6 +39,7 @@ import java.util.Set; import java.util.TreeSet; +import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; @@ -55,6 +57,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.ha.HAContext; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.StandbyException; import org.apache.hadoop.test.GenericTestUtils; @@ -230,6 +233,28 @@ public void testProxyRenameFiles() throws IOException, InterruptedException { testRename2(getRouterContext(), filename1, renamedFile, false); } + /** + * Test recoverLease when the result is false. + */ + @Test + public void testRecoverLease() throws Exception { + Path testPath = new Path("/recovery/test_recovery_lease"); + DistributedFileSystem routerFs = + (DistributedFileSystem) getRouterFileSystem(); + FSDataOutputStream fsDataOutputStream = null; + try { + fsDataOutputStream = routerFs.create(testPath); + fsDataOutputStream.write("hello world".getBytes()); + fsDataOutputStream.hflush(); + + boolean result = routerFs.recoverLease(testPath); + assertFalse(result); + } finally { + IOUtils.closeStream(fsDataOutputStream); + routerFs.delete(testPath, true); + } + } + @Test public void testGetContentSummaryEc() throws Exception { DistributedFileSystem routerDFS =