Java Code Examples for org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState#TEMPORARY

The following examples show how to use org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState#TEMPORARY . 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: FsDatasetImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the temporary block file (if any)
 */
@Override // FsDatasetSpi
public synchronized void unfinalizeBlock(ExtendedBlock b) throws IOException {
  ReplicaInfo replicaInfo = volumeMap.get(b.getBlockPoolId(), 
      b.getLocalBlock());
  if (replicaInfo != null && replicaInfo.getState() == ReplicaState.TEMPORARY) {
    // remove from volumeMap
    volumeMap.remove(b.getBlockPoolId(), b.getLocalBlock());
    
    // delete the on-disk temp file
    if (delBlockFromDisk(replicaInfo.getBlockFile(), 
        replicaInfo.getMetaFile(), b.getLocalBlock())) {
      LOG.warn("Block " + b + " unfinalized and removed. " );
    }
    if (replicaInfo.getVolume().isTransientStorage()) {
      ramDiskReplicaTracker.discardReplica(b.getBlockPoolId(), b.getBlockId(), true);
    }
  }
}
 
Example 2
Source File: FsDatasetImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the temporary block file (if any)
 */
@Override // FsDatasetSpi
public synchronized void unfinalizeBlock(ExtendedBlock b) throws IOException {
  ReplicaInfo replicaInfo = volumeMap.get(b.getBlockPoolId(), 
      b.getLocalBlock());
  if (replicaInfo != null && replicaInfo.getState() == ReplicaState.TEMPORARY) {
    // remove from volumeMap
    volumeMap.remove(b.getBlockPoolId(), b.getLocalBlock());
    
    // delete the on-disk temp file
    if (delBlockFromDisk(replicaInfo.getBlockFile(), 
        replicaInfo.getMetaFile(), b.getLocalBlock())) {
      LOG.warn("Block " + b + " unfinalized and removed. " );
    }
    if (replicaInfo.getVolume().isTransientStorage()) {
      ramDiskReplicaTracker.discardReplica(b.getBlockPoolId(), b.getBlockId(), true);
    }
  }
}
 
Example 3
Source File: PBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 4
Source File: PBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 5
Source File: FsDatasetImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override // FsDatasetSpi
public synchronized ReplicaInPipeline convertTemporaryToRbw(
    final ExtendedBlock b) throws IOException {
  final long blockId = b.getBlockId();
  final long expectedGs = b.getGenerationStamp();
  final long visible = b.getNumBytes();
  LOG.info("Convert " + b + " from Temporary to RBW, visible length="
      + visible);

  final ReplicaInPipeline temp;
  {
    // get replica
    final ReplicaInfo r = volumeMap.get(b.getBlockPoolId(), blockId);
    if (r == null) {
      throw new ReplicaNotFoundException(
          ReplicaNotFoundException.NON_EXISTENT_REPLICA + b);
    }
    // check the replica's state
    if (r.getState() != ReplicaState.TEMPORARY) {
      throw new ReplicaAlreadyExistsException(
          "r.getState() != ReplicaState.TEMPORARY, r=" + r);
    }
    temp = (ReplicaInPipeline)r;
  }
  // check generation stamp
  if (temp.getGenerationStamp() != expectedGs) {
    throw new ReplicaAlreadyExistsException(
        "temp.getGenerationStamp() != expectedGs = " + expectedGs
        + ", temp=" + temp);
  }

  // TODO: check writer?
  // set writer to the current thread
  // temp.setWriter(Thread.currentThread());

  // check length
  final long numBytes = temp.getNumBytes();
  if (numBytes < visible) {
    throw new IOException(numBytes + " = numBytes < visible = "
        + visible + ", temp=" + temp);
  }
  // check volume
  final FsVolumeImpl v = (FsVolumeImpl)temp.getVolume();
  if (v == null) {
    throw new IOException("r.getVolume() = null, temp="  + temp);
  }
  
  // move block files to the rbw directory
  BlockPoolSlice bpslice = v.getBlockPoolSlice(b.getBlockPoolId());
  final File dest = moveBlockFiles(b.getLocalBlock(), temp.getBlockFile(), 
      bpslice.getRbwDir());
  // create RBW
  final ReplicaBeingWritten rbw = new ReplicaBeingWritten(
      blockId, numBytes, expectedGs,
      v, dest.getParentFile(), Thread.currentThread(), 0);
  rbw.setBytesAcked(visible);
  // overwrite the RBW in the volume map
  volumeMap.add(b.getBlockPoolId(), rbw);
  return rbw;
}
 
Example 6
Source File: ReplicaInPipeline.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override  //ReplicaInfo
public ReplicaState getState() {
  return ReplicaState.TEMPORARY;
}
 
Example 7
Source File: FsDatasetImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override // FsDatasetSpi
public synchronized ReplicaInPipeline convertTemporaryToRbw(
    final ExtendedBlock b) throws IOException {
  final long blockId = b.getBlockId();
  final long expectedGs = b.getGenerationStamp();
  final long visible = b.getNumBytes();
  LOG.info("Convert " + b + " from Temporary to RBW, visible length="
      + visible);

  final ReplicaInPipeline temp;
  {
    // get replica
    final ReplicaInfo r = volumeMap.get(b.getBlockPoolId(), blockId);
    if (r == null) {
      throw new ReplicaNotFoundException(
          ReplicaNotFoundException.NON_EXISTENT_REPLICA + b);
    }
    // check the replica's state
    if (r.getState() != ReplicaState.TEMPORARY) {
      throw new ReplicaAlreadyExistsException(
          "r.getState() != ReplicaState.TEMPORARY, r=" + r);
    }
    temp = (ReplicaInPipeline)r;
  }
  // check generation stamp
  if (temp.getGenerationStamp() != expectedGs) {
    throw new ReplicaAlreadyExistsException(
        "temp.getGenerationStamp() != expectedGs = " + expectedGs
        + ", temp=" + temp);
  }

  // TODO: check writer?
  // set writer to the current thread
  // temp.setWriter(Thread.currentThread());

  // check length
  final long numBytes = temp.getNumBytes();
  if (numBytes < visible) {
    throw new IOException(numBytes + " = numBytes < visible = "
        + visible + ", temp=" + temp);
  }
  // check volume
  final FsVolumeImpl v = (FsVolumeImpl)temp.getVolume();
  if (v == null) {
    throw new IOException("r.getVolume() = null, temp="  + temp);
  }
  
  // move block files to the rbw directory
  BlockPoolSlice bpslice = v.getBlockPoolSlice(b.getBlockPoolId());
  final File dest = moveBlockFiles(b.getLocalBlock(), temp.getBlockFile(), 
      bpslice.getRbwDir());
  // create RBW
  final ReplicaBeingWritten rbw = new ReplicaBeingWritten(
      blockId, numBytes, expectedGs,
      v, dest.getParentFile(), Thread.currentThread(), 0);
  rbw.setBytesAcked(visible);
  // overwrite the RBW in the volume map
  volumeMap.add(b.getBlockPoolId(), rbw);
  return rbw;
}
 
Example 8
Source File: ReplicaInPipeline.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override  //ReplicaInfo
public ReplicaState getState() {
  return ReplicaState.TEMPORARY;
}