Skip to content

Commit a52f6bb

Browse files
S O'Donnellzmolnar-inf
authored andcommitted
CDPD-34438 HOTREQ-446. HDFS-16144. Revert HDFS-15372 (Files in snapshots no longer see attribute provider permissions). Contributed by Stephen O'Donnell
(cherry picked from commit f5d323d3cbcd961274b23fecfc5c21c48c8a8346) Change-Id: I1da570fe28d3fd913ffb0903ce5ee3504aecad26
1 parent 132ad66 commit a52f6bb

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestINodeAttributeProvider.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Set;
2626

2727
import com.google.common.collect.ImmutableList;
28+
import org.apache.hadoop.hdfs.DistributedFileSystem;
2829

2930
import org.apache.hadoop.conf.Configuration;
3031
import org.apache.hadoop.fs.FileStatus;
@@ -35,6 +36,7 @@
3536
import org.apache.hadoop.hdfs.DFSConfigKeys;
3637
import org.apache.hadoop.hdfs.HdfsConfiguration;
3738
import org.apache.hadoop.hdfs.MiniDFSCluster;
39+
import org.apache.hadoop.hdfs.DFSTestUtil;
3840
import org.apache.hadoop.security.AccessControlException;
3941
import org.apache.hadoop.security.UserGroupInformation;
4042
import org.junit.After;
@@ -87,7 +89,8 @@ public void checkPermissionWithContext(
8789
AuthorizationContext authzContext) throws AccessControlException {
8890
if (authzContext.getAncestorIndex() > 1
8991
&& authzContext.getInodes()[1].getLocalName().equals("user")
90-
&& authzContext.getInodes()[2].getLocalName().equals("acl")) {
92+
&& authzContext.getInodes()[2].getLocalName().equals("acl")
93+
|| runPermissionCheck) {
9194
this.ace.checkPermissionWithContext(authzContext);
9295
}
9396
CALLED.add("checkPermission|" + authzContext.getAncestorAccess()
@@ -485,4 +488,65 @@ public Void run() throws Exception {
485488
}
486489
});
487490
}
491+
492+
@Test
493+
// See HDFS-16132 where an issue was reported after HDFS-15372. The sequence
494+
// of operations here causes that change to break and the test fails with:
495+
// org.apache.hadoop.ipc.RemoteException(java.lang.AssertionError):
496+
// Absolute path required, but got 'foo'
497+
// at org.apache.hadoop.hdfs.server.namenode.INode.checkAbsolutePath
498+
// (INode.java:838)
499+
// at org.apache.hadoop.hdfs.server.namenode.INode.getPathComponents
500+
// (INode.java:813)
501+
// After reverting HDFS-15372 the test passes, so including this test in the
502+
// revert for future reference.
503+
public void testAttrProviderWorksCorrectlyOnRenamedSnapshotPaths()
504+
throws Exception {
505+
runPermissionCheck = true;
506+
FileSystem fs = FileSystem.get(miniDFS.getConfiguration(0));
507+
DistributedFileSystem hdfs = miniDFS.getFileSystem();
508+
final Path parent = new Path("/user");
509+
hdfs.mkdirs(parent);
510+
fs.setPermission(parent, new FsPermission(HDFS_PERMISSION));
511+
final Path sub1 = new Path(parent, "sub1");
512+
final Path sub1foo = new Path(sub1, "foo");
513+
hdfs.mkdirs(sub1);
514+
hdfs.mkdirs(sub1foo);
515+
Path f = new Path(sub1foo, "file0");
516+
DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0);
517+
hdfs.allowSnapshot(parent);
518+
hdfs.createSnapshot(parent, "s0");
519+
520+
f = new Path(sub1foo, "file1");
521+
DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0);
522+
f = new Path(sub1foo, "file2");
523+
DFSTestUtil.createFile(hdfs, f, 0, (short) 1, 0);
524+
525+
final Path sub2 = new Path(parent, "sub2");
526+
hdfs.mkdirs(sub2);
527+
final Path sub2foo = new Path(sub2, "foo");
528+
// mv /parent/sub1/foo to /parent/sub2/foo
529+
hdfs.rename(sub1foo, sub2foo);
530+
531+
hdfs.createSnapshot(parent, "s1");
532+
hdfs.createSnapshot(parent, "s2");
533+
534+
final Path sub3 = new Path(parent, "sub3");
535+
hdfs.mkdirs(sub3);
536+
// mv /parent/sub2/foo to /parent/sub3/foo
537+
hdfs.rename(sub2foo, sub3);
538+
539+
hdfs.delete(sub3, true);
540+
UserGroupInformation ugi =
541+
UserGroupInformation.createUserForTesting("u1", new String[] {"g1"});
542+
ugi.doAs(new PrivilegedExceptionAction<Void>() {
543+
@Override
544+
public Void run() throws Exception {
545+
FileSystem fs = FileSystem.get(miniDFS.getConfiguration(0));
546+
((DistributedFileSystem)fs).getSnapshotDiffReport(parent, "s1", "s2");
547+
CALLED.clear();
548+
return null;
549+
}
550+
});
551+
}
488552
}

0 commit comments

Comments
 (0)