HDFS-6718. Remove EncryptionZoneManager lock. (wang)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1612439 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7b466b3b70
commit
b57ec16567
|
@ -52,6 +52,8 @@ fs-encryption (Unreleased)
|
||||||
HDFS-6716. Update usage of KeyProviderCryptoExtension APIs on NameNode.
|
HDFS-6716. Update usage of KeyProviderCryptoExtension APIs on NameNode.
|
||||||
(wang)
|
(wang)
|
||||||
|
|
||||||
|
HDFS-6718. Remove EncryptionZoneManager lock. (wang)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -60,35 +60,6 @@ public class EncryptionZoneManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Protects the <tt>encryptionZones</tt> 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<Long, EncryptionZoneInt> encryptionZones;
|
private final Map<Long, EncryptionZoneInt> encryptionZones;
|
||||||
private final FSDirectory dir;
|
private final FSDirectory dir;
|
||||||
private final KeyProvider provider;
|
private final KeyProvider provider;
|
||||||
|
@ -101,7 +72,6 @@ public class EncryptionZoneManager {
|
||||||
public EncryptionZoneManager(FSDirectory dir, KeyProvider provider) {
|
public EncryptionZoneManager(FSDirectory dir, KeyProvider provider) {
|
||||||
this.dir = dir;
|
this.dir = dir;
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
lock = new ReentrantReadWriteLock();
|
|
||||||
encryptionZones = new HashMap<Long, EncryptionZoneInt>();
|
encryptionZones = new HashMap<Long, EncryptionZoneInt>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +86,7 @@ public class EncryptionZoneManager {
|
||||||
void addEncryptionZone(Long inodeId, String keyId) {
|
void addEncryptionZone(Long inodeId, String keyId) {
|
||||||
assert dir.hasWriteLock();
|
assert dir.hasWriteLock();
|
||||||
final EncryptionZoneInt ez = new EncryptionZoneInt(inodeId, keyId);
|
final EncryptionZoneInt ez = new EncryptionZoneInt(inodeId, keyId);
|
||||||
writeLock();
|
|
||||||
try {
|
|
||||||
encryptionZones.put(inodeId, ez);
|
encryptionZones.put(inodeId, ez);
|
||||||
} finally {
|
|
||||||
writeUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,12 +96,7 @@ public class EncryptionZoneManager {
|
||||||
*/
|
*/
|
||||||
void removeEncryptionZone(Long inodeId) {
|
void removeEncryptionZone(Long inodeId) {
|
||||||
assert dir.hasWriteLock();
|
assert dir.hasWriteLock();
|
||||||
writeLock();
|
|
||||||
try {
|
|
||||||
encryptionZones.remove(inodeId);
|
encryptionZones.remove(inodeId);
|
||||||
} finally {
|
|
||||||
writeUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,12 +107,7 @@ public class EncryptionZoneManager {
|
||||||
boolean isInAnEZ(INodesInPath iip)
|
boolean isInAnEZ(INodesInPath iip)
|
||||||
throws UnresolvedLinkException, SnapshotAccessControlException {
|
throws UnresolvedLinkException, SnapshotAccessControlException {
|
||||||
assert dir.hasReadLock();
|
assert dir.hasReadLock();
|
||||||
readLock();
|
|
||||||
try {
|
|
||||||
return (getEncryptionZoneForPath(iip) != null);
|
return (getEncryptionZoneForPath(iip) != null);
|
||||||
} finally {
|
|
||||||
readUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,16 +127,12 @@ public class EncryptionZoneManager {
|
||||||
* Called while holding the FSDirectory lock.
|
* Called while holding the FSDirectory lock.
|
||||||
*/
|
*/
|
||||||
String getKeyName(final INodesInPath iip) {
|
String getKeyName(final INodesInPath iip) {
|
||||||
readLock();
|
assert dir.hasReadLock();
|
||||||
try {
|
|
||||||
EncryptionZoneInt ezi = getEncryptionZoneForPath(iip);
|
EncryptionZoneInt ezi = getEncryptionZoneForPath(iip);
|
||||||
if (ezi == null) {
|
if (ezi == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ezi.getKeyName();
|
return ezi.getKeyName();
|
||||||
} finally {
|
|
||||||
readUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,7 +142,7 @@ public class EncryptionZoneManager {
|
||||||
* Must be called while holding the manager lock.
|
* Must be called while holding the manager lock.
|
||||||
*/
|
*/
|
||||||
private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) {
|
private EncryptionZoneInt getEncryptionZoneForPath(INodesInPath iip) {
|
||||||
assert hasReadLock();
|
assert dir.hasReadLock();
|
||||||
Preconditions.checkNotNull(iip);
|
Preconditions.checkNotNull(iip);
|
||||||
final INode[] inodes = iip.getINodes();
|
final INode[] inodes = iip.getINodes();
|
||||||
for (int i = inodes.length - 1; i >= 0; i--) {
|
for (int i = inodes.length - 1; i >= 0; i--) {
|
||||||
|
@ -220,8 +171,6 @@ public class EncryptionZoneManager {
|
||||||
void checkMoveValidity(INodesInPath srcIIP, INodesInPath dstIIP, String src)
|
void checkMoveValidity(INodesInPath srcIIP, INodesInPath dstIIP, String src)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assert dir.hasReadLock();
|
assert dir.hasReadLock();
|
||||||
readLock();
|
|
||||||
try {
|
|
||||||
final EncryptionZoneInt srcEZI = getEncryptionZoneForPath(srcIIP);
|
final EncryptionZoneInt srcEZI = getEncryptionZoneForPath(srcIIP);
|
||||||
final EncryptionZoneInt dstEZI = getEncryptionZoneForPath(dstIIP);
|
final EncryptionZoneInt dstEZI = getEncryptionZoneForPath(dstIIP);
|
||||||
final boolean srcInEZ = (srcEZI != null);
|
final boolean srcInEZ = (srcEZI != null);
|
||||||
|
@ -253,9 +202,6 @@ public class EncryptionZoneManager {
|
||||||
throw new IOException(sb.toString());
|
throw new IOException(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
readUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,8 +212,6 @@ public class EncryptionZoneManager {
|
||||||
XAttr createEncryptionZone(String src, String keyId, KeyVersion keyVersion)
|
XAttr createEncryptionZone(String src, String keyId, KeyVersion keyVersion)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assert dir.hasWriteLock();
|
assert dir.hasWriteLock();
|
||||||
writeLock();
|
|
||||||
try {
|
|
||||||
if (dir.isNonEmptyDirectory(src)) {
|
if (dir.isNonEmptyDirectory(src)) {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Attempt to create an encryption zone for a non-empty directory.");
|
"Attempt to create an encryption zone for a non-empty directory.");
|
||||||
|
@ -291,9 +235,6 @@ public class EncryptionZoneManager {
|
||||||
// Re-get the new encryption zone add the latest key version
|
// Re-get the new encryption zone add the latest key version
|
||||||
ezi = getEncryptionZoneForPath(srcIIP);
|
ezi = getEncryptionZoneForPath(srcIIP);
|
||||||
return keyIdXAttr;
|
return keyIdXAttr;
|
||||||
} finally {
|
|
||||||
writeUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,16 +244,11 @@ public class EncryptionZoneManager {
|
||||||
*/
|
*/
|
||||||
List<EncryptionZone> listEncryptionZones() throws IOException {
|
List<EncryptionZone> listEncryptionZones() throws IOException {
|
||||||
assert dir.hasReadLock();
|
assert dir.hasReadLock();
|
||||||
readLock();
|
|
||||||
try {
|
|
||||||
final List<EncryptionZone> ret =
|
final List<EncryptionZone> ret =
|
||||||
Lists.newArrayListWithExpectedSize(encryptionZones.size());
|
Lists.newArrayListWithExpectedSize(encryptionZones.size());
|
||||||
for (EncryptionZoneInt ezi : encryptionZones.values()) {
|
for (EncryptionZoneInt ezi : encryptionZones.values()) {
|
||||||
ret.add(new EncryptionZone(getFullPathName(ezi), ezi.getKeyName()));
|
ret.add(new EncryptionZone(getFullPathName(ezi), ezi.getKeyName()));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
} finally {
|
|
||||||
readUnlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue