/** * Copy constructor. * @param from where to copy construct from */ public FinalizedReplica(FinalizedReplica from) { super(from); this.setLastPartialChunkChecksum(from.getLastPartialChunkChecksum()); }
private ChunkChecksum getPartialChunkChecksumForFinalized( FinalizedReplica finalized) throws IOException { // There are a number of places in the code base where a finalized replica // object is created. If last partial checksum is loaded whenever a // finalized replica is created, it would increase latency in DataNode // initialization. Therefore, the last partial chunk checksum is loaded // lazily. // Load last checksum in case the replica is being written concurrently final long replicaVisibleLength = replica.getVisibleLength(); if (replicaVisibleLength % CHUNK_SIZE != 0 && finalized.getLastPartialChunkChecksum() == null) { // the finalized replica does not have precomputed last partial // chunk checksum. Recompute now. try { finalized.loadLastPartialChunkChecksum(); return new ChunkChecksum(finalized.getVisibleLength(), finalized.getLastPartialChunkChecksum()); } catch (FileNotFoundException e) { // meta file is lost. Continue anyway to preserve existing behavior. DataNode.LOG.warn( "meta file " + finalized.getMetaFile() + " is missing!"); return null; } } else { // If the checksum is null, BlockSender will use on-disk checksum. return new ChunkChecksum(finalized.getVisibleLength(), finalized.getLastPartialChunkChecksum()); } }
finalized.getVisibleLength(), finalized.getLastPartialChunkChecksum());
/** * * @param bytesReserved Space that was reserved during * block creation. Now that the block is being finalized we * can free up this space. * @return * @throws IOException */ ReplicaInfo addFinalizedBlock(String bpid, Block b, ReplicaInfo replicaInfo, long bytesReserved) throws IOException { releaseReservedSpace(bytesReserved); File dest = getBlockPoolSlice(bpid).addFinalizedBlock(b, replicaInfo); byte[] checksum = null; // copy the last partial checksum if the replica is originally // in finalized or rbw state. if (replicaInfo.getState() == ReplicaState.FINALIZED) { FinalizedReplica finalized = (FinalizedReplica)replicaInfo; checksum = finalized.getLastPartialChunkChecksum(); } else if (replicaInfo.getState() == ReplicaState.RBW) { ReplicaBeingWritten rbw = (ReplicaBeingWritten)replicaInfo; checksum = rbw.getLastChecksumAndDataLen().getChecksum(); } return new ReplicaBuilder(ReplicaState.FINALIZED) .setBlock(replicaInfo) .setFsVolume(this) .setDirectoryToUse(dest.getParentFile()) .setLastPartialChunkChecksum(checksum) .build(); }