HDFS-14840. Use Java Conccurent Instead of Synchronization in BlockPoolTokenSecretManager. Contributed by David Mollitor.

This commit is contained in:
Akira Ajisaka 2019-09-12 12:41:57 +09:00
parent 3b06f0bf9e
commit 68612a0410
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
1 changed files with 8 additions and 9 deletions

View File

@ -19,8 +19,8 @@ package org.apache.hadoop.hdfs.security.token.block;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier.AccessMode; import org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier.AccessMode;
@ -38,29 +38,28 @@ public class BlockPoolTokenSecretManager extends
SecretManager<BlockTokenIdentifier> { SecretManager<BlockTokenIdentifier> {
private final Map<String, BlockTokenSecretManager> map = private final Map<String, BlockTokenSecretManager> map =
new HashMap<String, BlockTokenSecretManager>(); new ConcurrentHashMap<>();
/** /**
* Add a block pool Id and corresponding {@link BlockTokenSecretManager} to map * Add a block pool Id and corresponding {@link BlockTokenSecretManager} to map
* @param bpid block pool Id * @param bpid block pool Id
* @param secretMgr {@link BlockTokenSecretManager} * @param secretMgr {@link BlockTokenSecretManager}
*/ */
public synchronized void addBlockPool(String bpid, public void addBlockPool(String bpid, BlockTokenSecretManager secretMgr) {
BlockTokenSecretManager secretMgr) {
map.put(bpid, secretMgr); map.put(bpid, secretMgr);
} }
@VisibleForTesting @VisibleForTesting
public synchronized BlockTokenSecretManager get(String bpid) { public BlockTokenSecretManager get(String bpid) {
BlockTokenSecretManager secretMgr = map.get(bpid); BlockTokenSecretManager secretMgr = map.get(bpid);
if (secretMgr == null) { if (secretMgr == null) {
throw new IllegalArgumentException("Block pool " + bpid throw new IllegalArgumentException(
+ " is not found"); "Block pool " + bpid + " is not found");
} }
return secretMgr; return secretMgr;
} }
public synchronized boolean isBlockPoolRegistered(String bpid) { public boolean isBlockPoolRegistered(String bpid) {
return map.containsKey(bpid); return map.containsKey(bpid);
} }