Return-Path: X-Original-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1F5D511DB6 for ; Tue, 22 Jul 2014 00:55:43 +0000 (UTC) Received: (qmail 71203 invoked by uid 500); 22 Jul 2014 00:55:43 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 71150 invoked by uid 500); 22 Jul 2014 00:55:42 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 71133 invoked by uid 99); 22 Jul 2014 00:55:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jul 2014 00:55:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jul 2014 00:55:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3AABC23889EB; Tue, 22 Jul 2014 00:55:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1612439 - in /hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs: CHANGES-fs-encryption.txt src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java Date: Tue, 22 Jul 2014 00:55:21 -0000 To: hdfs-commits@hadoop.apache.org From: wang@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140722005521.3AABC23889EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: wang Date: Tue Jul 22 00:55:20 2014 New Revision: 1612439 URL: http://svn.apache.org/r1612439 Log: HDFS-6718. Remove EncryptionZoneManager lock. (wang) Modified: hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java Modified: hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt?rev=1612439&r1=1612438&r2=1612439&view=diff ============================================================================== --- hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt (original) +++ hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/CHANGES-fs-encryption.txt Tue Jul 22 00:55:20 2014 @@ -52,6 +52,8 @@ fs-encryption (Unreleased) HDFS-6716. Update usage of KeyProviderCryptoExtension APIs on NameNode. (wang) + HDFS-6718. Remove EncryptionZoneManager lock. (wang) + OPTIMIZATIONS BUG FIXES Modified: hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java?rev=1612439&r1=1612438&r2=1612439&view=diff ============================================================================== --- hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java (original) +++ hadoop/common/branches/fs-encryption/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java Tue Jul 22 00:55:20 2014 @@ -60,35 +60,6 @@ public class EncryptionZoneManager { } - /** - * Protects the encryptionZones map and its contents. - */ - private final ReentrantReadWriteLock lock; - - private void readLock() { - lock.readLock().lock(); - } - - private void readUnlock() { - lock.readLock().unlock(); - } - - private void writeLock() { - lock.writeLock().lock(); - } - - private void writeUnlock() { - lock.writeLock().unlock(); - } - - public boolean hasWriteLock() { - return lock.isWriteLockedByCurrentThread(); - } - - public boolean hasReadLock() { - return lock.getReadHoldCount() > 0 || hasWriteLock(); - } - private final Map encryptionZones; private final FSDirectory dir; private final KeyProvider provider; @@ -101,7 +72,6 @@ public class EncryptionZoneManager { public EncryptionZoneManager(FSDirectory dir, KeyProvider provider) { this.dir = dir; this.provider = provider; - lock = new ReentrantReadWriteLock(); encryptionZones = new HashMap(); } @@ -116,12 +86,7 @@ public class EncryptionZoneManager { void addEncryptionZone(Long inodeId, String keyId) { assert dir.hasWriteLock(); final EncryptionZoneInt ez = new EncryptionZoneInt(inodeId, keyId); - writeLock(); - try { - encryptionZones.put(inodeId, ez); - } finally { - writeUnlock(); - } + encryptionZones.put(inodeId, ez); } /** @@ -131,12 +96,7 @@ public class EncryptionZoneManager { */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); - writeLock(); - try { - encryptionZones.remove(inodeId); - } finally { - writeUnlock(); - } + encryptionZones.remove(inodeId); } /** @@ -147,12 +107,7 @@ public class EncryptionZoneManager { boolean isInAnEZ(INodesInPath iip) throws UnresolvedLinkException, SnapshotAccessControlException { assert dir.hasReadLock(); - readLock(); - try { - return (getEncryptionZoneForPath(iip) != null); - } finally { - readUnlock(); - } + return (getEncryptionZoneForPath(iip) != null); } /** @@ -172,16 +127,12 @@ public class EncryptionZoneManager { * Called while holding the FSDirectory lock. */ String getKeyName(final INodesInPath iip) { - readLock(); - try { - EncryptionZoneInt ezi = getEncryptionZoneForPath(iip); - if (ezi == null) { - return null; - } - return ezi.getKeyName(); - } finally { - readUnlock(); + assert dir.hasReadLock(); + EncryptionZoneInt ezi = getEncryptionZoneForPath(iip); + if (ezi == null) { + return null; } + return ezi.getKeyName(); } /** @@ -191,7 +142,7 @@ public class EncryptionZoneManager { * Must be called while holding the manager lock. */ private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) { - assert hasReadLock(); + assert dir.hasReadLock(); Preconditions.checkNotNull(iip); final INode[] inodes = iip.getINodes(); for (int i = inodes.length - 1; i >= 0; i--) { @@ -220,41 +171,36 @@ public class EncryptionZoneManager { void checkMoveValidity(INodesInPath srcIIP, INodesInPath dstIIP, String src) throws IOException { assert dir.hasReadLock(); - readLock(); - try { - final EncryptionZoneInt srcEZI = getEncryptionZoneForPath(srcIIP); - final EncryptionZoneInt dstEZI = getEncryptionZoneForPath(dstIIP); - final boolean srcInEZ = (srcEZI != null); - final boolean dstInEZ = (dstEZI != null); - if (srcInEZ) { - if (!dstInEZ) { - throw new IOException( - src + " can't be moved from an encryption zone."); - } - } else { - if (dstInEZ) { - throw new IOException( - src + " can't be moved into an encryption zone."); - } + final EncryptionZoneInt srcEZI = getEncryptionZoneForPath(srcIIP); + final EncryptionZoneInt dstEZI = getEncryptionZoneForPath(dstIIP); + final boolean srcInEZ = (srcEZI != null); + final boolean dstInEZ = (dstEZI != null); + if (srcInEZ) { + if (!dstInEZ) { + throw new IOException( + src + " can't be moved from an encryption zone."); + } + } else { + if (dstInEZ) { + throw new IOException( + src + " can't be moved into an encryption zone."); } + } - if (srcInEZ || dstInEZ) { - Preconditions.checkState(srcEZI != null, "couldn't find src EZ?"); - Preconditions.checkState(dstEZI != null, "couldn't find dst EZ?"); - if (srcEZI != dstEZI) { - final String srcEZPath = getFullPathName(srcEZI); - final String dstEZPath = getFullPathName(dstEZI); - final StringBuilder sb = new StringBuilder(src); - sb.append(" can't be moved from encryption zone "); - sb.append(srcEZPath); - sb.append(" to encryption zone "); - sb.append(dstEZPath); - sb.append("."); - throw new IOException(sb.toString()); - } + if (srcInEZ || dstInEZ) { + Preconditions.checkState(srcEZI != null, "couldn't find src EZ?"); + Preconditions.checkState(dstEZI != null, "couldn't find dst EZ?"); + if (srcEZI != dstEZI) { + final String srcEZPath = getFullPathName(srcEZI); + final String dstEZPath = getFullPathName(dstEZI); + final StringBuilder sb = new StringBuilder(src); + sb.append(" can't be moved from encryption zone "); + sb.append(srcEZPath); + sb.append(" to encryption zone "); + sb.append(dstEZPath); + sb.append("."); + throw new IOException(sb.toString()); } - } finally { - readUnlock(); } } @@ -266,34 +212,29 @@ public class EncryptionZoneManager { XAttr createEncryptionZone(String src, String keyId, KeyVersion keyVersion) throws IOException { assert dir.hasWriteLock(); - writeLock(); - try { - if (dir.isNonEmptyDirectory(src)) { - throw new IOException( - "Attempt to create an encryption zone for a non-empty directory."); - } - - final INodesInPath srcIIP = dir.getINodesInPath4Write(src, false); - EncryptionZoneInt ezi = getEncryptionZoneForPath(srcIIP); - if (ezi != null) { - throw new IOException("Directory " + src + " is already in an " + - "encryption zone. (" + getFullPathName(ezi) + ")"); - } - - final XAttr keyIdXAttr = XAttrHelper - .buildXAttr(CRYPTO_XATTR_ENCRYPTION_ZONE, keyId.getBytes()); - - final List xattrs = Lists.newArrayListWithCapacity(1); - xattrs.add(keyIdXAttr); - // updating the xattr will call addEncryptionZone, - // done this way to handle edit log loading - dir.unprotectedSetXAttrs(src, xattrs, EnumSet.of(XAttrSetFlag.CREATE)); - // Re-get the new encryption zone add the latest key version - ezi = getEncryptionZoneForPath(srcIIP); - return keyIdXAttr; - } finally { - writeUnlock(); - } + if (dir.isNonEmptyDirectory(src)) { + throw new IOException( + "Attempt to create an encryption zone for a non-empty directory."); + } + + final INodesInPath srcIIP = dir.getINodesInPath4Write(src, false); + EncryptionZoneInt ezi = getEncryptionZoneForPath(srcIIP); + if (ezi != null) { + throw new IOException("Directory " + src + " is already in an " + + "encryption zone. (" + getFullPathName(ezi) + ")"); + } + + final XAttr keyIdXAttr = XAttrHelper + .buildXAttr(CRYPTO_XATTR_ENCRYPTION_ZONE, keyId.getBytes()); + + final List xattrs = Lists.newArrayListWithCapacity(1); + xattrs.add(keyIdXAttr); + // updating the xattr will call addEncryptionZone, + // done this way to handle edit log loading + dir.unprotectedSetXAttrs(src, xattrs, EnumSet.of(XAttrSetFlag.CREATE)); + // Re-get the new encryption zone add the latest key version + ezi = getEncryptionZoneForPath(srcIIP); + return keyIdXAttr; } /** @@ -303,16 +244,11 @@ public class EncryptionZoneManager { */ List listEncryptionZones() throws IOException { assert dir.hasReadLock(); - readLock(); - try { - final List ret = - Lists.newArrayListWithExpectedSize(encryptionZones.size()); - for (EncryptionZoneInt ezi : encryptionZones.values()) { - ret.add(new EncryptionZone(getFullPathName(ezi), ezi.getKeyName())); - } - return ret; - } finally { - readUnlock(); + final List ret = + Lists.newArrayListWithExpectedSize(encryptionZones.size()); + for (EncryptionZoneInt ezi : encryptionZones.values()) { + ret.add(new EncryptionZone(getFullPathName(ezi), ezi.getKeyName())); } + return ret; } }