All removals from the blocks map goes through this function.

@param b
block to be removed
@param decrementSafeBlockCount
whether need to decrement safe block count when needed
@return the {@link BlockInfo} for the removed block
772241
private BlockInfo removeBlockFromMap(Block b) {
    if (b == null) {
      return null;
    }
     ns.decrementSafeBlockCountForBlockRemoval(b);
    return blocks.remove(b);
  }
420658
synchronized boolean remove(BlockInfo blockInfo, 
                              int oldReplicas, 
                              int decommissionedReplicas,
                              int oldExpectedReplicas) {
    int priLevel = getPriority(blockInfo, oldReplicas, 
                               decommissionedReplicas,
                               oldExpectedReplicas);
    return remove(blockInfo, priLevel);
  }
644427
synchronized int getNonCorruptUnderReplicatedBlocksCount() {
    int size = 0;
    for (int i=0; i<QUEUE_WITH_CORRUPT_BLOCKS; i++) {
      size += priorityQueues.get(i).size();
    }
    return size;
  }
190237
public static void blockInfo(AFPChain afpChain)
	{
		int     i, j, k, a, n;

		int blockNum = afpChain.getBlockNum();

		int[] blockSize =afpChain.getBlockSize();
		int[] afpChainList = afpChain.getAfpChainList();
		int[] block2Afp = afpChain.getBlock2Afp();
		int[][][]blockResList = afpChain.getBlockResList();

		List<AFP>afpSet = afpChain.getAfpSet();
		int[] blockResSize = afpChain.getBlockResSize();

		for(i = 0; i < blockNum; i ++)  {
			n = 0;
			for(j = 0; j < blockSize[i]; j ++)      {
				//the index in afpChainList, not in the whole afp set
				a = afpChainList[block2Afp[i] + j];
				for(k = 0; k < afpSet.get(a).getFragLen(); k ++)     {
					blockResList[i][0][n] = afpSet.get(a).getP1() + k;
					blockResList[i][1][n] = afpSet.get(a).getP2() + k;
					n ++;
				}
			}
			blockResSize[i] = n;
		}

		afpChain.setBlockResSize(blockResSize);
		afpChain.setBlockSize(blockSize);
		afpChain.setAfpChainList(afpChainList);
		afpChain.setBlock2Afp(block2Afp);
		afpChain.setBlockResList(blockResList);
	}
160027
boolean provablyExecutesBefore(BasicBlock thatBlock) {
    // If thatBlock is a descendant of this block, and there are no hoisted
    // blocks between them, then this block must start before thatBlock.
    BasicBlock currentBlock;
    for (currentBlock = thatBlock;
        currentBlock != null && currentBlock != this;
        currentBlock = currentBlock.getParent()) {}

    if (currentBlock == this) {
      return true;
    }
    return isGlobalScopeBlock() && thatBlock.isGlobalScopeBlock();
  }
327410
@Override
    protected void disconnectTransactions(StoredBlock oldBlock) throws PrunedException, BlockStoreException {
        checkState(lock.isHeldByCurrentThread());
        blockStore.beginDatabaseBatchWrite();
        try {
            StoredUndoableBlock undoBlock = blockStore.getUndoBlock(oldBlock.getHeader().getHash());
            if (undoBlock == null) throw new PrunedException(oldBlock.getHeader().getHash());
            TransactionOutputChanges txOutChanges = undoBlock.getTxOutChanges();
            for (UTXO out : txOutChanges.txOutsSpent)
                blockStore.addUnspentTransactionOutput(out);
            for (UTXO out : txOutChanges.txOutsCreated)
                blockStore.removeUnspentTransactionOutput(out);
        } catch (PrunedException e) {
            blockStore.abortDatabaseBatchWrite();
            throw e;
        } catch (BlockStoreException e) {
            blockStore.abortDatabaseBatchWrite();
            throw e;
        }
    }
