コード例 #1
0
  synchronized List<Block> invalidateWork(final DatanodeDescriptor dn) {
    final long delay = getInvalidationDelay();
    if (delay > 0) {
      if (BlockManager.LOG.isDebugEnabled()) {
        BlockManager.LOG.debug(
            "Block deletion is delayed during NameNode startup. "
                + "The deletion will start after "
                + delay
                + " ms.");
      }
      return null;
    }
    final LightWeightHashSet<Block> set = node2blocks.get(dn);
    if (set == null) {
      return null;
    }

    // # blocks that can be sent in one message is limited
    final int limit = blockInvalidateLimit;
    final List<Block> toInvalidate = set.pollN(limit);

    // If we send everything in this message, remove this node entry
    if (set.isEmpty()) {
      remove(dn);
    }

    dn.addBlocksToBeInvalidated(toInvalidate);
    numBlocks -= toInvalidate.size();
    return toInvalidate;
  }
コード例 #2
0
 /** Remove the specified number of blocks to be invalidated */
 public Block[] getInvalidateBlocks(int maxblocks) {
   synchronized (invalidateBlocks) {
     Block[] deleteList =
         invalidateBlocks.pollToArray(new Block[Math.min(invalidateBlocks.size(), maxblocks)]);
     return deleteList.length == 0 ? null : deleteList;
   }
 }
コード例 #3
0
 /**
  * @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 = node2blocks.get(dn);
   if (s == null) {
     return false; // no invalidate blocks for this storage ID
   }
   Block blockInSet = s.getElement(block);
   return blockInSet != null && block.getGenerationStamp() == blockInSet.getGenerationStamp();
 }
コード例 #4
0
 /** Remove the block from the specified storage. */
 synchronized void remove(final DatanodeInfo dn, final Block block) {
   final LightWeightHashSet<Block> v = node2blocks.get(dn);
   if (v != null && v.remove(block)) {
     numBlocks--;
     if (v.isEmpty()) {
       node2blocks.remove(dn);
     }
   }
 }
コード例 #5
0
 /** 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 = node2blocks.get(datanode);
   if (set == null) {
     set = new LightWeightHashSet<Block>();
     node2blocks.put(datanode, set);
   }
   if (set.add(block)) {
     numBlocks++;
     if (log) {
       NameNode.blockStateChangeLog.info(
           "BLOCK* " + getClass().getSimpleName() + ": add " + block + " to " + datanode);
     }
   }
 }
コード例 #6
0
  /** Print the contents to out. */
  synchronized void dump(final PrintWriter out) {
    final int size = node2blocks.values().size();
    out.println("Metasave: Blocks " + numBlocks + " waiting deletion from " + size + " datanodes.");
    if (size == 0) {
      return;
    }

    for (Map.Entry<DatanodeInfo, LightWeightHashSet<Block>> entry : node2blocks.entrySet()) {
      final LightWeightHashSet<Block> blocks = entry.getValue();
      if (blocks.size() > 0) {
        out.println(entry.getKey());
        out.println(blocks);
      }
    }
  }
コード例 #7
0
 /** Store block invalidation work. */
 void addBlocksToBeInvalidated(List<Block> blocklist) {
   assert (blocklist != null && blocklist.size() > 0);
   synchronized (invalidateBlocks) {
     for (Block blk : blocklist) {
       invalidateBlocks.add(blk);
     }
   }
 }
コード例 #8
0
 @Override
 public String dumpDatanode() {
   StringBuilder sb = new StringBuilder(super.dumpDatanode());
   int repl = replicateBlocks.size();
   if (repl > 0) {
     sb.append(" ").append(repl).append(" blocks to be replicated;");
   }
   int inval = invalidateBlocks.size();
   if (inval > 0) {
     sb.append(" ").append(inval).append(" blocks to be invalidated;");
   }
   int recover = recoverBlocks.size();
   if (recover > 0) {
     sb.append(" ").append(recover).append(" blocks to be recovered;");
   }
   return sb.toString();
 }
コード例 #9
0
 /** Remove a storage from the invalidatesSet */
 synchronized void remove(final DatanodeInfo dn) {
   final LightWeightHashSet<Block> blocks = node2blocks.remove(dn);
   if (blocks != null) {
     numBlocks -= blocks.size();
   }
 }
コード例 #10
0
 /** The number of block invalidation items that are pending to be sent to the datanode */
 int getNumberOfBlocksToBeInvalidated() {
   synchronized (invalidateBlocks) {
     return invalidateBlocks.size();
   }
 }