Java Code Examples for org.apache.hadoop.hdfs.protocol.BlockListAsLongs.BlockReportReplica#getNumBytes()

The following examples show how to use org.apache.hadoop.hdfs.protocol.BlockListAsLongs.BlockReportReplica#getNumBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockListAsLongs.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public long[] getBlockListAsLongs() {
  // terribly inefficient but only occurs if server tries to transcode
  // an undecoded buffer into longs - ie. it will never happen but let's
  // handle it anyway
  if (numFinalized == -1) {
    int n = 0;
    for (Replica replica : this) {
      if (replica.getState() == ReplicaState.FINALIZED) {
        n++;
      }
    }
    numFinalized = n;
  }
  int numUc = numBlocks - numFinalized;
  int size = 2 + 3*(numFinalized+1) + 4*(numUc);
  long[] longs = new long[size];
  longs[0] = numFinalized;
  longs[1] = numUc;

  int idx = 2;
  int ucIdx = idx + 3*numFinalized;
  // delimiter block
  longs[ucIdx++] = -1;
  longs[ucIdx++] = -1;
  longs[ucIdx++] = -1;

  for (BlockReportReplica block : this) {
    switch (block.getState()) {
      case FINALIZED: {
        longs[idx++] = block.getBlockId();
        longs[idx++] = block.getNumBytes();
        longs[idx++] = block.getGenerationStamp();
        break;
      }
      default: {
        longs[ucIdx++] = block.getBlockId();
        longs[ucIdx++] = block.getNumBytes();
        longs[ucIdx++] = block.getGenerationStamp();
        longs[ucIdx++] = block.getState().getValue();
        break;
      }
    }
  }
  return longs;
}
 
Example 2
Source File: BlockReportTestBase.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private static StorageBlockReport[] getBlockReports(
    DataNode dn, String bpid, boolean corruptOneBlockGs,
    boolean corruptOneBlockLen) {
  Map<DatanodeStorage, BlockListAsLongs> perVolumeBlockLists =
      dn.getFSDataset().getBlockReports(bpid);

  // Send block report
  StorageBlockReport[] reports =
      new StorageBlockReport[perVolumeBlockLists.size()];
  boolean corruptedGs = false;
  boolean corruptedLen = false;

  int reportIndex = 0;
  for(Map.Entry<DatanodeStorage, BlockListAsLongs> kvPair : perVolumeBlockLists.entrySet()) {
    DatanodeStorage dnStorage = kvPair.getKey();
    BlockListAsLongs blockList = kvPair.getValue();

    // Walk the list of blocks until we find one each to corrupt the
    // generation stamp and length, if so requested.
    BlockListAsLongs.Builder builder = BlockListAsLongs.builder();
    for (BlockReportReplica block : blockList) {
      if (corruptOneBlockGs && !corruptedGs) {
        long gsOld = block.getGenerationStamp();
        long gsNew;
        do {
          gsNew = rand.nextInt();
        } while (gsNew == gsOld);
        block.setGenerationStamp(gsNew);
        LOG.info("Corrupted the GS for block ID " + block);
        corruptedGs = true;
      } else if (corruptOneBlockLen && !corruptedLen) {
        long lenOld = block.getNumBytes();
        long lenNew;
        do {
          lenNew = rand.nextInt((int)lenOld - 1);
        } while (lenNew == lenOld);
        block.setNumBytes(lenNew);
        LOG.info("Corrupted the length for block ID " + block);
        corruptedLen = true;
      }
      builder.add(new BlockReportReplica(block));
    }

    reports[reportIndex++] =
        new StorageBlockReport(dnStorage, builder.build());
  }

  return reports;
}
 
Example 3
Source File: BlockListAsLongs.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public long[] getBlockListAsLongs() {
  // terribly inefficient but only occurs if server tries to transcode
  // an undecoded buffer into longs - ie. it will never happen but let's
  // handle it anyway
  if (numFinalized == -1) {
    int n = 0;
    for (Replica replica : this) {
      if (replica.getState() == ReplicaState.FINALIZED) {
        n++;
      }
    }
    numFinalized = n;
  }
  int numUc = numBlocks - numFinalized;
  int size = 2 + 3*(numFinalized+1) + 4*(numUc);
  long[] longs = new long[size];
  longs[0] = numFinalized;
  longs[1] = numUc;

  int idx = 2;
  int ucIdx = idx + 3*numFinalized;
  // delimiter block
  longs[ucIdx++] = -1;
  longs[ucIdx++] = -1;
  longs[ucIdx++] = -1;

  for (BlockReportReplica block : this) {
    switch (block.getState()) {
      case FINALIZED: {
        longs[idx++] = block.getBlockId();
        longs[idx++] = block.getNumBytes();
        longs[idx++] = block.getGenerationStamp();
        break;
      }
      default: {
        longs[ucIdx++] = block.getBlockId();
        longs[ucIdx++] = block.getNumBytes();
        longs[ucIdx++] = block.getGenerationStamp();
        longs[ucIdx++] = block.getState().getValue();
        break;
      }
    }
  }
  return longs;
}
 
Example 4
Source File: BlockReportTestBase.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static StorageBlockReport[] getBlockReports(
    DataNode dn, String bpid, boolean corruptOneBlockGs,
    boolean corruptOneBlockLen) {
  Map<DatanodeStorage, BlockListAsLongs> perVolumeBlockLists =
      dn.getFSDataset().getBlockReports(bpid);

  // Send block report
  StorageBlockReport[] reports =
      new StorageBlockReport[perVolumeBlockLists.size()];
  boolean corruptedGs = false;
  boolean corruptedLen = false;

  int reportIndex = 0;
  for(Map.Entry<DatanodeStorage, BlockListAsLongs> kvPair : perVolumeBlockLists.entrySet()) {
    DatanodeStorage dnStorage = kvPair.getKey();
    BlockListAsLongs blockList = kvPair.getValue();

    // Walk the list of blocks until we find one each to corrupt the
    // generation stamp and length, if so requested.
    BlockListAsLongs.Builder builder = BlockListAsLongs.builder();
    for (BlockReportReplica block : blockList) {
      if (corruptOneBlockGs && !corruptedGs) {
        long gsOld = block.getGenerationStamp();
        long gsNew;
        do {
          gsNew = rand.nextInt();
        } while (gsNew == gsOld);
        block.setGenerationStamp(gsNew);
        LOG.info("Corrupted the GS for block ID " + block);
        corruptedGs = true;
      } else if (corruptOneBlockLen && !corruptedLen) {
        long lenOld = block.getNumBytes();
        long lenNew;
        do {
          lenNew = rand.nextInt((int)lenOld - 1);
        } while (lenNew == lenOld);
        block.setNumBytes(lenNew);
        LOG.info("Corrupted the length for block ID " + block);
        corruptedLen = true;
      }
      builder.add(new BlockReportReplica(block));
    }

    reports[reportIndex++] =
        new StorageBlockReport(dnStorage, builder.build());
  }

  return reports;
}