1202646
@Override
    public Collection<BlockingState> computeAddonsBlockingStatesForFutureSubscriptionBaseEvents() {
        if (!ProductCategory.BASE.equals(subscription.getCategory())) {
            // Only base subscriptions have add-ons
            return ImmutableList.of();
        }

        // We need to find the first "trigger" transition, from which we will create the add-ons cancellation events.
        // This can either be a future entitlement cancel...
        if (isEntitlementFutureCancelled()) {
            // Note that in theory we could always only look subscription base as we assume entitlement cancel means subscription base cancel
            // but we want to use the effective date of the entitlement cancel event to create the add-on cancel event
            final BlockingState futureEntitlementCancelEvent = getEntitlementCancellationEvent(subscription.getId());
            return computeAddonsBlockingStatesForNextSubscriptionBaseEvent(futureEntitlementCancelEvent.getEffectiveDate(), false);
        } else if (isEntitlementFutureChanged()) {
            // ...or a subscription change (i.e. a change plan where the new plan has an impact on the existing add-on).
            // We need to go back to subscription base as entitlement doesn't know about these
            return computeAddonsBlockingStatesForNextSubscriptionBaseEvent(utcNow, true);
        } else {
            return ImmutableList.of();
        }
    }
170855
private int countCorruptNodes(Block b, 
                                    Iterator<DatanodeDescriptor> nodeIter) {
    int corrupt = 0;
    Collection<DatanodeDescriptor> nodesCorrupt = corruptReplicas.getNodes(b);
    while (nodeIter.hasNext()) {
      DatanodeDescriptor node = nodeIter.next();
      if ((nodesCorrupt != null) && (nodesCorrupt.contains(node))) {
        corrupt++;
      }
    }
    return corrupt;
  }
1321482
public static BlockAndLocation[] locatedBlocks2BlockLocations(
     LocatedBlocks blocks) {
   if (blocks == null) {
     return new BlockAndLocation[0];
   }
   int nrBlocks = blocks.locatedBlockCount();
   BlockAndLocation[] blkLocations = new BlockAndLocation[nrBlocks];
   if (nrBlocks == 0) {
     return blkLocations;
   }
   int idx = 0;
   for (LocatedBlock blk : blocks.getLocatedBlocks()) {
     assert idx < nrBlocks : "Incorrect index";
     DatanodeInfo[] locations = blk.getLocations();
     String[] hosts = new String[locations.length];
     String[] names = new String[locations.length];
     String[] racks = new String[locations.length];
     for (int hCnt = 0; hCnt < locations.length; hCnt++) {
       hosts[hCnt] = locations[hCnt].getHostName();
       names[hCnt] = locations[hCnt].getName();
       NodeBase node = new NodeBase(names[hCnt],
                                    locations[hCnt].getNetworkLocation());
       racks[hCnt] = node.toString();
     }
     Block block = blk.getBlock();
     blkLocations[idx] = new BlockAndLocation(block.getBlockId(),
                                           block.getGenerationStamp(),
                                           names, hosts, racks,
                                           blk.getStartOffset(),
                                           block.getNumBytes(),
                                           blk.isCorrupt());
     idx++;
   }
   return blkLocations;
 }
68679
public static BlockLocation[] locatedBlocks2Locations(LocatedBlocks blocks) {
    if (blocks == null) {
      return new BlockLocation[0];
    }
    int nrBlocks = blocks.locatedBlockCount();
    BlockLocation[] blkLocations = new BlockLocation[nrBlocks];
    if (nrBlocks == 0) {
      return blkLocations;
    }
    int idx = 0;
    for (LocatedBlock blk : blocks.getLocatedBlocks()) {
      assert idx < nrBlocks : "Incorrect index";
      DatanodeInfo[] locations = blk.getLocations();
      String[] hosts = new String[locations.length];
      String[] names = new String[locations.length];
      String[] racks = new String[locations.length];
      for (int hCnt = 0; hCnt < locations.length; hCnt++) {
        hosts[hCnt] = locations[hCnt].getHostName();
        names[hCnt] = locations[hCnt].getName();
        NodeBase node = new NodeBase(names[hCnt],
                                     locations[hCnt].getNetworkLocation());
        racks[hCnt] = node.toString();
      }
      blkLocations[idx] = new BlockLocation(names, hosts, racks,
                                            blk.getStartOffset(),
                                            blk.getBlockSize(),
                                            blk.isCorrupt());
      idx++;
    }
    return blkLocations;
  }
