From 68612a0410066af745e80d3b6d732a6151a635e3 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Thu, 12 Sep 2019 12:41:57 +0900 Subject: [PATCH] HDFS-14840. Use Java Conccurent Instead of Synchronization in BlockPoolTokenSecretManager. Contributed by David Mollitor. --- .../block/BlockPoolTokenSecretManager.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java index bbd3750cbb9..e477eee8437 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java @@ -19,8 +19,8 @@ package org.apache.hadoop.hdfs.security.token.block; import java.io.IOException; import java.util.EnumSet; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier.AccessMode; @@ -37,30 +37,29 @@ import org.apache.hadoop.fs.StorageType; public class BlockPoolTokenSecretManager extends SecretManager { - private final Map map = - new HashMap(); + private final Map map = + new ConcurrentHashMap<>(); /** * Add a block pool Id and corresponding {@link BlockTokenSecretManager} to map * @param bpid block pool Id * @param secretMgr {@link BlockTokenSecretManager} */ - public synchronized void addBlockPool(String bpid, - BlockTokenSecretManager secretMgr) { + public void addBlockPool(String bpid, BlockTokenSecretManager secretMgr) { map.put(bpid, secretMgr); } @VisibleForTesting - public synchronized BlockTokenSecretManager get(String bpid) { + public BlockTokenSecretManager get(String bpid) { BlockTokenSecretManager secretMgr = map.get(bpid); if (secretMgr == null) { - throw new IllegalArgumentException("Block pool " + bpid - + " is not found"); + throw new IllegalArgumentException( + "Block pool " + bpid + " is not found"); } return secretMgr; } - public synchronized boolean isBlockPoolRegistered(String bpid) { + public boolean isBlockPoolRegistered(String bpid) { return map.containsKey(bpid); }