[21/50] [abbrv] hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6de9213d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6de9213d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6de9213d Branch: refs/heads/HDFS-7240 Commit: 6de9213df111a9a4ed875db995d67af72d08a798 Parents: a3f78d8 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:52:39 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/6de9213d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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; } /** @@ -387,6 +409,9 @@ public class
[44/50] [abbrv] hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6de9213d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6de9213d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6de9213d Branch: refs/heads/YARN-4757 Commit: 6de9213df111a9a4ed875db995d67af72d08a798 Parents: a3f78d8 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:52:39 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/6de9213d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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; } /** @@ -387,6 +409,9 @@ public class
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2.6 7fe08d762 -> 1b00cebcd HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. (cherry picked from commit 9b68eda2746702246c7f4b4abe412c974ba56339) (cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) (cherry picked from commit 06e38c835d0ad9619d4bea662f2dd7d0f62007a9) (cherry picked from commit 0274636529cfac4d64582a7c21631aebbf4deb1b) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/1b00cebc Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/1b00cebc Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/1b00cebc Branch: refs/heads/branch-2.6 Commit: 1b00cebcdb378ab510e81dc85c62674af764da53 Parents: 7fe08d7 Author: Zhe ZhangAuthored: Tue Jun 7 10:42:19 2016 -0700 Committer: Zhe Zhang Committed: Tue Jun 7 10:42:19 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 27 +--- .../hdfs/server/namenode/FSDirectory.java | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/1b00cebc/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 90b99ce..16ff864 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -97,7 +97,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -108,7 +108,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -145,6 +144,9 @@ public class EncryptionZoneManager { 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 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -203,6 +207,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} final INode[] inodes = iip.getINodes(); for (int i = inodes.length - 1; i >= 0; i--) { final INode inode = inodes[i]; @@ -337,6 +344,10 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + final List emptyZones = Lists.newArrayList(); + return new BatchedListEntries(emptyZones, false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -371,4 +382,14 @@ public class EncryptionZoneManager { final boolean hasMore = (numResponses < tailMap.size()); return new BatchedListEntries(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; + } }
[41/47] hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6de9213d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6de9213d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6de9213d Branch: refs/heads/HDFS-1312 Commit: 6de9213df111a9a4ed875db995d67af72d08a798 Parents: a3f78d8 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:52:39 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/6de9213d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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; } /** @@ -387,6 +409,9 @@ public class
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2.8 738b67e9d -> 72addd8d5 HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. (cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) (cherry picked from commit 06e38c835d0ad9619d4bea662f2dd7d0f62007a9) (cherry picked from commit 0499907466e78a5b674ac72a5503af892adc348f) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/72addd8d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/72addd8d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/72addd8d Branch: refs/heads/branch-2.8 Commit: 72addd8d5c899f61673b348d321d95cc0499fe9e Parents: 738b67e Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Tue Jun 7 09:09:18 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 36 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/72addd8d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..e29d420 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,10 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + final List emptyZones = Lists.newArrayList(); + return new BatchedListEntries(emptyZones, false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +391,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @return Whether there has been any attempt to create an
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2 5b4c80b27 -> 049990746 HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. (cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) (cherry picked from commit 06e38c835d0ad9619d4bea662f2dd7d0f62007a9) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/04999074 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/04999074 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/04999074 Branch: refs/heads/branch-2 Commit: 0499907466e78a5b674ac72a5503af892adc348f Parents: 5b4c80b Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Tue Jun 7 08:57:27 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 36 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/04999074/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..e29d420 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,10 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + final List emptyZones = Lists.newArrayList(); + return new BatchedListEntries(emptyZones, false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +391,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @return Whether there has been any attempt to create an encryption zone in + * the cluster at all. If not, it is safe to quickly
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2.7 97e79662b -> 9b68eda27 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) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/9b68eda2 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/9b68eda2 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/9b68eda2 Branch: refs/heads/branch-2.7 Commit: 9b68eda2746702246c7f4b4abe412c974ba56339 Parents: 97e7966 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 16:09:14 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 27 +--- .../hdfs/server/namenode/FSDirectory.java | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/9b68eda2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 5aa9e1c..bda7aba 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -97,7 +97,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -108,7 +108,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -145,6 +144,9 @@ public class EncryptionZoneManager { 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 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -203,6 +207,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -340,6 +347,10 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + final List emptyZones = Lists.newArrayList(); + return new BatchedListEntries<>(emptyZones, false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -374,4 +385,14 @@ public class EncryptionZoneManager { final boolean hasMore = (numResponses < tailMap.size()); return new BatchedListEntries(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; + } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/9b68eda2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2.8 ec4f9a14f -> 027463652 HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. (cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) (cherry picked from commit 06e38c835d0ad9619d4bea662f2dd7d0f62007a9) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/02746365 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/02746365 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/02746365 Branch: refs/heads/branch-2.8 Commit: 0274636529cfac4d64582a7c21631aebbf4deb1b Parents: ec4f9a1 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:54:36 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/02746365/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/branch-2 0cbbc2f0d -> 06e38c835 HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. (cherry picked from commit 6de9213df111a9a4ed875db995d67af72d08a798) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/06e38c83 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/06e38c83 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/06e38c83 Branch: refs/heads/branch-2 Commit: 06e38c835d0ad9619d4bea662f2dd7d0f62007a9 Parents: 0cbbc2f Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:53:12 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/06e38c83/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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. +
hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster.
Repository: hadoop Updated Branches: refs/heads/trunk a3f78d8fa -> 6de9213df HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6de9213d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6de9213d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6de9213d Branch: refs/heads/trunk Commit: 6de9213df111a9a4ed875db995d67af72d08a798 Parents: a3f78d8 Author: Zhe ZhangAuthored: Mon Jun 6 15:52:39 2016 -0700 Committer: Zhe Zhang Committed: Mon Jun 6 15:52:39 2016 -0700 -- .../server/namenode/EncryptionZoneManager.java | 35 +--- .../server/namenode/FSDirEncryptionZoneOp.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/6de9213d/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java -- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 8454c04..41dbb59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -95,7 +95,7 @@ public class EncryptionZoneManager { } } - private final TreeMap encryptionZones; + private TreeMap encryptionZones = null; private final FSDirectory dir; private final int maxListEncryptionZonesResponses; @@ -106,7 +106,6 @@ public class EncryptionZoneManager { */ public EncryptionZoneManager(FSDirectory dir, Configuration conf) { this.dir = dir; -encryptionZones = new TreeMap (); maxListEncryptionZonesResponses = conf.getInt( DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES, DFSConfigKeys.DFS_NAMENODE_LIST_ENCRYPTION_ZONES_NUM_RESPONSES_DEFAULT @@ -143,6 +142,9 @@ public class EncryptionZoneManager { 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); } @@ -153,7 +155,9 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); -encryptionZones.remove(inodeId); +if (hasCreatedEncryptionZone()) { + encryptionZones.remove(inodeId); +} } /** @@ -201,6 +205,9 @@ public class EncryptionZoneManager { private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { assert dir.hasReadLock(); Preconditions.checkNotNull(iip); +if (!hasCreatedEncryptionZone()) { + return null; +} List inodes = iip.getReadOnlyINodes(); for (int i = inodes.size() - 1; i >= 0; i--) { final INode inode = inodes.get(i); @@ -313,7 +320,8 @@ public class EncryptionZoneManager { throw new IOException("Attempt to create an encryption zone for a file."); } -if (encryptionZones.get(srcINode.getId()) != null) { +if (hasCreatedEncryptionZone() && encryptionZones. +get(srcINode.getId()) != null) { throw new IOException("Directory " + src + " is already an encryption " + "zone."); } @@ -340,6 +348,9 @@ public class EncryptionZoneManager { BatchedListEntries listEncryptionZones(long prevId) throws IOException { assert dir.hasReadLock(); +if (!hasCreatedEncryptionZone()) { + return new BatchedListEntries(Lists.newArrayList(), false); +} NavigableMap tailMap = encryptionZones.tailMap (prevId, false); final int numResponses = Math.min(maxListEncryptionZonesResponses, @@ -379,7 +390,18 @@ public class EncryptionZoneManager { * @return number of encryption zones. */ public int getNumEncryptionZones() { -return encryptionZones.size(); +return hasCreatedEncryptionZone() ? +encryptionZones.size() : 0; + } + + /** + * @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