当前位置: 首页>>代码示例>>Java>>正文


Java ReplicaState.FINALIZED属性代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState.FINALIZED属性的典型用法代码示例。如果您正苦于以下问题:Java ReplicaState.FINALIZED属性的具体用法?Java ReplicaState.FINALIZED怎么用?Java ReplicaState.FINALIZED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState的用法示例。


在下文中一共展示了ReplicaState.FINALIZED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

public void add(Replica replica) {
  try {
    // zig-zag to reduce size of legacy blocks
    cos.writeSInt64NoTag(replica.getBlockId());
    cos.writeRawVarint64(replica.getBytesOnDisk());
    cos.writeRawVarint64(replica.getGenerationStamp());
    ReplicaState state = replica.getState();
    // although state is not a 64-bit value, using a long varint to
    // allow for future use of the upper bits
    cos.writeRawVarint64(state.getValue());
    if (state == ReplicaState.FINALIZED) {
      numFinalized++;
    }
    numBlocks++;
  } catch (IOException ioe) {
    // shouldn't happen, ByteString.Output doesn't throw IOE
    throw new IllegalStateException(ioe);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:BlockListAsLongs.java

示例2: BlockReportReplica

public BlockReportReplica(Block block) {
  super(block);
  if (block instanceof BlockReportReplica) {
    this.state = ((BlockReportReplica)block).getState();
  } else {
    this.state = ReplicaState.FINALIZED;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:BlockListAsLongs.java

示例3: addStoredBlockUnderConstruction

void addStoredBlockUnderConstruction(StatefulBlockInfo ucBlock,
    DatanodeStorageInfo storageInfo) throws IOException {
  BlockInfoContiguousUnderConstruction block = ucBlock.storedBlock;
  block.addReplicaIfNotPresent(
      storageInfo, ucBlock.reportedBlock, ucBlock.reportedState);

  if (ucBlock.reportedState == ReplicaState.FINALIZED &&
      !block.findDatanode(storageInfo.getDatanodeDescriptor())) {
    addStoredBlock(block, storageInfo, null, true);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:BlockManager.java

示例4: append

@Override  // FsDatasetSpi
public synchronized ReplicaHandler append(ExtendedBlock b,
    long newGS, long expectedBlockLen) throws IOException {
  // If the block was successfully finalized because all packets
  // were successfully processed at the Datanode but the ack for
  // some of the packets were not received by the client. The client 
  // re-opens the connection and retries sending those packets.
  // The other reason is that an "append" is occurring to this block.
  
  // check the validity of the parameter
  if (newGS < b.getGenerationStamp()) {
    throw new IOException("The new generation stamp " + newGS + 
        " should be greater than the replica " + b + "'s generation stamp");
  }
  ReplicaInfo replicaInfo = getReplicaInfo(b);
  LOG.info("Appending to " + replicaInfo);
  if (replicaInfo.getState() != ReplicaState.FINALIZED) {
    throw new ReplicaNotFoundException(
        ReplicaNotFoundException.UNFINALIZED_REPLICA + b);
  }
  if (replicaInfo.getNumBytes() != expectedBlockLen) {
    throw new IOException("Corrupted replica " + replicaInfo + 
        " with a length of " + replicaInfo.getNumBytes() + 
        " expected length is " + expectedBlockLen);
  }

  FsVolumeReference ref = replicaInfo.getVolume().obtainReference();
  ReplicaBeingWritten replica = null;
  try {
    replica = append(b.getBlockPoolId(), (FinalizedReplica)replicaInfo, newGS,
        b.getNumBytes());
  } catch (IOException e) {
    IOUtils.cleanup(null, ref);
    throw e;
  }
  return new ReplicaHandler(replica, ref);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:FsDatasetImpl.java

示例5: finalizeBlock

/**
 * Complete the block write!
 */
@Override // FsDatasetSpi
public synchronized void finalizeBlock(ExtendedBlock b) throws IOException {
  if (Thread.interrupted()) {
    // Don't allow data modifications from interrupted threads
    throw new IOException("Cannot finalize block from Interrupted Thread");
  }
  ReplicaInfo replicaInfo = getReplicaInfo(b);
  if (replicaInfo.getState() == ReplicaState.FINALIZED) {
    // this is legal, when recovery happens on a file that has
    // been opened for append but never modified
    return;
  }
  finalizeReplica(b.getBlockPoolId(), replicaInfo);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:FsDatasetImpl.java

示例6: getFinalizedBlocks

/**
 * Get the list of finalized blocks from in-memory blockmap for a block pool.
 */
@Override
public synchronized List<FinalizedReplica> getFinalizedBlocks(String bpid) {
  ArrayList<FinalizedReplica> finalized =
      new ArrayList<FinalizedReplica>(volumeMap.size(bpid));
  for (ReplicaInfo b : volumeMap.replicas(bpid)) {
    if(b.getState() == ReplicaState.FINALIZED) {
      finalized.add(new FinalizedReplica((FinalizedReplica)b));
    }
  }
  return finalized;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:FsDatasetImpl.java

示例7: getFinalizedBlocksOnPersistentStorage

/**
 * Get the list of finalized blocks from in-memory blockmap for a block pool.
 */
@Override
public synchronized List<FinalizedReplica> getFinalizedBlocksOnPersistentStorage(String bpid) {
  ArrayList<FinalizedReplica> finalized =
      new ArrayList<FinalizedReplica>(volumeMap.size(bpid));
  for (ReplicaInfo b : volumeMap.replicas(bpid)) {
    if(!b.getVolume().isTransientStorage() &&
       b.getState() == ReplicaState.FINALIZED) {
      finalized.add(new FinalizedReplica((FinalizedReplica)b));
    }
  }
  return finalized;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:FsDatasetImpl.java

示例8: convert

public static ReplicaState convert(ReplicaStateProto state) {
  switch (state) {
  case RBW:
    return ReplicaState.RBW;
  case RUR:
    return ReplicaState.RUR;
  case RWR:
    return ReplicaState.RWR;
  case TEMPORARY:
    return ReplicaState.TEMPORARY;
  case FINALIZED:
  default:
    return ReplicaState.FINALIZED;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:PBHelper.java

示例9: checkBlock

/**
 * Check if a block is valid.
 *
 * @param b           The block to check.
 * @param minLength   The minimum length that the block must have.  May be 0.
 * @param state       If this is null, it is ignored.  If it is non-null, we
 *                        will check that the replica has this state.
 *
 * @throws ReplicaNotFoundException          If the replica is not found
 *
 * @throws UnexpectedReplicaStateException   If the replica is not in the 
 *                                             expected state.
 */
@Override // {@link FsDatasetSpi}
public void checkBlock(ExtendedBlock b, long minLength, ReplicaState state)
    throws ReplicaNotFoundException, UnexpectedReplicaStateException {
  final BInfo binfo = getBInfo(b);
  
  if (binfo == null) {
    throw new ReplicaNotFoundException(b);
  }
  if ((state == ReplicaState.FINALIZED && !binfo.isFinalized()) ||
      (state != ReplicaState.FINALIZED && binfo.isFinalized())) {
    throw new UnexpectedReplicaStateException(b,state);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:SimulatedFSDataset.java

示例10: initReplicaRecovery

@Override
public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
throws IOException {
  ExtendedBlock b = rBlock.getBlock();
  final Map<Block, BInfo> map = getMap(b.getBlockPoolId());
  BInfo binfo = map.get(b.getLocalBlock());
  if (binfo == null) {
    throw new IOException("No such Block " + b );  
  }

  return new ReplicaRecoveryInfo(binfo.getBlockId(), binfo.getBytesOnDisk(), 
      binfo.getGenerationStamp(), 
      binfo.isFinalized()?ReplicaState.FINALIZED : ReplicaState.RBW);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:SimulatedFSDataset.java

示例11: initBlockRecords

private List<BlockRecord> initBlockRecords(DataNode spyDN) throws IOException {
  List<BlockRecord> blocks = new ArrayList<BlockRecord>(1);
  DatanodeRegistration dnR = dn.getDNRegistrationForBP(block.getBlockPoolId());
  BlockRecord blockRecord = new BlockRecord(
      new DatanodeID(dnR), spyDN,
      new ReplicaRecoveryInfo(block.getBlockId(), block.getNumBytes(),
          block.getGenerationStamp(), ReplicaState.FINALIZED));
  blocks.add(blockRecord);
  return blocks;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:10,代码来源:TestBlockRecovery.java

示例12: ReplicaUnderRecovery

public ReplicaUnderRecovery(ReplicaInfo replica, long recoveryId) {
  super(replica, replica.getVolume(), replica.getDir());
  if ( replica.getState() != ReplicaState.FINALIZED &&
       replica.getState() != ReplicaState.RBW &&
       replica.getState() != ReplicaState.RWR ) {
    throw new IllegalArgumentException("Cannot recover replica: " + replica);
  }
  this.original = replica;
  this.recoveryId = recoveryId;
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:10,代码来源:ReplicaUnderRecovery.java

示例13: getBlockListAsLongs

@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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:46,代码来源:BlockListAsLongs.java

示例14: processFirstBlockReport

/**
 * processFirstBlockReport is intended only for processing "initial" block
 * reports, the first block report received from a DN after it registers.
 * It just adds all the valid replicas to the datanode, without calculating 
 * a toRemove list (since there won't be any).  It also silently discards 
 * any invalid blocks, thereby deferring their processing until 
 * the next block report.
 * @param storageInfo - DatanodeStorageInfo that sent the report
 * @param report - the initial block report, to be processed
 * @throws IOException 
 */
private void processFirstBlockReport(
    final DatanodeStorageInfo storageInfo,
    final BlockListAsLongs report) throws IOException {
  if (report == null) return;
  assert (namesystem.hasWriteLock());
  assert (storageInfo.getBlockReportCount() == 0);

  for (BlockReportReplica iblk : report) {
    ReplicaState reportedState = iblk.getState();
    
    if (shouldPostponeBlocksFromFuture &&
        namesystem.isGenStampInFuture(iblk)) {
      queueReportedBlock(storageInfo, iblk, reportedState,
          QUEUE_REASON_FUTURE_GENSTAMP);
      continue;
    }
    
    BlockInfoContiguous storedBlock = blocksMap.getStoredBlock(iblk);
    // If block does not belong to any file, we are done.
    if (storedBlock == null) continue;
    
    // If block is corrupt, mark it and continue to next block.
    BlockUCState ucState = storedBlock.getBlockUCState();
    BlockToMarkCorrupt c = checkReplicaCorrupt(
        iblk, reportedState, storedBlock, ucState,
        storageInfo.getDatanodeDescriptor());
    if (c != null) {
      if (shouldPostponeBlocksFromFuture) {
        // In the Standby, we may receive a block report for a file that we
        // just have an out-of-date gen-stamp or state for, for example.
        queueReportedBlock(storageInfo, iblk, reportedState,
            QUEUE_REASON_CORRUPT_STATE);
      } else {
        markBlockAsCorrupt(c, storageInfo, storageInfo.getDatanodeDescriptor());
      }
      continue;
    }
    
    // If block is under construction, add this replica to its list
    if (isBlockUnderConstruction(storedBlock, ucState, reportedState)) {
      ((BlockInfoContiguousUnderConstruction)storedBlock)
          .addReplicaIfNotPresent(storageInfo, iblk, reportedState);
      // OpenFileBlocks only inside snapshots also will be added to safemode
      // threshold. So we need to update such blocks to safemode
      // refer HDFS-5283
      BlockInfoContiguousUnderConstruction blockUC =
          (BlockInfoContiguousUnderConstruction) storedBlock;
      if (namesystem.isInSnapshot(blockUC)) {
        int numOfReplicas = blockUC.getNumExpectedLocations();
        namesystem.incrementSafeBlockCount(numOfReplicas);
      }
      //and fall through to next clause
    }      
    //add replica if appropriate
    if (reportedState == ReplicaState.FINALIZED) {
      addStoredBlockImmediate(storedBlock, storageInfo);
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:70,代码来源:BlockManager.java

示例15: moveBlockAcrossStorage

/**
 * Move block files from one storage to another storage.
 * @return Returns the Old replicaInfo
 * @throws IOException
 */
@Override
public ReplicaInfo moveBlockAcrossStorage(ExtendedBlock block,
    StorageType targetStorageType) throws IOException {
  ReplicaInfo replicaInfo = getReplicaInfo(block);
  if (replicaInfo.getState() != ReplicaState.FINALIZED) {
    throw new ReplicaNotFoundException(
        ReplicaNotFoundException.UNFINALIZED_REPLICA + block);
  }
  if (replicaInfo.getNumBytes() != block.getNumBytes()) {
    throw new IOException("Corrupted replica " + replicaInfo
        + " with a length of " + replicaInfo.getNumBytes()
        + " expected length is " + block.getNumBytes());
  }
  if (replicaInfo.getVolume().getStorageType() == targetStorageType) {
    throw new ReplicaAlreadyExistsException("Replica " + replicaInfo
        + " already exists on storage " + targetStorageType);
  }

  if (replicaInfo.isOnTransientStorage()) {
    // Block movement from RAM_DISK will be done by LazyPersist mechanism
    throw new IOException("Replica " + replicaInfo
        + " cannot be moved from storageType : "
        + replicaInfo.getVolume().getStorageType());
  }

  try (FsVolumeReference volumeRef = volumes.getNextVolume(
      targetStorageType, block.getNumBytes())) {
    File oldBlockFile = replicaInfo.getBlockFile();
    File oldMetaFile = replicaInfo.getMetaFile();
    FsVolumeImpl targetVolume = (FsVolumeImpl) volumeRef.getVolume();
    // Copy files to temp dir first
    File[] blockFiles = copyBlockFiles(block.getBlockId(),
        block.getGenerationStamp(), oldMetaFile, oldBlockFile,
        targetVolume.getTmpDir(block.getBlockPoolId()),
        replicaInfo.isOnTransientStorage());

    ReplicaInfo newReplicaInfo = new ReplicaInPipeline(
        replicaInfo.getBlockId(), replicaInfo.getGenerationStamp(),
        targetVolume, blockFiles[0].getParentFile(), 0);
    newReplicaInfo.setNumBytes(blockFiles[1].length());
    // Finalize the copied files
    newReplicaInfo = finalizeReplica(block.getBlockPoolId(), newReplicaInfo);

    removeOldReplica(replicaInfo, newReplicaInfo, oldBlockFile, oldMetaFile,
        oldBlockFile.length(), oldMetaFile.length(), block.getBlockPoolId());
  }

  // Replace the old block if any to reschedule the scanning.
  return replicaInfo;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:55,代码来源:FsDatasetImpl.java


注:本文中的org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState.FINALIZED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。