Browse Source

HDFS-14741. RBF: RecoverLease should be return false when the file is open in multiple destination. Contributed by xuzq

Ayush Saxena 5 years ago
parent
commit
52c77bc160

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java

@@ -363,7 +363,7 @@ public class RouterClientProtocol implements ClientProtocol {
         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;
   }
 

+ 25 - 0
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java

@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.server.federation.router;
 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.Random;
 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.federation.resolver.RemoteLocation;
 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 class TestRouterRpcMultiDestination extends TestRouterRpc {
     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 =