/** Check the files of a replica. */ static void checkReplicaFiles(final ReplicaInfo r) throws IOException { //check replica's data exists if (!r.blockDataExists()) { throw new FileNotFoundException("Block data not found, r=" + r); } if (r.getBytesOnDisk() != r.getBlockDataLength()) { throw new IOException("Block length mismatch, len=" + r.getBlockDataLength() + " but r=" + r); } //check replica's meta file if (!r.metadataExists()) { throw new IOException(r.getMetadataURI() + " does not exist, r=" + r); } if (r.getMetadataLength() == 0) { throw new IOException("Metafile is empty, r=" + r); } }
@Override //Object public String toString() { return getClass().getSimpleName() + ", " + super.toString() + ", " + getState() + "\n getNumBytes() = " + getNumBytes() + "\n getBytesOnDisk() = " + getBytesOnDisk() + "\n getVisibleLength()= " + getVisibleLength() + "\n getVolume() = " + getVolume() + "\n getBlockURI() = " + getBlockURI(); }
@Override // FsDatasetSpi public Block getStoredBlock(String bpid, long blkid) throws IOException { try (AutoCloseableLock lock = datasetLock.acquire()) { ReplicaInfo r = volumeMap.get(bpid, blkid); if (r == null) { return null; } return new Block(blkid, r.getBytesOnDisk(), r.getGenerationStamp()); } }
/** * Move a persisted replica from lazypersist directory to a subdirectory * under finalized. */ ReplicaInfo activateSavedReplica(ReplicaInfo replicaInfo, RamDiskReplica replicaState) throws IOException { File metaFile = replicaState.getSavedMetaFile(); File blockFile = replicaState.getSavedBlockFile(); final long blockId = replicaInfo.getBlockId(); final File blockDir = DatanodeUtil.idToBlockDir(finalizedDir, blockId); final File targetBlockFile = new File(blockDir, blockFile.getName()); final File targetMetaFile = new File(blockDir, metaFile.getName()); fileIoProvider.moveFile(volume, blockFile, targetBlockFile); FsDatasetImpl.LOG.info("Moved " + blockFile + " to " + targetBlockFile); fileIoProvider.moveFile(volume, metaFile, targetMetaFile); FsDatasetImpl.LOG.info("Moved " + metaFile + " to " + targetMetaFile); ReplicaInfo newReplicaInfo = new ReplicaBuilder(ReplicaState.FINALIZED) .setBlockId(blockId) .setLength(replicaInfo.getBytesOnDisk()) .setGenerationStamp(replicaInfo.getGenerationStamp()) .setFsVolume(replicaState.getLazyPersistVolume()) .setDirectoryToUse(targetBlockFile.getParentFile()) .build(); return newReplicaInfo; }
/** * Cleanup the replicaInfo object passed. * * @param bpid - block pool id * @param replicaInfo - ReplicaInfo */ private void cleanupReplica(String bpid, ReplicaInfo replicaInfo) { if (replicaInfo.deleteBlockData() || !replicaInfo.blockDataExists()) { FsVolumeImpl volume = (FsVolumeImpl) replicaInfo.getVolume(); volume.onBlockFileDeletion(bpid, replicaInfo.getBytesOnDisk()); if (replicaInfo.deleteMetadata() || !replicaInfo.metadataExists()) { volume.onMetaFileDeletion(bpid, replicaInfo.getMetadataLength()); } } }
@Override public long getBytesOnDisk() { return original.getBytesOnDisk(); }
@Override public long getBytesOnDisk() { return original.getBytesOnDisk(); }
if (replica.getBytesOnDisk() < replica.getVisibleLength()) { throw new IOException("getBytesOnDisk() < getVisibleLength(), rip=" + replica);
if (replica.getBytesOnDisk() != oldBlock.getNumBytes()) { throw new IOException("THIS IS NOT SUPPOSED TO HAPPEN:" + " replica.getBytesOnDisk() != block.getNumBytes(), block="
/** Check the files of a replica. */ static void checkReplicaFiles(final ReplicaInfo r) throws IOException { //check replica's file final File f = r.getBlockFile(); if (!f.exists()) { throw new FileNotFoundException("File " + f + " not found, r=" + r); } if (r.getBytesOnDisk() != f.length()) { throw new IOException("File length mismatched. The length of " + f + " is " + f.length() + " but r=" + r); } //check replica's meta file final File metafile = FsDatasetUtil.getMetaFile(f, r.getGenerationStamp()); if (!metafile.exists()) { throw new IOException("Metafile " + metafile + " does not exist, r=" + r); } if (metafile.length() == 0) { throw new IOException("Metafile " + metafile + " is empty, r=" + r); } }
/** Check the files of a replica. */ static void checkReplicaFiles(final ReplicaInfo r) throws IOException { //check replica's file final File f = r.getBlockFile(); if (!f.exists()) { throw new FileNotFoundException("File " + f + " not found, r=" + r); } if (r.getBytesOnDisk() != f.length()) { throw new IOException("File length mismatched. The length of " + f + " is " + f.length() + " but r=" + r); } //check replica's meta file final File metafile = FsDatasetUtil.getMetaFile(f, r.getGenerationStamp()); if (!metafile.exists()) { throw new IOException("Metafile " + metafile + " does not exist, r=" + r); } if (metafile.length() == 0) { throw new IOException("Metafile " + metafile + " is empty, r=" + r); } }
@Override //Object public String toString() { return getClass().getSimpleName() + ", " + super.toString() + ", " + getState() + "\n getNumBytes() = " + getNumBytes() + "\n getBytesOnDisk() = " + getBytesOnDisk() + "\n getVisibleLength()= " + getVisibleLength() + "\n getVolume() = " + getVolume() + "\n getBlockFile() = " + getBlockFile(); }
@Override //Object public String toString() { return getClass().getSimpleName() + ", " + super.toString() + ", " + getState() + "\n getNumBytes() = " + getNumBytes() + "\n getBytesOnDisk() = " + getBytesOnDisk() + "\n getVisibleLength()= " + getVisibleLength() + "\n getVolume() = " + getVolume() + "\n getBlockFile() = " + getBlockFile(); }
public ReplicaRecoveryInfo createInfo() { return new ReplicaRecoveryInfo(original.getBlockId(), original.getBytesOnDisk(), original.getGenerationStamp(), original.getState()); } }
public ReplicaRecoveryInfo createInfo() { return new ReplicaRecoveryInfo(original.getBlockId(), original.getBytesOnDisk(), original.getGenerationStamp(), original.getState()); } }
private static void assertEquals(ReplicaInfo originalInfo, ReplicaRecoveryInfo recoveryInfo) { Assert.assertEquals(originalInfo.getBlockId(), recoveryInfo.getBlockId()); Assert.assertEquals(originalInfo.getGenerationStamp(), recoveryInfo.getGenerationStamp()); Assert.assertEquals(originalInfo.getBytesOnDisk(), recoveryInfo.getNumBytes()); Assert.assertEquals(originalInfo.getState(), recoveryInfo.getOriginalReplicaState()); }
replicaInfo.getBytesOnDisk(), replicaInfo.getGenerationStamp(), replicaState.getLazyPersistVolume(),
if (replica.getBytesOnDisk() != oldBlock.getNumBytes()) { throw new IOException("THIS IS NOT SUPPOSED TO HAPPEN:" + " replica.getBytesOnDisk() != block.getNumBytes(), block="
private static void assertEquals(ReplicaInfo originalInfo, ReplicaRecoveryInfo recoveryInfo) { Assert.assertEquals(originalInfo.getBlockId(), recoveryInfo.getBlockId()); Assert.assertEquals(originalInfo.getGenerationStamp(), recoveryInfo.getGenerationStamp()); Assert.assertEquals(originalInfo.getBytesOnDisk(), recoveryInfo.getNumBytes()); Assert.assertEquals(originalInfo.getState(), recoveryInfo.getOriginalReplicaState()); }
replicaInfo.getBytesOnDisk(), replicaInfo.getGenerationStamp(), replicaState.getLazyPersistVolume(),