@Override public String toString() { // Called in AsyncLazyPersistService.execute for displaying error messages. return "LazyWriter async task of persist RamDisk block pool id:" + bpId + " block pool id: " + blockId + " with block file " + replicaInfo.getBlockURI() + " and meta file " + replicaInfo.getMetadataURI() + " to target volume " + targetVolume; }
/** * Get a target subdirectory under trash/ for a given block file that is being * deleted. * * The subdirectory structure under trash/ mirrors that under current/ to keep * implicit memory of where the files are to be restored (if necessary). * * @return the trash directory for a given block file that is being deleted. */ public String getTrashDirectory(ReplicaInfo info) { URI blockURI = info.getBlockURI(); try{ File blockFile = new File(blockURI); return getTrashDirectory(blockFile); } catch (IllegalArgumentException e) { LOG.warn("Failed to get block file for replica {}", info, e); } return null; }
static File moveBlockFiles(Block b, ReplicaInfo replicaInfo, File destdir) throws IOException { final File dstfile = new File(destdir, b.getBlockName()); final File dstmeta = FsDatasetUtil.getMetaFile(dstfile, b.getGenerationStamp()); try { replicaInfo.renameMeta(dstmeta.toURI()); } catch (IOException e) { throw new IOException("Failed to move meta file for " + b + " from " + replicaInfo.getMetadataURI() + " to " + dstmeta, e); } try { replicaInfo.renameData(dstfile.toURI()); } catch (IOException e) { throw new IOException("Failed to move block file for " + b + " from " + replicaInfo.getBlockURI() + " to " + dstfile.getAbsolutePath(), e); } if (LOG.isDebugEnabled()) { LOG.debug("addFinalizedBlock: Moved " + replicaInfo.getMetadataURI() + " to " + dstmeta + " and " + replicaInfo.getBlockURI() + " to " + dstfile); } return dstfile; }
static File[] copyBlockFiles(ReplicaInfo srcReplica, File dstMeta, File dstFile, boolean calculateChecksum, int smallBufferSize, final Configuration conf) throws IOException { if (calculateChecksum) { computeChecksum(srcReplica, dstMeta, smallBufferSize, conf); } else { try { srcReplica.copyMetadata(dstMeta.toURI()); } catch (IOException e) { throw new IOException("Failed to copy " + srcReplica + " metadata to " + dstMeta, e); } } try { srcReplica.copyBlockdata(dstFile.toURI()); } catch (IOException e) { throw new IOException("Failed to copy " + srcReplica + " block file to " + dstFile, e); } if (LOG.isDebugEnabled()) { if (calculateChecksum) { LOG.debug("Copied " + srcReplica.getMetadataURI() + " meta to " + dstMeta + " and calculated checksum"); } else { LOG.debug("Copied " + srcReplica.getBlockURI() + " to " + dstFile); } } return new File[] {dstMeta, dstFile}; }
@Override public String toString() { // Called in AsyncDiskService.execute for displaying error messages. return "deletion of block " + block.getBlockPoolId() + " " + block.getLocalBlock() + " with block file " + replicaToDelete.getBlockURI() + " and meta file " + replicaToDelete.getMetadataURI() + " from volume " + volume; }
@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(); }
private boolean moveFiles() { if (trashDirectory == null) { LOG.error("Trash dir for replica " + replicaToDelete + " is null"); return false; } File trashDirFile = new File(trashDirectory); try { volume.getFileIoProvider().mkdirsWithExistsCheck( volume, trashDirFile); } catch (IOException e) { return false; } if (LOG.isDebugEnabled()) { LOG.debug("Moving files " + replicaToDelete.getBlockURI() + " and " + replicaToDelete.getMetadataURI() + " to trash."); } final String blockName = replicaToDelete.getBlockName(); final long genstamp = replicaToDelete.getGenerationStamp(); File newBlockFile = new File(trashDirectory, blockName); File newMetaFile = new File(trashDirectory, DatanodeUtil.getMetaName(blockName, genstamp)); try { return (replicaToDelete.renameData(newBlockFile.toURI()) && replicaToDelete.renameMeta(newMetaFile.toURI())); } catch (IOException e) { LOG.error("Error moving files to trash: " + replicaToDelete, e); } return false; }
@VisibleForTesting static ReplicaInfo selectReplicaToDelete(final ReplicaInfo replica1, final ReplicaInfo replica2) { ReplicaInfo replicaToKeep; ReplicaInfo replicaToDelete; // it's the same block so don't ever delete it, even if GS or size // differs. caller should keep the one it just discovered on disk if (replica1.getBlockURI().equals(replica2.getBlockURI())) { return null; } if (replica1.getGenerationStamp() != replica2.getGenerationStamp()) { replicaToKeep = replica1.getGenerationStamp() > replica2.getGenerationStamp() ? replica1 : replica2; } else if (replica1.getNumBytes() != replica2.getNumBytes()) { replicaToKeep = replica1.getNumBytes() > replica2.getNumBytes() ? replica1 : replica2; } else if (replica1.getVolume().isTransientStorage() && !replica2.getVolume().isTransientStorage()) { replicaToKeep = replica2; } else { replicaToKeep = replica1; } replicaToDelete = (replicaToKeep == replica1) ? replica2 : replica1; if (LOG.isDebugEnabled()) { LOG.debug("resolveDuplicateReplicas decide to keep " + replicaToKeep + ". Will try to delete " + replicaToDelete); } return replicaToDelete; }
blockFileName = info.getBlockURI().toString(); length = info.getVisibleLength(); genstamp = info.getGenerationStamp();
throw new FileNotFoundException(replicaInfo.getBlockURI().toString());
@Override // FsDatasetSpi public BlockLocalPathInfo getBlockLocalPathInfo(ExtendedBlock block) throws IOException { try (AutoCloseableLock lock = datasetLock.acquire()) { final Replica replica = volumeMap.get(block.getBlockPoolId(), block.getBlockId()); if (replica == null) { throw new ReplicaNotFoundException(block); } if (replica.getGenerationStamp() < block.getGenerationStamp()) { throw new IOException( "Replica generation stamp < block generation stamp, block=" + block + ", replica=" + replica); } else if (replica.getGenerationStamp() > block.getGenerationStamp()) { block.setGenerationStamp(replica.getGenerationStamp()); } } ReplicaInfo r = getBlockReplica(block); File blockFile = new File(r.getBlockURI()); File metaFile = new File(r.getMetadataURI()); BlockLocalPathInfo info = new BlockLocalPathInfo(block, blockFile.getAbsolutePath(), metaFile.toString()); return info; }
File blockFile = new File(info.getBlockURI()); if (blockFile != null && blockFile.getParentFile() == null) { errors.add("Failed to delete replica " + invalidBlks[i] addDeletingBlock(bpid, removing.getBlockId()); if (LOG.isDebugEnabled()) { LOG.debug("Block file " + removing.getBlockURI() + " is to be deleted");
@Override public void run() { final long blockLength = replicaToDelete.getBlockDataLength(); final long metaLength = replicaToDelete.getMetadataLength(); boolean result; result = (trashDirectory == null) ? deleteFiles() : moveFiles(); if (!result) { LOG.warn("Unexpected error trying to " + (trashDirectory == null ? "delete" : "move") + " block " + block.getBlockPoolId() + " " + block.getLocalBlock() + " at file " + replicaToDelete.getBlockURI() + ". Ignored."); } else { if(block.getLocalBlock().getNumBytes() != BlockCommand.NO_ACK){ datanode.notifyNamenodeDeletedBlock(block, volume.getStorageID()); } volume.onBlockFileDeletion(block.getBlockPoolId(), blockLength); volume.onMetaFileDeletion(block.getBlockPoolId(), metaLength); LOG.info("Deleted " + block.getBlockPoolId() + " " + block.getLocalBlock() + " URI " + replicaToDelete.getBlockURI()); } updateDeletedBlockId(block); IOUtils.cleanup(null, volumeRef); } }
if (memBlockInfo.getBlockURI().compareTo(diskFile.toURI()) != 0) { if (diskMetaFileExists) { if (memBlockInfo.metadataExists()) { + memBlockInfo.getBlockURI() + " does not exist. Updating it to the file found during scan " + diskFile.getAbsolutePath()); File memFile = new File(memBlockInfo.getBlockURI()); long gs = diskMetaFileExists && diskMetaFile.getParent().equals(memFile.getParent()) ? diskGS