/** @return the lease containing src */ public synchronized Lease getLease(INodeFile src) {return leasesById.get(src.getId());}
private void updateRemovedUnderConstructionFiles( ReclaimContext reclaimContext) { if (isUnderConstruction() && reclaimContext.removedUCFiles != null) { reclaimContext.removedUCFiles.add(getId()); } }
boolean addFileDiff(INodeFile file, byte[][] relativePath) { if (getTotalEntries() < maxEntries) { modifiedList.add(new DiffReportListingEntry(file.getId(), file.getId(), relativePath,false, null)); } else { setLastPath(relativePath); return false; } return true; } /** @return True if {@link #from} is earlier than {@link #to} */
/** * Remove the lease for the specified holder and src */ synchronized void removeLease(String holder, INodeFile src) { Lease lease = getLease(holder); if (lease != null) { removeLease(lease, src.getId()); } else { LOG.warn("Removing non-existent lease! holder={} src={}", holder, src .getFullPathName()); } }
void setLastBlock(BlockInfo blk) { blk.setBlockCollectionId(this.getId()); setBlock(numBlocks() - 1, blk); }
b.append(FSDirectory.DOT_RESERVED_PATH_PREFIX) .append(Path.SEPARATOR).append(FSDirectory.DOT_INODES_STRING) .append(Path.SEPARATOR).append(entry.getValue().getId()); FSImageSerialization.writeINodeUnderConstruction( out, entry.getValue(), b.toString());
FileEdekInfo(FSDirectory dir, INodeFile inode) throws IOException { assert dir.hasReadLock(); Preconditions.checkNotNull(inode, "INodeFile is null"); inodeId = inode.getId(); final FileEncryptionInfo fei = FSDirEncryptionZoneOp .getFileEncryptionInfo(dir, INodesInPath.fromINode(inode)); Preconditions.checkNotNull(fei, "FileEncryptionInfo is null for " + inodeId); existingEdek = EncryptedKeyVersion .createForDecryption(fei.getKeyName(), fei.getEzKeyVersionName(), fei.getIV(), fei.getEncryptedDataEncryptionKey()); }
static void writeINodeUnderConstruction(DataOutputStream out, INodeFile cons, String path) throws IOException { writeString(path, out); out.writeLong(cons.getId()); out.writeShort(cons.getFileReplication()); out.writeLong(cons.getModificationTime()); out.writeLong(cons.getPreferredBlockSize()); writeBlocks(cons.getBlocks(), out); cons.getPermissionStatus().write(out); FileUnderConstructionFeature uc = cons.getFileUnderConstructionFeature(); writeString(uc.getClientName(), out); writeString(uc.getClientMachine(), out); out.writeInt(0); // do not store locations of last block }
/** * append array of blocks to this.blocks */ void concatBlocks(INodeFile[] inodes, BlockManager bm) { int size = this.blocks.length; int totalAddedBlocks = 0; for(INodeFile f : inodes) { Preconditions.checkState(f.isStriped() == this.isStriped()); totalAddedBlocks += f.blocks.length; } BlockInfo[] newlist = new BlockInfo[size + totalAddedBlocks]; System.arraycopy(this.blocks, 0, newlist, 0, size); for(INodeFile in: inodes) { System.arraycopy(in.blocks, 0, newlist, size, in.blocks.length); size += in.blocks.length; } setBlocks(newlist); for(BlockInfo b : blocks) { b.setBlockCollectionId(getId()); short oldRepl = b.getReplication(); short repl = getPreferredBlockReplication(); if (oldRepl != repl) { bm.setReplication(oldRepl, repl, b); } } }
openFileEntries.add(new OpenFileEntry(inodeFile.getId(), fullPathName, inodeFile.getFileUnderConstructionFeature().getClientName(), inodeFile.getFileUnderConstructionFeature().getClientMachine()));
/** * Serialize a {@link INodeFile} node * @param file The INodeFile to write * @param out The {@link DataOutputStream} where the fields are written * @param writeUnderConstruction Whether to write under construction information */ public static void writeINodeFile(INodeFile file, DataOutput out, boolean writeUnderConstruction) throws IOException { writeLocalName(file, out); out.writeLong(file.getId()); out.writeShort(file.getFileReplication()); out.writeLong(file.getModificationTime()); out.writeLong(file.getAccessTime()); out.writeLong(file.getPreferredBlockSize()); writeBlocks(file.getBlocks(), out); SnapshotFSImageFormat.saveFileDiffList(file, out); if (writeUnderConstruction) { if (file.isUnderConstruction()) { out.writeBoolean(true); final FileUnderConstructionFeature uc = file.getFileUnderConstructionFeature(); writeString(uc.getClientName(), out); writeString(uc.getClientMachine(), out); } else { out.writeBoolean(false); } } writePermissionStatus(file, out); }
void serializeFilesUCSection(OutputStream out) throws IOException { Collection<Long> filesWithUC = fsn.getLeaseManager() .getINodeIdWithLeases(); for (Long id : filesWithUC) { INode inode = fsn.getFSDirectory().getInode(id); if (inode == null) { LOG.warn("Fail to find inode " + id + " when saving the leases."); continue; } INodeFile file = inode.asFile(); if (!file.isUnderConstruction()) { LOG.warn("Fail to save the lease for inode id " + id + " as the file is not under construction"); continue; } String path = file.getFullPathName(); FileUnderConstructionEntry.Builder b = FileUnderConstructionEntry .newBuilder().setInodeId(file.getId()).setFullPath(path); FileUnderConstructionEntry e = b.build(); e.writeDelimitedTo(out); } parent.commitSection(summary, FSImageFormatProtobuf.SectionName.FILES_UNDERCONSTRUCTION); }
if (org.apache.commons.lang3.StringUtils.isEmpty(path) || fullPathName.startsWith(path)) { openFileEntries.add(new OpenFileEntry(inodeFile.getId(), inodeFile.getFullPathName(), inodeFile.getFileUnderConstructionFeature().getClientName(),
boolean isFileDeleted(INodeFile file) { assert hasReadLock(); if (dir.getInode(file.getId()) == null) { return true;
private void serializeFileDiffList(INodeFile file, OutputStream out) throws IOException { FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature(); if (sf != null) { DiffList<FileDiff> diffList = sf.getDiffs().asList(); SnapshotDiffSection.DiffEntry entry = SnapshotDiffSection.DiffEntry .newBuilder().setInodeId(file.getId()).setType(Type.FILEDIFF) .setNumOfDiff(diffList.size()).build(); entry.writeDelimitedTo(out); for (int i = diffList.size() - 1; i >= 0; i--) { FileDiff diff = diffList.get(i); SnapshotDiffSection.FileDiff.Builder fb = SnapshotDiffSection.FileDiff .newBuilder().setSnapshotId(diff.getSnapshotId()) .setFileSize(diff.getFileSize()); if(diff.getBlocks() != null) { for(Block block : diff.getBlocks()) { fb.addBlocks(PBHelperClient.convert(block)); } } INodeFileAttributes copy = diff.snapshotINode; if (copy != null) { fb.setName(ByteString.copyFrom(copy.getLocalNameBytes())) .setSnapshotCopy(buildINodeFile(copy, parent.getSaverContext())); } fb.build().writeDelimitedTo(out); } } }
file.toUnderConstruction(uc.getClientName(), uc.getClientMachine()); fsn.leaseManager.addLease(uc.getClientName(), file.getId()); if (blocks.length > 0) { BlockInfo lastBlk = file.getLastBlock();
file.getFileUnderConstructionFeature().getClientName(), file.getId());
PermissionStatus permissions = newNode.getPermissionStatus(); AddOp op = AddOp.getInstance(cache.get()) .setInodeId(newNode.getId()) .setPath(path) .setReplication(newNode.getFileReplication())