Skip to content

Commit 6a49bf9

Browse files
author
S O'Donnell
committed
HDFS-14852. Removing from LowRedundancyBlocks does not remove the block from all queues. Contributed by Fei Hui.
1 parent 82a7505 commit 6a49bf9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2531,7 +2531,7 @@ void processPendingReconstructions() {
25312531
* with the most up-to-date block information (e.g. genstamp).
25322532
*/
25332533
BlockInfo bi = blocksMap.getStoredBlock(timedOutItems[i]);
2534-
if (bi == null) {
2534+
if (bi == null || bi.isDeleted()) {
25352535
continue;
25362536
}
25372537
NumberReplicas num = countNodes(timedOutItems[i]);

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/LowRedundancyBlocks.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,18 @@ boolean remove(BlockInfo block, int priLevel, int oldExpectedReplicas) {
382382
} else {
383383
// Try to remove the block from all queues if the block was
384384
// not found in the queue for the given priority level.
385+
boolean found = false;
385386
for (int i = 0; i < LEVEL; i++) {
386387
if (i != priLevel && priorityQueues.get(i).remove(block)) {
387388
NameNode.blockStateChangeLog.debug(
388389
"BLOCK* NameSystem.LowRedundancyBlock.remove: Removing block" +
389390
" {} from priority queue {}", block, i);
390391
decrementBlockStat(block, i, oldExpectedReplicas);
391-
return true;
392+
found = true;
392393
}
393394
}
395+
return found;
394396
}
395-
return false;
396397
}
397398

398399
private void decrementBlockStat(BlockInfo blockInfo, int priLevel,

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestLowRedundancyBlockQueues.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,15 @@ private void assertInLevel(LowRedundancyBlocks queues,
276276
}
277277
fail("Block " + block + " not found in level " + level);
278278
}
279+
280+
@Test
281+
public void testRemoveBlockInManyQueues() {
282+
LowRedundancyBlocks neededReconstruction = new LowRedundancyBlocks();
283+
BlockInfo block = new BlockInfoContiguous(new Block(), (short)1024);
284+
neededReconstruction.add(block, 2, 0, 1, 3);
285+
neededReconstruction.add(block, 0, 0, 0, 3);
286+
neededReconstruction.remove(block, LowRedundancyBlocks.LEVEL);
287+
assertFalse("Should not contain the block.",
288+
neededReconstruction.contains(block));
289+
}
279290
}

0 commit comments

Comments
 (0)