Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 578EB200AC8 for ; Tue, 7 Jun 2016 22:26:15 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5606A160968; Tue, 7 Jun 2016 20:26:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7AE40160A4F for ; Tue, 7 Jun 2016 22:26:14 +0200 (CEST) Received: (qmail 83824 invoked by uid 500); 7 Jun 2016 20:25:55 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 81702 invoked by uid 99); 7 Jun 2016 20:25:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jun 2016 20:25:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D84CEDFABB; Tue, 7 Jun 2016 20:25:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jianhe@apache.org To: common-commits@hadoop.apache.org Date: Tue, 07 Jun 2016 20:26:36 -0000 Message-Id: In-Reply-To: <683f6ba9e8d840a6b940e3d8147b7a0b@git.apache.org> References: <683f6ba9e8d840a6b940e3d8147b7a0b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [44/50] [abbrv] hadoop git commit: HDFS-10458. getFileEncryptionInfo should return quickly for non-encrypted cluster. archived-at: Tue, 07 Jun 2016 20:26:15 -0000 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 Zhang Authored: 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 EncryptionZoneManager { */ String[] getKeyNames() { assert dir.hasReadLock(); + if (!hasCreatedEncryptionZone()) { + return new String[0]; + } String[] ret = new String[encryptionZones.size()]; int index = 0; for (Map.Entry entry : encryptionZones 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/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 bd25419..2997179 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 @@ -254,7 +254,7 @@ final class FSDirEncryptionZoneOp { static FileEncryptionInfo getFileEncryptionInfo(final FSDirectory fsd, final INode inode, final int snapshotId, final INodesInPath iip) throws IOException { - if (!inode.isFile()) { + if (!inode.isFile() || !fsd.ezManager.hasCreatedEncryptionZone()) { return null; } fsd.readLock(); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org