HDFS-6945. BlockManager should remove a block from excessReplicateMap and decrement ExcessBlocks metric when the block is removed. (aajisaka)
This commit is contained in:
parent
e428fea730
commit
18a91fe4df
|
@ -398,6 +398,9 @@ Release 2.8.0 - UNRELEASED
|
|||
HDFS-7997. The first non-existing xattr should also throw IOException.
|
||||
(zhouyingchao via yliu)
|
||||
|
||||
HDFS-6945. BlockManager should remove a block from excessReplicateMap and
|
||||
decrement ExcessBlocks metric when the block is removed. (aajisaka)
|
||||
|
||||
Release 2.7.0 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -3351,8 +3351,7 @@ public class BlockManager {
|
|||
// file already removes them from the block map below.
|
||||
block.setNumBytes(BlockCommand.NO_ACK);
|
||||
addToInvalidates(block);
|
||||
corruptReplicas.removeFromCorruptReplicasMap(block);
|
||||
blocksMap.removeBlock(block);
|
||||
removeBlockFromMap(block);
|
||||
// Remove the block from pendingReplications and neededReplications
|
||||
pendingReplications.remove(block);
|
||||
neededReplications.remove(block, UnderReplicatedBlocks.LEVEL);
|
||||
|
@ -3528,11 +3527,30 @@ public class BlockManager {
|
|||
}
|
||||
|
||||
public void removeBlockFromMap(Block block) {
|
||||
removeFromExcessReplicateMap(block);
|
||||
blocksMap.removeBlock(block);
|
||||
// If block is removed from blocksMap remove it from corruptReplicasMap
|
||||
corruptReplicas.removeFromCorruptReplicasMap(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a block is removed from blocksMap, remove it from excessReplicateMap.
|
||||
*/
|
||||
private void removeFromExcessReplicateMap(Block block) {
|
||||
for (DatanodeStorageInfo info : blocksMap.getStorages(block)) {
|
||||
String uuid = info.getDatanodeDescriptor().getDatanodeUuid();
|
||||
LightWeightLinkedSet<Block> excessReplicas = excessReplicateMap.get(uuid);
|
||||
if (excessReplicas != null) {
|
||||
if (excessReplicas.remove(block)) {
|
||||
excessBlocksCount.decrementAndGet();
|
||||
if (excessReplicas.isEmpty()) {
|
||||
excessReplicateMap.remove(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return blocksMap.getCapacity();
|
||||
}
|
||||
|
|
|
@ -280,11 +280,16 @@ public class TestNameNodeMetrics {
|
|||
public void testExcessBlocks() throws Exception {
|
||||
Path file = getTestPath("testExcessBlocks");
|
||||
createFile(file, 100, (short)2);
|
||||
long totalBlocks = 1;
|
||||
NameNodeAdapter.setReplication(namesystem, file.toString(), (short)1);
|
||||
MetricsRecordBuilder rb = getMetrics(NS_METRICS);
|
||||
assertGauge("ExcessBlocks", totalBlocks, rb);
|
||||
assertGauge("ExcessBlocks", 1L, rb);
|
||||
|
||||
// verify ExcessBlocks metric is decremented and
|
||||
// excessReplicateMap is cleared after deleting a file
|
||||
fs.delete(file, true);
|
||||
rb = getMetrics(NS_METRICS);
|
||||
assertGauge("ExcessBlocks", 0L, rb);
|
||||
assertTrue(bm.excessReplicateMap.isEmpty());
|
||||
}
|
||||
|
||||
/** Test to ensure metrics reflects missing blocks */
|
||||
|
|
Loading…
Reference in New Issue