HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
(cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) (cherry picked from commit 06e38c835d0ad9619d4bea662f2dd7d0f62007a9) (cherry picked from commit 0274636529cfac4d64582a7c21631aebbf4deb1b)
This commit is contained in:
parent
97e79662b6
commit
9b68eda274
@ -97,7 +97,7 @@ String getKeyName() {
|
||||
}
|
||||
}
|
||||
|
||||
private final TreeMap<Long, EncryptionZoneInt> encryptionZones;
|
||||
private TreeMap<Long, EncryptionZoneInt> encryptionZones = null;
|
||||
private final FSDirectory dir;
|
||||
private final int maxListEncryptionZonesResponses;
|
||||
|
||||
@ -108,7 +108,6 @@ String getKeyName() {
|
||||
*/
|
||||
public EncryptionZoneManager(FSDirectory dir, Configuration conf) {
|
||||
this.dir = dir;
|
||||
encryptionZones = new TreeMap<Long, EncryptionZoneInt>();
|
||||
maxListEncryptionZonesResponses = conf.getInt(
|
||||
DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES,
|
||||
DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT
|
||||
@ -145,6 +144,9 @@ void unprotectedAddEncryptionZone(Long inodeId,
|
||||
CipherSuite suite, CryptoProtocolVersion version, String keyName) {
|
||||
final EncryptionZoneInt ez = new EncryptionZoneInt(
|
||||
inodeId, suite, version, keyName);
|
||||
if (encryptionZones == null) {
|
||||
encryptionZones = new TreeMap<>();
|
||||
}
|
||||
encryptionZones.put(inodeId, ez);
|
||||
}
|
||||
|
||||
@ -155,7 +157,9 @@ void unprotectedAddEncryptionZone(Long inodeId,
|
||||
*/
|
||||
void removeEncryptionZone(Long inodeId) {
|
||||
assert dir.hasWriteLock();
|
||||
encryptionZones.remove(inodeId);
|
||||
if (hasCreatedEncryptionZone()) {
|
||||
encryptionZones.remove(inodeId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,6 +207,9 @@ String getKeyName(final INodesInPath iip) {
|
||||
private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) {
|
||||
assert dir.hasReadLock();
|
||||
Preconditions.checkNotNull(iip);
|
||||
if (!hasCreatedEncryptionZone()) {
|
||||
return null;
|
||||
}
|
||||
List<INode> inodes = iip.getReadOnlyINodes();
|
||||
for (int i = inodes.size() - 1; i >= 0; i--) {
|
||||
final INode inode = inodes.get(i);
|
||||
@ -340,6 +347,10 @@ XAttr createEncryptionZone(String src, CipherSuite suite,
|
||||
BatchedListEntries<EncryptionZone> listEncryptionZones(long prevId)
|
||||
throws IOException {
|
||||
assert dir.hasReadLock();
|
||||
if (!hasCreatedEncryptionZone()) {
|
||||
final List<EncryptionZone> emptyZones = Lists.newArrayList();
|
||||
return new BatchedListEntries<>(emptyZones, false);
|
||||
}
|
||||
NavigableMap<Long, EncryptionZoneInt> tailMap = encryptionZones.tailMap
|
||||
(prevId, false);
|
||||
final int numResponses = Math.min(maxListEncryptionZonesResponses,
|
||||
@ -374,4 +385,14 @@ BatchedListEntries<EncryptionZone> listEncryptionZones(long prevId)
|
||||
final boolean hasMore = (numResponses < tailMap.size());
|
||||
return new BatchedListEntries<EncryptionZone>(zones, hasMore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether there has been any attempt to create an encryption zone in
|
||||
* the cluster at all. If not, it is safe to quickly return null when
|
||||
* checking the encryption information of any file or directory in the
|
||||
* cluster.
|
||||
*/
|
||||
public boolean hasCreatedEncryptionZone() {
|
||||
return encryptionZones != null;
|
||||
}
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ void setFileEncryptionInfo(String src, FileEncryptionInfo info)
|
||||
*/
|
||||
FileEncryptionInfo getFileEncryptionInfo(INode inode, int snapshotId,
|
||||
INodesInPath iip) throws IOException {
|
||||
if (!inode.isFile()) {
|
||||
if (!inode.isFile() || !ezManager.hasCreatedEncryptionZone()) {
|
||||
return null;
|
||||
}
|
||||
readLock();
|
||||
|
Loading…
x
Reference in New Issue
Block a user