private void putBlocksSet(final DatanodeInfo dn, final Block block, final LightWeightHashSet set) { if (blockIdManager.isStripedBlock(block)) { assert getECBlocksSet(dn) == null; nodeToECBlocks.put(dn, set); } else { assert getBlocksSet(dn) == null; nodeToBlocks.put(dn, set); } }
private LightWeightHashSet<Block> getBlocksSet(final DatanodeInfo dn, final Block block) { if (blockIdManager.isStripedBlock(block)) { return getECBlocksSet(dn); } else { return getBlocksSet(dn); } }
/** * Add a block to the block collection which will be * invalidated on the specified datanode. */ synchronized void add(final Block block, final DatanodeInfo datanode, final boolean log) { LightWeightHashSet<Block> set = getBlocksSet(datanode, block); if (set == null) { set = new LightWeightHashSet<>(); putBlocksSet(datanode, block, set); } if (set.add(block)) { if (blockIdManager.isStripedBlock(block)) { numECBlocks.increment(); } else { numBlocks.increment(); } if (log) { NameNode.blockStateChangeLog.debug("BLOCK* {}: add {} to {}", getClass().getSimpleName(), block, datanode); } } }
private long getBlockSetsSize(final DatanodeInfo dn) { LightWeightHashSet<Block> replicaBlocks = getBlocksSet(dn); LightWeightHashSet<Block> stripedBlocks = getECBlocksSet(dn); return ((replicaBlocks == null ? 0 : replicaBlocks.size()) + (stripedBlocks == null ? 0 : stripedBlocks.size())); }
/** * @return true if the given storage has the given block listed for * invalidation. Blocks are compared including their generation stamps: * if a block is pending invalidation but with a different generation stamp, * returns false. */ synchronized boolean contains(final DatanodeInfo dn, final Block block) { final LightWeightHashSet<Block> s = getBlocksSet(dn, block); if (s == null) { return false; // no invalidate blocks for this storage ID } Block blockInSet = s.getElement(block); return blockInSet != null && block.getGenerationStamp() == blockInSet.getGenerationStamp(); }
/** Remove the block from the specified storage. */ synchronized void remove(final DatanodeInfo dn, final Block block) { final LightWeightHashSet<Block> v = getBlocksSet(dn, block); if (v != null && v.remove(block)) { if (blockIdManager.isStripedBlock(block)) { numECBlocks.decrement(); } else { numBlocks.decrement(); } if (v.isEmpty() && getBlockSetsSize(dn) == 0) { remove(dn); } } }