示例#1
0
  /**
   * Return a range of corrupt replica block ids. Up to numExpectedBlocks blocks starting at the
   * next block after startingBlockId are returned (fewer if numExpectedBlocks blocks are
   * unavailable). If startingBlockId is null, up to numExpectedBlocks blocks are returned from the
   * beginning. If startingBlockId cannot be found, null is returned.
   *
   * @param numExpectedBlocks Number of block ids to return. 0 <= numExpectedBlocks <= 100
   * @param startingBlockId Block id from which to start. If null, start at beginning.
   * @return Up to numExpectedBlocks blocks from startingBlockId if it exists
   */
  long[] getCorruptReplicaBlockIds(int numExpectedBlocks, Long startingBlockId) throws IOException {
    if (numExpectedBlocks < 0 || numExpectedBlocks > 100) {
      return null;
    }

    List<Long> sortedIds = new ArrayList<Long>();

    Collection<CorruptReplica> corruptReplicas = getAllCorruptReplicas();
    if (corruptReplicas != null) {
      for (CorruptReplica replica : corruptReplicas) {
        sortedIds.add(replica.getBlockId());
      }
    }

    Iterator<Long> blockIt = sortedIds.iterator();

    // if the starting block id was specified, iterate over keys until
    // we find the matching block. If we find a matching block, break
    // to leave the iterator on the next block after the specified block.
    if (startingBlockId != null) {
      boolean isBlockFound = false;
      while (blockIt.hasNext()) {
        Long bid = blockIt.next();
        if (bid == startingBlockId) {
          isBlockFound = true;
          break;
        }
      }

      if (!isBlockFound) {
        return null;
      }
    }

    ArrayList<Long> corruptReplicaBlockIds = new ArrayList<Long>();

    // append up to numExpectedBlocks blockIds to our list
    for (int i = 0; i < numExpectedBlocks && blockIt.hasNext(); i++) {
      corruptReplicaBlockIds.add(blockIt.next());
    }

    long[] ret = new long[corruptReplicaBlockIds.size()];
    for (int i = 0; i < ret.length; i++) {
      ret[i] = corruptReplicaBlockIds.get(i);
    }

    return ret;
  }
示例#2
0
  /**
   * Get Nodes which have corrupt replicas of Block
   *
   * @param blk Block for which nodes are requested
   * @return collection of nodes. Null if does not exists
   */
  Collection<DatanodeDescriptor> getNodes(BlockInfo blk)
      throws StorageException, TransactionContextException {

    // HOPS datanodeMgr is null in some tests
    if (datanodeMgr == null) {
      return new ArrayList<DatanodeDescriptor>();
    }

    Collection<CorruptReplica> corruptReplicas = getCorruptReplicas(blk);
    Collection<DatanodeDescriptor> dnds = new TreeSet<DatanodeDescriptor>();
    if (corruptReplicas != null) {
      for (CorruptReplica cr : corruptReplicas) {
        DatanodeDescriptor dn = datanodeMgr.getDatanode(cr.getStorageId());
        if (dn != null) {
          dnds.add(dn);
        }
      }
    }
    return dnds;
  }