From d25c1be517323985132d2a891c210928db7547d7 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 26 Dec 2022 21:19:33 +0800 Subject: [PATCH] HDFS-16861. RBF. Truncate API always fails when dirs use AllResolver oder on Router (#5184) Co-authored-by: xiezhineng Reviewed-by: Inigo Goiri Signed-off-by: Tao Li --- .../federation/router/RouterClientProtocol.java | 3 ++- .../federation/router/TestRouterAllResolver.java | 14 ++++++++++++++ 2 files changed, 16 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 a5f83c95b7b..ee8ae5885a6 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 @@ -702,8 +702,9 @@ public class RouterClientProtocol implements ClientProtocol { RemoteMethod method = new RemoteMethod("truncate", new Class[] {String.class, long.class, String.class}, new RemoteParam(), newLength, clientName); + // Truncate can return true/false, so don't expect a result return rpcClient.invokeSequential(locations, method, Boolean.class, - Boolean.TRUE); + null); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAllResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAllResolver.java index 715b627f694..075917bfbe0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAllResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAllResolver.java @@ -33,6 +33,7 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.NamenodeContext; import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext; @@ -46,6 +47,7 @@ import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntr import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesRequest; import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse; import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; +import org.apache.hadoop.hdfs.server.namenode.TestFileTruncate; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -191,6 +193,18 @@ public class TestRouterAllResolver { assertDirsEverywhere(path, 9); assertFilesDistributed(path, 15); + // Test truncate + String testTruncateFile = path + "/dir2/dir22/dir220/file-truncate.txt"; + createTestFile(routerFs, testTruncateFile); + Path testTruncateFilePath = new Path(testTruncateFile); + routerFs.truncate(testTruncateFilePath, 10); + TestFileTruncate.checkBlockRecovery(testTruncateFilePath, + (DistributedFileSystem) routerFs); + assertEquals("Truncate file fails", 10, + routerFs.getFileStatus(testTruncateFilePath).getLen()); + assertDirsEverywhere(path, 9); + assertFilesDistributed(path, 16); + // Removing a directory should remove it from every subcluster routerFs.delete(new Path(path + "/dir2/dir22/dir220"), true); assertDirsEverywhere(path, 8);