/** 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); } }
/** * Find the file corresponding to the block and return it if it exists. */ ReplicaInfo validateBlockFile(String bpid, long blockId) { //Should we check for metadata file too? final ReplicaInfo r; try (AutoCloseableLock lock = datasetLock.acquire()) { r = volumeMap.get(bpid, blockId); } if (r != null) { if (r.blockDataExists()) { return r; } // if file is not null, but doesn't exist - possibly disk failed datanode.checkDiskErrorAsync(r.getVolume()); } if (LOG.isDebugEnabled()) { LOG.debug("blockId=" + blockId + ", replica=" + r); } return null; }
@Override // FsDatasetSpi public boolean contains(final ExtendedBlock block) { try (AutoCloseableLock lock = datasetLock.acquire()) { final long blockId = block.getLocalBlock().getBlockId(); final String bpid = block.getBlockPoolId(); final ReplicaInfo r = volumeMap.get(bpid, blockId); return (r != null && r.blockDataExists()); } }
throw new UnexpectedReplicaStateException(b,state); if (!replicaInfo.blockDataExists()) { throw new FileNotFoundException(replicaInfo.getBlockURI().toString());
@Override // FsDatasetSpi public InputStream getBlockInputStream(ExtendedBlock b, long seekOffset) throws IOException { ReplicaInfo info; synchronized(this) { info = volumeMap.get(b.getBlockPoolId(), b.getLocalBlock()); } if (info != null && info.getVolume().isTransientStorage()) { ramDiskReplicaTracker.touch(b.getBlockPoolId(), b.getBlockId()); datanode.getMetrics().incrRamDiskBlocksReadHits(); } if(info != null && info.blockDataExists()) { return info.getDataInputStream(seekOffset); } else { throw new IOException("No data exists for block " + b); } }
/** * 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()); } } }
if (!memBlockInfo.blockDataExists()) { if (memBlockInfo.blockDataExists()) { if (memBlockInfo.getBlockURI().compareTo(diskFile.toURI()) != 0) { if (diskMetaFileExists) {