Search in sources :

Example 1 with LocalReplica

use of org.apache.hadoop.hdfs.server.datanode.LocalReplica in project hadoop by apache.

the class FsVolumeImpl method append.

public ReplicaInPipeline append(String bpid, ReplicaInfo replicaInfo, long newGS, long estimateBlockLen) throws IOException {
    long bytesReserved = estimateBlockLen - replicaInfo.getNumBytes();
    if (getAvailable() < bytesReserved) {
        throw new DiskOutOfSpaceException("Insufficient space for appending to " + replicaInfo);
    }
    assert replicaInfo.getVolume() == this : "The volume of the replica should be the same as this volume";
    // construct a RBW replica with the new GS
    File newBlkFile = new File(getRbwDir(bpid), replicaInfo.getBlockName());
    LocalReplicaInPipeline newReplicaInfo = new ReplicaBuilder(ReplicaState.RBW).setBlockId(replicaInfo.getBlockId()).setLength(replicaInfo.getNumBytes()).setGenerationStamp(newGS).setFsVolume(this).setDirectoryToUse(newBlkFile.getParentFile()).setWriterThread(Thread.currentThread()).setBytesToReserve(bytesReserved).buildLocalReplicaInPipeline();
    // load last checksum and datalen
    LocalReplica localReplica = (LocalReplica) replicaInfo;
    byte[] lastChunkChecksum = loadLastPartialChunkChecksum(localReplica.getBlockFile(), localReplica.getMetaFile());
    newReplicaInfo.setLastChecksumAndDataLen(replicaInfo.getNumBytes(), lastChunkChecksum);
    // rename meta file to rbw directory
    // rename block file to rbw directory
    newReplicaInfo.moveReplicaFrom(replicaInfo, newBlkFile);
    reserveSpaceForReplica(bytesReserved);
    return newReplicaInfo;
}
Also used : DiskOutOfSpaceException(org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException) LocalReplica(org.apache.hadoop.hdfs.server.datanode.LocalReplica) ReplicaBuilder(org.apache.hadoop.hdfs.server.datanode.ReplicaBuilder) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LocalReplicaInPipeline(org.apache.hadoop.hdfs.server.datanode.LocalReplicaInPipeline)

Aggregations

File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 LocalReplica (org.apache.hadoop.hdfs.server.datanode.LocalReplica)1 LocalReplicaInPipeline (org.apache.hadoop.hdfs.server.datanode.LocalReplicaInPipeline)1 ReplicaBuilder (org.apache.hadoop.hdfs.server.datanode.ReplicaBuilder)1 DiskOutOfSpaceException (org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException)1