HDFS-14840. Use Java Conccurent Instead of Synchronization in BlockPoolTokenSecretManager. Contributed by David Mollitor.
This commit is contained in:
parent
3b06f0bf9e
commit
68612a0410
|
@ -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;
|
||||||
|
@ -37,30 +37,29 @@ import org.apache.hadoop.fs.StorageType;
|
||||||
public class BlockPoolTokenSecretManager extends
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue