Skip to content

Commit d2225c8

Browse files
committed
HDFS-14722. RBF: GetMountPointStatus should return mountTable information when getFileInfoAll throw IOException. Contributed by xuzq.
1 parent b661dcf commit d2225c8

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,10 @@ private HdfsFileStatus getMountPointStatus(
19131913
MountTableResolver mountTable = (MountTableResolver) subclusterResolver;
19141914
MountTable entry = mountTable.getMountPoint(mName);
19151915
if (entry != null) {
1916+
permission = entry.getMode();
1917+
owner = entry.getOwnerName();
1918+
group = entry.getGroupName();
1919+
19161920
RemoteMethod method = new RemoteMethod("getFileInfo",
19171921
new Class<?>[] {String.class}, new RemoteParam());
19181922
HdfsFileStatus fInfo = getFileInfoAll(
@@ -1922,10 +1926,6 @@ private HdfsFileStatus getMountPointStatus(
19221926
owner = fInfo.getOwner();
19231927
group = fInfo.getGroup();
19241928
childrenNum = fInfo.getChildrenNum();
1925-
} else {
1926-
permission = entry.getMode();
1927-
owner = entry.getOwnerName();
1928-
group = entry.getGroupName();
19291929
}
19301930
}
19311931
} catch (IOException e) {

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.FileNotFoundException;
2626
import java.io.IOException;
27+
import java.net.URISyntaxException;
2728
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.Iterator;
@@ -53,6 +54,7 @@
5354
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest;
5455
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
5556
import org.apache.hadoop.security.AccessControlException;
57+
import org.apache.hadoop.security.UserGroupInformation;
5658
import org.apache.hadoop.test.LambdaTestUtils;
5759
import org.apache.hadoop.util.Time;
5860
import org.junit.After;
@@ -254,6 +256,61 @@ public void testListFilesTime() throws Exception {
254256
}
255257
}
256258

259+
/**
260+
* Verify that the file/dir status with IOException in getMountPointStatus.
261+
*/
262+
@Test
263+
public void testGetMountPointStatusWithIOException()
264+
throws IOException, InterruptedException {
265+
try {
266+
// Add mount table entry.
267+
MountTable addEntry = MountTable.newInstance("/testA",
268+
Collections.singletonMap("ns0", "/testA"));
269+
assertTrue(addMountTable(addEntry));
270+
addEntry = MountTable.newInstance("/testA/testB",
271+
Collections.singletonMap("ns0", "/testA/testB"));
272+
assertTrue(addMountTable(addEntry));
273+
addEntry = MountTable.newInstance("/testB",
274+
Collections.singletonMap("ns0", "/test1/testB"));
275+
addEntry.setOwnerName("userB");
276+
addEntry.setGroupName("groupB");
277+
assertTrue(addMountTable(addEntry));
278+
279+
assertTrue(nnFs0.mkdirs(new Path("/test1")));
280+
nnFs0.setPermission(new Path("/test1"),
281+
FsPermission.createImmutable((short) 0700));
282+
283+
// Use mock user to getListing through router.
284+
UserGroupInformation user = UserGroupInformation.createUserForTesting(
285+
"mock_user", new String[] {"mock_group"});
286+
LambdaTestUtils.doAs(user, () -> getListing("/testA"));
287+
} finally {
288+
nnFs0.delete(new Path("/test1"), true);
289+
}
290+
}
291+
292+
/**
293+
* GetListing of testPath through router.
294+
*/
295+
private void getListing(String testPath)
296+
throws IOException, URISyntaxException {
297+
ClientProtocol clientProtocol1 =
298+
routerContext.getClient().getNamenode();
299+
DirectoryListing listing = clientProtocol1.getListing(testPath,
300+
HdfsFileStatus.EMPTY_NAME, false);
301+
302+
assertEquals(1, listing.getPartialListing().length);
303+
HdfsFileStatus fileStatus = listing.getPartialListing()[0];
304+
String currentOwner = fileStatus.getOwner();
305+
String currentGroup = fileStatus.getGroup();
306+
String currentFileName =
307+
fileStatus.getFullPath(new Path("/")).getName();
308+
309+
assertEquals("testB", currentFileName);
310+
assertEquals("userB", currentOwner);
311+
assertEquals("groupB", currentGroup);
312+
}
313+
257314
/**
258315
* Verify permission for a mount point when the actual destination is not
259316
* present. It returns the permissions of the mount point.

0 commit comments

Comments
 (0)