@Override public INodeFile getBlockCollection(long id) { INode inode = getFSDirectory().getInode(id); return inode == null ? null : inode.asFile(); }
/** * Load the deleted list in a DirectoryDiff */ private List<INode> loadDeletedList(final List<INodeReference> refList, InputStream in, INodeDirectory dir, List<Long> deletedNodes, List<Integer> deletedRefNodes) throws IOException { List<INode> dlist = new ArrayList<INode>(deletedRefNodes.size() + deletedNodes.size()); // load non-reference inodes for (long deletedId : deletedNodes) { INode deleted = fsDir.getInode(deletedId); dlist.add(deleted); addToDeletedList(deleted, dir); } // load reference nodes in the deleted list for (int refId : deletedRefNodes) { INodeReference deletedRef = refList.get(refId); dlist.add(deletedRef); addToDeletedList(deletedRef, dir); } Collections.sort(dlist, new Comparator<INode>() { @Override public int compare(INode n1, INode n2) { return n1.compareTo(n2.getLocalNameBytes()); } }); return dlist; }
private synchronized INode[] getINodesWithLease() { List<INode> inodes = new ArrayList<>(leasesById.size()); INode currentINode; for (long inodeId : leasesById.keySet()) { currentINode = fsnamesystem.getFSDirectory().getInode(inodeId); // A file with an active lease could get deleted, or its // parent directories could get recursively deleted. if (currentINode != null && currentINode.isFile() && !fsnamesystem.isFileDeleted(currentINode.asFile())) { inodes.add(currentINode); } } return inodes.toArray(new INode[0]); }
/** * Returns the full path from an INode id. * <p/> * Called while holding the FSDirectory lock. */ String getFullPathName(Long nodeId) { assert dir.hasReadLock(); INode inode = dir.getInode(nodeId); if (inode == null) { return null; } return inode.getFullPathName(); }
INodeFile file = dir.getInode(id).asFile(); String path = file.getFullPathName(); FSImageSerialization.writeINodeUnderConstruction(
void loadINodeDirectorySection(InputStream in) throws IOException { final List<INodeReference> refList = parent.getLoaderContext() .getRefList(); while (true) { INodeDirectorySection.DirEntry e = INodeDirectorySection.DirEntry .parseDelimitedFrom(in); // note that in is a LimitedInputStream if (e == null) { break; } INodeDirectory p = dir.getInode(e.getParent()).asDirectory(); for (long id : e.getChildrenList()) { INode child = dir.getInode(id); addToParent(p, child); } for (int refId : e.getRefChildrenList()) { INodeReference ref = refList.get(refId); addToParent(p, ref); } } }
INodesInPath resolvePath(FSPermissionChecker pc, String src, long fileId) throws UnresolvedLinkException, FileNotFoundException, AccessControlException, ParentNotDirectoryException { // Older clients may not have given us an inode ID to work with. // In this case, we have to try to resolve the path and hope it // hasn't changed or been deleted since the file was opened for write. INodesInPath iip; if (fileId == HdfsConstants.GRANDFATHER_INODE_ID) { iip = resolvePath(pc, src, DirOp.WRITE); } else { INode inode = getInode(fileId); if (inode == null) { iip = INodesInPath.fromComponents(INode.getPathComponents(src)); } else { iip = INodesInPath.fromINode(inode); } } return iip; }
return new byte[][]{INodeDirectory.ROOT_NAME}; INode inode = fsd.getInode(id); if (inode == null) { throw new FileNotFoundException(
/** * Resolves the path to inode id, then check if it's the same as the inode id * passed in. This is necessary to filter out zones in snapshots. * @param zoneId * @param zonePath * @return true if path resolve to the id, false if not. * @throws UnresolvedLinkException */ private boolean pathResolvesToId(final long zoneId, final String zonePath) throws UnresolvedLinkException, AccessControlException, ParentNotDirectoryException { assert dir.hasReadLock(); INode inode = dir.getInode(zoneId); if (inode == null) { return false; } INode lastINode = null; if (INode.isValidAbsolutePath(zonePath)) { INodesInPath iip = dir.getINodesInPath(zonePath, DirOp.READ_LINK); lastINode = iip.getLastINode(); } if (lastINode == null || lastINode.getId() != zoneId) { return false; } return true; }
/** * Save the batch's edeks to file xattrs. */ static void saveFileXAttrsForBatch(FSDirectory fsd, List<FileEdekInfo> batch) { assert fsd.getFSNamesystem().hasWriteLock(); assert !fsd.hasWriteLock(); if (batch != null && !batch.isEmpty()) { for (FileEdekInfo entry : batch) { final INode inode = fsd.getInode(entry.getInodeId()); // no dir lock, so inode could be removed. no-op if so. if (inode == null) { NameNode.LOG.info("Cannot find inode {}, skip saving xattr for" + " re-encryption", entry.getInodeId()); continue; } fsd.getEditLog().logSetXAttrs(inode.getFullPathName(), inode.getXAttrFeature().getXAttrs(), false); } } }
private INodeReference loadINodeReference( INodeReferenceSection.INodeReference r) { long referredId = r.getReferredId(); INode referred = fsDir.getInode(referredId); WithCount withCount = (WithCount) referred.getParentReference(); if (withCount == null) { withCount = new INodeReference.WithCount(null, referred); } final INodeReference ref; if (r.hasDstSnapshotId()) { // DstReference ref = new INodeReference.DstReference(null, withCount, r.getDstSnapshotId()); } else { ref = new INodeReference.WithName(null, withCount, r.getName() .toByteArray(), r.getLastSnapshotId()); } return ref; }
private void loadSnapshots(InputStream in, int size) throws IOException { for (int i = 0; i < size; i++) { SnapshotSection.Snapshot pbs = SnapshotSection.Snapshot .parseDelimitedFrom(in); INodeDirectory root = loadINodeDirectory(pbs.getRoot(), parent.getLoaderContext()); int sid = pbs.getSnapshotId(); INodeDirectory parent = fsDir.getInode(root.getId()).asDirectory(); Snapshot snapshot = new Snapshot(sid, root, parent); // add the snapshot to parent, since we follow the sequence of // snapshotsByNames when saving, we do not need to sort when loading parent.getDirectorySnapshottableFeature().addSnapshot(snapshot); snapshotMap.put(sid, snapshot); } }
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); }
@Override public void removeXattr(long id, String xattrName) throws IOException { writeLock(); try { final INode inode = dir.getInode(id); if (inode == null) { return; } final XAttrFeature xaf = inode.getXAttrFeature(); if (xaf == null) { return; } final XAttr spsXAttr = xaf.getXAttr(xattrName); if (spsXAttr != null) { FSDirSatisfyStoragePolicyOp.removeSPSXattr(dir, inode, spsXAttr); } } finally { writeUnlock("removeXAttr"); } getEditLog().logSync(); }
blockManager.getDatanodeManager().getDatanodes()) { for (long ucFileId : dataNode.getLeavingServiceStatus().getOpenFiles()) { INode ucFile = getFSDirectory().getInode(ucFileId); if (ucFile == null || ucFileId <= prevId || openFileIds.contains(ucFileId)) {
private INodeReferenceSection.INodeReference.Builder buildINodeReference( final INodeReference ref, final long refIndex) throws IOException { INodeReferenceSection.INodeReference.Builder rb = INodeReferenceSection.INodeReference.newBuilder(). setReferredId(ref.getId()); if (ref instanceof WithName) { rb.setLastSnapshotId(((WithName) ref).getLastSnapshotId()).setName( ByteString.copyFrom(ref.getLocalNameBytes())); } else if (ref instanceof DstReference) { rb.setDstSnapshotId(ref.getDstSnapshotId()); } if (fsn.getFSDirectory().getInode(ref.getId()) == null) { FSImage.LOG.error( "FSImageFormatPBSnapshot: Missing referred INodeId " + ref.getId() + " for INodeReference index " + refIndex + "; path=" + ref.getFullPathName() + "; parent=" + (ref.getParent() == null ? "null" : ref.getParent().getFullPathName())); ++numImageErrors; } return rb; }
try { handler.getTraverser().checkINodeReady(task.zoneId); final INode zoneNode = dir.getInode(task.zoneId); if (zoneNode == null) {
/** * Load the snapshot diff section from fsimage. */ public void loadSnapshotDiffSection(InputStream in) throws IOException { final List<INodeReference> refList = parent.getLoaderContext() .getRefList(); while (true) { SnapshotDiffSection.DiffEntry entry = SnapshotDiffSection.DiffEntry .parseDelimitedFrom(in); if (entry == null) { break; } long inodeId = entry.getInodeId(); INode inode = fsDir.getInode(inodeId); SnapshotDiffSection.DiffEntry.Type type = entry.getType(); switch (type) { case FILEDIFF: loadFileDiffList(in, inode.asFile(), entry.getNumOfDiff()); break; case DIRECTORYDIFF: loadDirectoryDiffList(in, inode.asDirectory(), entry.getNumOfDiff(), refList); break; } } }
/** * Load the snapshots section from fsimage. Also add snapshottable feature * to snapshottable directories. */ public void loadSnapshotSection(InputStream in) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection section = SnapshotSection.parseDelimitedFrom(in); int snum = section.getNumSnapshots(); sm.setNumSnapshots(snum); sm.setSnapshotCounter(section.getSnapshotCounter()); for (long sdirId : section.getSnapshottableDirList()) { INodeDirectory dir = fsDir.getInode(sdirId).asDirectory(); if (!dir.isSnapshottable()) { dir.addSnapshottableFeature(); } else { // dir is root, and admin set root to snapshottable before dir.setSnapshotQuota( DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } sm.addSnapshottable(dir); } loadSnapshots(in, snum); }
boolean isFileDeleted(INodeFile file) { assert hasReadLock(); if (dir.getInode(file.getId()) == null) { return true;