HDFS-13192. Change the code order in getFileEncryptionInfo to avoid unnecessary call of assignment. Contributed by LiXin Ge.
This commit is contained in:
parent
225d877092
commit
cd4a97bf80
|
@ -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(
|
||||
|
|
|
@ -1418,6 +1418,39 @@ public class TestEncryptionZones {
|
|||
dfsAdmin.getEncryptionZoneForPath(snap3Zone).getPath().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Reference in New Issue