Java Code Examples for org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.RamDiskReplicaTracker.RamDiskReplica#getLazyPersistVolume()

The following examples show how to use org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.RamDiskReplicaTracker.RamDiskReplica#getLazyPersistVolume() . 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 4 votes vote down vote up
/**
 * Attempt to evict one or more transient block replicas we have at least
 * spaceNeeded bytes free.
 */
private void evictBlocks() throws IOException {
  int iterations = 0;

  while (iterations++ < MAX_BLOCK_EVICTIONS_PER_ITERATION &&
         transientFreeSpaceBelowThreshold()) {
    RamDiskReplica replicaState = ramDiskReplicaTracker.getNextCandidateForEviction();

    if (replicaState == null) {
      break;
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Evicting block " + replicaState);
    }

    ReplicaInfo replicaInfo, newReplicaInfo;
    File blockFile, metaFile;
    long blockFileUsed, metaFileUsed;
    final String bpid = replicaState.getBlockPoolId();

    synchronized (FsDatasetImpl.this) {
      replicaInfo = getReplicaInfo(replicaState.getBlockPoolId(), replicaState.getBlockId());
      Preconditions.checkState(replicaInfo.getVolume().isTransientStorage());
      blockFile = replicaInfo.getBlockFile();
      metaFile = replicaInfo.getMetaFile();
      blockFileUsed = blockFile.length();
      metaFileUsed = metaFile.length();
      ramDiskReplicaTracker.discardReplica(replicaState.getBlockPoolId(),
          replicaState.getBlockId(), false);

      // Move the replica from lazyPersist/ to finalized/ on target volume
      BlockPoolSlice bpSlice =
          replicaState.getLazyPersistVolume().getBlockPoolSlice(bpid);
      File newBlockFile = bpSlice.activateSavedReplica(
          replicaInfo, replicaState.getSavedMetaFile(),
          replicaState.getSavedBlockFile());

      newReplicaInfo =
          new FinalizedReplica(replicaInfo.getBlockId(),
                               replicaInfo.getBytesOnDisk(),
                               replicaInfo.getGenerationStamp(),
                               replicaState.getLazyPersistVolume(),
                               newBlockFile.getParentFile());

      // Update the volumeMap entry.
      volumeMap.add(bpid, newReplicaInfo);

      // Update metrics
      datanode.getMetrics().incrRamDiskBlocksEvicted();
      datanode.getMetrics().addRamDiskBlocksEvictionWindowMs(
          Time.monotonicNow() - replicaState.getCreationTime());
      if (replicaState.getNumReads() == 0) {
        datanode.getMetrics().incrRamDiskBlocksEvictedWithoutRead();
      }
    }

    removeOldReplica(replicaInfo, newReplicaInfo, blockFile, metaFile,
        blockFileUsed, metaFileUsed, bpid);
  }
}
 
Example 2
Source File: FsDatasetImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Attempt to evict one or more transient block replicas we have at least
 * spaceNeeded bytes free.
 */
private void evictBlocks() throws IOException {
  int iterations = 0;

  while (iterations++ < MAX_BLOCK_EVICTIONS_PER_ITERATION &&
         transientFreeSpaceBelowThreshold()) {
    RamDiskReplica replicaState = ramDiskReplicaTracker.getNextCandidateForEviction();

    if (replicaState == null) {
      break;
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Evicting block " + replicaState);
    }

    ReplicaInfo replicaInfo, newReplicaInfo;
    File blockFile, metaFile;
    long blockFileUsed, metaFileUsed;
    final String bpid = replicaState.getBlockPoolId();

    synchronized (FsDatasetImpl.this) {
      replicaInfo = getReplicaInfo(replicaState.getBlockPoolId(), replicaState.getBlockId());
      Preconditions.checkState(replicaInfo.getVolume().isTransientStorage());
      blockFile = replicaInfo.getBlockFile();
      metaFile = replicaInfo.getMetaFile();
      blockFileUsed = blockFile.length();
      metaFileUsed = metaFile.length();
      ramDiskReplicaTracker.discardReplica(replicaState.getBlockPoolId(),
          replicaState.getBlockId(), false);

      // Move the replica from lazyPersist/ to finalized/ on target volume
      BlockPoolSlice bpSlice =
          replicaState.getLazyPersistVolume().getBlockPoolSlice(bpid);
      File newBlockFile = bpSlice.activateSavedReplica(
          replicaInfo, replicaState.getSavedMetaFile(),
          replicaState.getSavedBlockFile());

      newReplicaInfo =
          new FinalizedReplica(replicaInfo.getBlockId(),
                               replicaInfo.getBytesOnDisk(),
                               replicaInfo.getGenerationStamp(),
                               replicaState.getLazyPersistVolume(),
                               newBlockFile.getParentFile());

      // Update the volumeMap entry.
      volumeMap.add(bpid, newReplicaInfo);

      // Update metrics
      datanode.getMetrics().incrRamDiskBlocksEvicted();
      datanode.getMetrics().addRamDiskBlocksEvictionWindowMs(
          Time.monotonicNow() - replicaState.getCreationTime());
      if (replicaState.getNumReads() == 0) {
        datanode.getMetrics().incrRamDiskBlocksEvictedWithoutRead();
      }
    }

    removeOldReplica(replicaInfo, newReplicaInfo, blockFile, metaFile,
        blockFileUsed, metaFileUsed, bpid);
  }
}