HDFS-16939. Fix the thread safety bug in LowRedundancyBlocks. (#5450 #5471). Contributed by Shuyan Zhang.

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
zhangshuyan 2023-03-11 16:09:06 +08:00 committed by GitHub
parent 4a23389f5e
commit 8cc57f5eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -86,10 +86,10 @@ class LowRedundancyBlocks implements Iterable<BlockInfo> {
private final List<LightWeightLinkedSet<BlockInfo>> priorityQueues private final List<LightWeightLinkedSet<BlockInfo>> priorityQueues
= new ArrayList<>(LEVEL); = new ArrayList<>(LEVEL);
/** The number of corrupt blocks with replication factor 1 */
private final LongAdder lowRedundancyBlocks = new LongAdder(); private final LongAdder lowRedundancyBlocks = new LongAdder();
private final LongAdder corruptBlocks = new LongAdder(); private final LongAdder corruptBlocks = new LongAdder();
/** The number of corrupt blocks with replication factor 1 */
private final LongAdder corruptReplicationOneBlocks = new LongAdder(); private final LongAdder corruptReplicationOneBlocks = new LongAdder();
private final LongAdder lowRedundancyECBlockGroups = new LongAdder(); private final LongAdder lowRedundancyECBlockGroups = new LongAdder();
private final LongAdder corruptECBlockGroups = new LongAdder(); private final LongAdder corruptECBlockGroups = new LongAdder();
@ -367,11 +367,11 @@ class LowRedundancyBlocks implements Iterable<BlockInfo> {
* @return true if the block was found and removed from one of the priority * @return true if the block was found and removed from one of the priority
* queues * queues
*/ */
boolean remove(BlockInfo block, int priLevel) { synchronized boolean remove(BlockInfo block, int priLevel) {
return remove(block, priLevel, block.getReplication()); return remove(block, priLevel, block.getReplication());
} }
boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas) { synchronized boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas) {
if(priLevel >= 0 && priLevel < LEVEL if(priLevel >= 0 && priLevel < LEVEL
&& priorityQueues.get(priLevel).remove(block)) { && priorityQueues.get(priLevel).remove(block)) {
NameNode.blockStateChangeLog.debug( NameNode.blockStateChangeLog.debug(