1348835
private int countLiveNodes(Block b, Iterator<DatanodeDescriptor> nodeIter) {
    int live = 0;
    Collection<DatanodeDescriptor> nodesCorrupt = null;
    if (corruptReplicas.size() != 0) {
      nodesCorrupt = corruptReplicas.getNodes(b);
    }
    while (nodeIter.hasNext()) {
      DatanodeDescriptor node = nodeIter.next();
      if (((nodesCorrupt != null) && (nodesCorrupt.contains(node))) ||
        node.isDecommissionInProgress() || node.isDecommissioned()) {
        // do nothing
      } else {
        live++;
      }
    }
    return live;
  }
23312
BlockInfo addINodeForLoading(Block b, INodeFile iNode) {
    // allocate new block when loading the image
    // for hardlinked files, we need to check if the blocks are already there
    BlockInfo info = checkBlockInfo(b, iNode.getReplication(),
        iNode.isHardlinkFile());
    info.inode = iNode;
    return info;
  }
57324
private void addToInvalidates(Block b, boolean ackRequired) {
    StringBuilder sb = new StringBuilder();
    for (Iterator<DatanodeDescriptor> it =
      blocksMap.nodeIterator(b); it.hasNext();) {
      DatanodeDescriptor node = it.next();
      addToInvalidatesNoLog(b, node, ackRequired);
      sb.append(node.getName());
      sb.append(' ');
    }
    if (isInitialized && !isInSafeMode()) {
      // do not log in startup phase
      NameNode.stateChangeLog.info("BLOCK* NameSystem.addToInvalidates: "
              + b.getBlockName() + " is added to invalidSet of " + sb);
    }
  }
116905
@Override
  public void addBlock(BlockInfo newblock) {
    if (this.blocks == null) {
      this.blocks = new BlockInfo[1];
      this.blocks[0] = newblock;
    } else {
      int size = this.blocks.length;
      BlockInfo[] newlist = new BlockInfo[size + 1];
      System.arraycopy(this.blocks, 0, newlist, 0, size);
      newlist[size] = newblock;
      this.blocks = newlist;
    }
  }
1063699
private NumberReplicas countNodes(Block b,
                                    Iterator<DatanodeDescriptor> nodeIter) {
    int count = 0;
    int live = 0;
    int corrupt = 0;
    int excess = 0;
    Collection<DatanodeDescriptor> nodesCorrupt = corruptReplicas.getNodes(b);
    while (nodeIter.hasNext()) {
      DatanodeDescriptor node = nodeIter.next();
      if ((nodesCorrupt != null) && (nodesCorrupt.contains(node))) {
        corrupt++;
      } else if (node.isDecommissionInProgress() || node.isDecommissioned()) {
        count++;
      } else {
        Collection<Block> blocksExcess = initializedReplQueues ?
          excessReplicateMap.get(node.getStorageID()) : null;
        if (blocksExcess != null && blocksExcess.contains(b)) {
          excess++;
        } else {
          live++;
        }
      }
    }
    return new NumberReplicas(live, count, corrupt, excess);
  }
584623
private void sortBlocksBySize(Map<String, List<OneBlockInfo>> nodeToBlocks) {
    OneBlockInfoSizeComparator comparator = new OneBlockInfoSizeComparator();
    for (Entry<String, List<OneBlockInfo>> entry : nodeToBlocks.entrySet()) {
      Collections.sort(entry.getValue(), comparator);
    }
  }
478128
void moveBlockToHead(BlockInfo b) {
    blockList = b.listRemove(blockList, this);
    blockList = b.listInsert(blockList, this, -1);
  }