HDFS-13192. Change the code order in getFileEncryptionInfo to avoid unnecessary call of assignment. Contributed by LiXin Ge.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/cd4a97bf Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/cd4a97bf Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/cd4a97bf Branch: refs/heads/HDFS-7240 Commit: cd4a97bf80f1170175447b95b95ce78d717d86ff Parents: 225d877 Author: Inigo Goiri <inigo...@apache.org> Authored: Tue Feb 27 08:53:00 2018 -0800 Committer: Inigo Goiri <inigo...@apache.org> Committed: Tue Feb 27 08:53:00 2018 -0800 ---------------------------------------------------------------------- .../server/namenode/FSDirEncryptionZoneOp.java | 8 ++--- .../apache/hadoop/hdfs/TestEncryptionZones.java | 33 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/cd4a97bf/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java index 9fbdaeb..bf5652d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirEncryptionZoneOp.java @@ -456,17 +456,17 @@ final class FSDirEncryptionZoneOp { } } - final CryptoProtocolVersion version = encryptionZone.getVersion(); - final CipherSuite suite = encryptionZone.getSuite(); - final String keyName = encryptionZone.getKeyName(); XAttr fileXAttr = FSDirXAttrOp.unprotectedGetXAttrByPrefixedName( iip, CRYPTO_XATTR_FILE_ENCRYPTION_INFO); - if (fileXAttr == null) { NameNode.LOG.warn("Could not find encryption XAttr for file " + iip.getPath() + " in encryption zone " + encryptionZone.getPath()); return null; } + + final CryptoProtocolVersion version = encryptionZone.getVersion(); + final CipherSuite suite = encryptionZone.getSuite(); + final String keyName = encryptionZone.getKeyName(); try { HdfsProtos.PerFileEncryptionInfoProto fileProto = HdfsProtos.PerFileEncryptionInfoProto.parseFrom( http://git-wip-us.apache.org/repos/asf/hadoop/blob/cd4a97bf/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java index cf13057..e2d307a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java @@ -1419,6 +1419,39 @@ public class TestEncryptionZones { } /** + * Test correctness of encryption zones on a existing snapshot path. + * Specifically, test the file in encryption zones with no encryption info + */ + @Test + public void testSnapshotWithFile() throws Exception { + final int len = 8196; + final Path zoneParent = new Path("/zones"); + final Path zone = new Path(zoneParent, "zone"); + final Path zoneFile = new Path(zone, "zoneFile"); + fsWrapper.mkdir(zone, FsPermission.getDirDefault(), true); + DFSTestUtil.createFile(fs, zoneFile, len, (short) 1, 0xFEED); + String contents = DFSTestUtil.readFile(fs, zoneFile); + + // Create the snapshot which contains the file + dfsAdmin.allowSnapshot(zoneParent); + final Path snap1 = fs.createSnapshot(zoneParent, "snap1"); + + // Now delete the file and create encryption zone + fsWrapper.delete(zoneFile, false); + dfsAdmin.createEncryptionZone(zone, TEST_KEY, NO_TRASH); + assertEquals("Got unexpected ez path", zone.toString(), + dfsAdmin.getEncryptionZoneForPath(zone).getPath()); + + // The file in snapshot shouldn't have any encryption info + final Path snapshottedZoneFile = new Path( + snap1 + "/" + zone.getName() + "/" + zoneFile.getName()); + FileEncryptionInfo feInfo = getFileEncryptionInfo(snapshottedZoneFile); + assertNull("Expected null ez info", feInfo); + assertEquals("Contents of snapshotted file have changed unexpectedly", + contents, DFSTestUtil.readFile(fs, snapshottedZoneFile)); + } + + /** * Verify symlinks can be created in encryption zones and that * they function properly when the target is in the same * or different ez. --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org