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

Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
zhangshuyan 2023-03-06 20:10:31 +08:00 committed by GitHub
parent 2a0dc2ab2f
commit 2cb0c35fc1
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
= new ArrayList<>(LEVEL);
/** The number of corrupt blocks with replication factor 1 */
private final LongAdder lowRedundancyBlocks = 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 lowRedundancyECBlockGroups = new LongAdder();
private final LongAdder corruptECBlockGroups = new LongAdder();
@ -369,11 +369,11 @@ class LowRedundancyBlocks implements Iterable<BlockInfo> {
* @return true if the block was found and removed from one of the priority
* queues
*/
boolean remove(BlockInfo block, int priLevel) {
synchronized boolean remove(BlockInfo block, int priLevel) {
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
&& priorityQueues.get(priLevel).remove(block)) {
NameNode.blockStateChangeLog.debug(