/** How many copies of this block is pending replication? */
 int getNumReplicas(Block block) {
   synchronized (pendingReplications) {
     PendingBlockInfo found = pendingReplications.get(block);
     if (found != null) {
       return found.getNumReplicas();
     }
   }
   return 0;
 }
 /** Add a block to the list of pending Replications */
 void add(Block block, int numReplicas) {
   synchronized (pendingReplications) {
     PendingBlockInfo found = pendingReplications.get(block);
     if (found == null) {
       pendingReplications.put(block, new PendingBlockInfo(numReplicas));
     } else {
       found.incrementReplicas(numReplicas);
       found.setTimeStamp();
     }
   }
 }
 /**
  * One replication request for this block has finished. Decrement the number of pending
  * replication requests for this block.
  */
 void remove(Block block) {
   synchronized (pendingReplications) {
     PendingBlockInfo found = pendingReplications.get(block);
     if (found != null) {
       FSNamesystem.LOG.debug("Removing pending replication for block" + block);
       found.decrementReplicas();
       if (found.getNumReplicas() <= 0) {
         pendingReplications.remove(block);
       }
     }
   }
 }
 /** Iterate through all items and detect timed-out items */
 void pendingReplicationCheck() {
   synchronized (pendingReplications) {
     Iterator iter = pendingReplications.entrySet().iterator();
     long now = FSNamesystem.now();
     FSNamesystem.LOG.debug("PendingReplicationMonitor checking Q");
     while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       PendingBlockInfo pendingBlock = (PendingBlockInfo) entry.getValue();
       if (now > pendingBlock.getTimeStamp() + timeout) {
         Block block = (Block) entry.getKey();
         synchronized (timedOutItems) {
           timedOutItems.add(block);
         }
         FSNamesystem.LOG.warn("PendingReplicationMonitor timed out block " + block);
         iter.remove();
       }
     }
   }
 }