void updateMtimeAndLease(long timestamp) { srcParent.updateModificationTime(timestamp, srcIIP.getLatestSnapshotId()); final INode dstParent = dstParentIIP.getLastINode(); dstParent.updateModificationTime(timestamp, dstIIP.getLatestSnapshotId()); }
static void unprotectedSetOwner( FSDirectory fsd, INodesInPath iip, String username, String groupname) throws FileNotFoundException, UnresolvedLinkException, QuotaExceededException, SnapshotAccessControlException { assert fsd.hasWriteLock(); final INode inode = FSDirectory.resolveLastINode(iip); if (username != null) { inode.setUser(username, iip.getLatestSnapshotId()); } if (groupname != null) { inode.setGroup(groupname, iip.getLatestSnapshotId()); } }
static void unprotectedSetPermission( FSDirectory fsd, INodesInPath iip, FsPermission permissions) throws FileNotFoundException, UnresolvedLinkException, QuotaExceededException, SnapshotAccessControlException { assert fsd.hasWriteLock(); final INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); inode.setPermission(permissions, snapshotId); }
/** * Remove xattrs from the inode, and return the <em>removed</em> xattrs. * @return the <em>removed</em> xattrs. */ static List<XAttr> unprotectedRemoveXAttrs( FSDirectory fsd, final INodesInPath iip, final List<XAttr> toRemove) throws IOException { assert fsd.hasWriteLock(); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); List<XAttr> removedXAttrs = Lists.newArrayListWithCapacity(toRemove.size()); List<XAttr> newXAttrs = filterINodeXAttrs(existingXAttrs, toRemove, removedXAttrs); if (existingXAttrs.size() != newXAttrs.size()) { XAttrStorage.updateINodeXAttrs(inode, newXAttrs, snapshotId); return removedXAttrs; } return null; }
private static void setDirStoragePolicy( FSDirectory fsd, INodesInPath iip, byte policyId) throws IOException { INode inode = FSDirectory.resolveLastINode(iip); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); XAttr xAttr = BlockStoragePolicySuite.buildXAttr(policyId); List<XAttr> newXAttrs = null; if (policyId == HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) { List<XAttr> toRemove = Lists.newArrayList(); toRemove.add(xAttr); List<XAttr> removed = Lists.newArrayList(); newXAttrs = FSDirXAttrOp.filterINodeXAttrs(existingXAttrs, toRemove, removed); } else { newXAttrs = FSDirXAttrOp.setINodeXAttrs(fsd, existingXAttrs, Arrays.asList(xAttr), EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE)); } XAttrStorage.updateINodeXAttrs(inode, newXAttrs, iip.getLatestSnapshotId()); }
static void removeSPSXattr(FSDirectory fsd, INode inode, XAttr spsXAttr) throws IOException { try { fsd.writeLock(); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); existingXAttrs.remove(spsXAttr); XAttrStorage.updateINodeXAttrs(inode, existingXAttrs, INodesInPath .fromINode(inode).getLatestSnapshotId()); List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1); xAttrs.add(spsXAttr); fsd.getEditLog().logRemoveXAttrs(inode.getFullPathName(), xAttrs, false); } finally { fsd.writeUnlock(); } } }
static List<AclEntry> unprotectedSetAcl(FSDirectory fsd, INodesInPath iip, List<AclEntry> aclSpec, boolean fromEdits) throws IOException { assert fsd.hasWriteLock(); // ACL removal is logged to edits as OP_SET_ACL with an empty list. if (aclSpec.isEmpty()) { unprotectedRemoveAcl(fsd, iip); return AclFeature.EMPTY_ENTRY_LIST; } INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> newAcl = aclSpec; if (!fromEdits) { List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); newAcl = AclTransformation.replaceAclEntries(existingAcl, aclSpec); } AclStorage.updateINodeAcl(inode, newAcl, snapshotId); return newAcl; }
/** * Remove the last inode in the path from the namespace. * Note: the caller needs to update the ancestors' quota count. * * @return -1 for failing to remove; * 0 for removing a reference whose referred inode has other * reference nodes; * 1 otherwise. */ @VisibleForTesting public long removeLastINode(final INodesInPath iip) { final int latestSnapshot = iip.getLatestSnapshotId(); final INode last = iip.getLastINode(); final INodeDirectory parent = iip.getINode(-2).asDirectory(); if (!parent.removeChild(last, latestSnapshot)) { return -1; } return (!last.isInLatestSnapshot(latestSnapshot) && INodeReference.tryRemoveReference(last) > 0) ? 0 : 1; }
boolean cleanDst( BlockStoragePolicySuite bsps, BlocksMapUpdateInfo collectedBlocks) { Preconditions.checkState(oldDstChild != null); List<INode> removedINodes = new ChunkedArrayList<>(); List<Long> removedUCFiles = new ChunkedArrayList<>(); INode.ReclaimContext context = new INode.ReclaimContext( bsps, collectedBlocks, removedINodes, removedUCFiles); final boolean filesDeleted; if (!oldDstChild.isInLatestSnapshot(dstIIP.getLatestSnapshotId())) { oldDstChild.destroyAndCollectBlocks(context); filesDeleted = true; } else { oldDstChild.cleanSubtree(context, Snapshot.CURRENT_STATE_ID, dstIIP.getLatestSnapshotId()); filesDeleted = context.quotaDelta().getNsDelta() >= 0; } fsd.updateReplicationFactor(context.collectedBlocks() .toUpdateReplicationInfo()); fsd.getFSNamesystem().removeLeasesAndINodes( removedUCFiles, removedINodes, false); return filesDeleted; }
void restoreDst(BlockStoragePolicySuite bsps) { Preconditions.checkState(oldDstChild != null); final INodeDirectory dstParent = dstParentIIP.getLastINode().asDirectory(); if (dstParent.isWithSnapshot()) { dstParent.undoRename4DstParent(bsps, oldDstChild, dstIIP.getLatestSnapshotId()); } else { fsd.addLastINodeNoQuotaCheck(dstParentIIP, oldDstChild); } if (oldDstChild != null && oldDstChild.isReference()) { final INodeReference removedDstRef = oldDstChild.asReference(); final INodeReference.WithCount wc = (INodeReference.WithCount) removedDstRef.getReferredINode().asReference(); wc.addReference(removedDstRef); } }
private static void setNewINodeStoragePolicy(BlockManager bm, INodesInPath iip, boolean isLazyPersist) throws IOException { INodeFile inode = iip.getLastINode().asFile(); if (isLazyPersist) { BlockStoragePolicy lpPolicy = bm.getStoragePolicy("LAZY_PERSIST"); // Set LAZY_PERSIST storage policy if the flag was passed to // CreateFile. if (lpPolicy == null) { throw new HadoopIllegalArgumentException( "The LAZY_PERSIST storage policy has been disabled " + "by the administrator."); } inode.setStoragePolicyID(lpPolicy.getId(), iip.getLatestSnapshotId()); } else { BlockStoragePolicy effectivePolicy = bm.getStoragePolicy(inode.getStoragePolicyID()); if (effectivePolicy != null && effectivePolicy.isCopyOnCreateFile()) { // Copy effective policy from ancestor directory to current file. inode.setStoragePolicyID(effectivePolicy.getId(), iip.getLatestSnapshotId()); } } }
/** * Update the quota usage after deletion. The quota update is only necessary * when image/edits have been loaded and the file/dir to be deleted is not * contained in snapshots. */ void updateCountForDelete(final INode inode, final INodesInPath iip) { if (getFSNamesystem().isImageLoaded() && !inode.isInLatestSnapshot(iip.getLatestSnapshotId())) { QuotaCounts counts = inode.computeQuotaUsage(getBlockStoragePolicySuite()); unprotectedUpdateCount(iip, iip.length() - 1, counts.negation()); } }
INodesInPath addSourceToDestination() { final INode dstParent = dstParentIIP.getLastINode(); final byte[] dstChildName = dstIIP.getLastLocalName(); final INode toDst; if (withCount == null) { srcChild.setLocalName(dstChildName); toDst = srcChild; } else { withCount.getReferredINode().setLocalName(dstChildName); toDst = new INodeReference.DstReference(dstParent.asDirectory(), withCount, dstIIP.getLatestSnapshotId()); } return fsd.addLastINodeNoQuotaCheck(dstParentIIP, toDst); }
assert fsd.hasWriteLock(); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); AclFeature f = inode.getAclFeature(); if (f == null) {
/** * Truncate has the following properties: * 1.) Any block deletions occur now. * 2.) INode length is truncated now - new clients can only read up to * the truncated length. * 3.) INode will be set to UC and lastBlock set to UNDER_RECOVERY. * 4.) NN will trigger DN truncation recovery and waits for DNs to report. * 5.) File is considered UNDER_RECOVERY until truncation recovery * completes. * 6.) Soft and hard Lease expiration require truncation recovery to * complete. * * @return true if on the block boundary or false if recovery is need */ private static boolean unprotectedTruncate(FSNamesystem fsn, INodesInPath iip, long newLength, BlocksMapUpdateInfo collectedBlocks, long mtime, QuotaCounts delta) throws IOException { assert fsn.hasWriteLock(); INodeFile file = iip.getLastINode().asFile(); int latestSnapshot = iip.getLatestSnapshotId(); file.recordModification(latestSnapshot, true); verifyQuotaForTruncate(fsn, iip, file, newLength, delta); Set<BlockInfo> toRetain = file.getSnapshotBlocksToRetain(latestSnapshot); long remainingLength = file.collectBlocksBeyondMax(newLength, collectedBlocks, toRetain); file.setModificationTime(mtime); // return whether on a block boundary return (remainingLength - newLength) == 0; }
static boolean unprotectedSetTimes( FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force) throws QuotaExceededException { assert fsd.hasWriteLock(); boolean status = false; INode inode = iip.getLastINode(); int latest = iip.getLatestSnapshotId(); if (mtime != -1) { inode = inode.setModificationTime(mtime, latest); status = true; } // if the last access time update was within the last precision interval, // then no need to store access time if (atime != -1 && (status || force || atime > inode.getAccessTime() + fsd.getAccessTimePrecision())) { inode.setAccessTime(atime, latest, fsd.getFSNamesystem().getSnapshotManager(). getSkipCaptureAccessTimeOnlyChange()); status = true; } return status; } }
+ iip.getPath()); final int snapshotId = iip.getLatestSnapshotId(); if (inode.isFile()) { if (policyId != HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) {
static FileStatus removeDefaultAcl(FSDirectory fsd, FSPermissionChecker pc, final String srcArg) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.filterDefaultAclEntries( existingAcl); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus modifyAclEntries( FSDirectory fsd, FSPermissionChecker pc, final String srcArg, List<AclEntry> aclSpec) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.mergeAclEntries( existingAcl, aclSpec); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }
static FileStatus removeAclEntries( FSDirectory fsd, FSPermissionChecker pc, final String srcArg, List<AclEntry> aclSpec) throws IOException { String src = srcArg; checkAclsConfigFlag(fsd); INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); src = iip.getPath(); fsd.checkOwner(pc, iip); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); List<AclEntry> newAcl = AclTransformation.filterAclEntriesByAclSpec( existingAcl, aclSpec); AclStorage.updateINodeAcl(inode, newAcl, snapshotId); fsd.getEditLog().logSetAcl(src, newAcl); } catch (AclException e){ throw new AclException(e.getMessage() + " Path: " + src, e); } finally { fsd.writeUnlock(); } return fsd.getAuditFileInfo(iip); }