@Override // FSNamesystemMBean @Metric public long getFilesTotal() { // There is no need to take fSNamesystem's lock as // FSDirectory has its own lock. return this.dir.totalInodes(); }
FSNamesystem fsn = fsd.getFSNamesystem(); fsd.writeLock(); try { if (deleteAllowed(iip)) { FSDirSnapshotOp.checkSnapshot(fsd, iip, snapshottableDirs); ReclaimContext context = new ReclaimContext( fsd.getBlockStoragePolicySuite(), collectedBlocks, removedINodes, removedUCFiles); if (unprotectedDelete(fsd, iip, context, mtime)) { filesRemoved = context.quotaDelta().getNsDelta(); fsd.updateReplicationFactor(context.collectedBlocks() .toUpdateReplicationInfo()); fsn.removeSnapshottableDirs(snapshottableDirs); fsd.updateCount(iip, context.quotaDelta(), false); fsd.writeUnlock();
/** * 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); } } }
/** * Add the given child to the namespace. * @param existing the INodesInPath containing all the ancestral INodes * @param child the new INode to add * @param modes create modes * @return a new INodesInPath instance containing the new child INode. Null * if the adding fails. * @throws QuotaExceededException is thrown if it violates quota limit */ INodesInPath addINode(INodesInPath existing, INode child, FsPermission modes) throws QuotaExceededException, UnresolvedLinkException { cacheName(child); writeLock(); try { return addLastINode(existing, child, modes, true); } finally { writeUnlock(); } }
/** * update quota of each inode and check to see if quota is exceeded. * See {@link #updateCount(INodesInPath, int, QuotaCounts, boolean)} */ void updateCountNoQuotaCheck(INodesInPath inodesInPath, int numOfINodes, QuotaCounts counts) { assert hasWriteLock(); try { updateCount(inodesInPath, numOfINodes, counts, false); } catch (QuotaExceededException e) { NameNode.LOG.error("BUG: unexpected exception ", e); } }
static boolean setTimes( FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force) throws QuotaExceededException { fsd.writeLock(); try { return unprotectedSetTimes(fsd, iip, mtime, atime, force); } finally { fsd.writeUnlock(); } }
static FileStatus setPermission( FSDirectory fsd, FSPermissionChecker pc, final String src, FsPermission permission) throws IOException { if (FSDirectory.isExactReservedName(src)) { throw new InvalidPathException(src); } INodesInPath iip; fsd.writeLock(); try { iip = fsd.resolvePath(pc, src, DirOp.WRITE); fsd.checkOwner(pc, iip); unprotectedSetPermission(fsd, iip, permission); } finally { fsd.writeUnlock(); } fsd.getEditLog().logSetPermissions(iip.getPath(), permission); return fsd.getAuditFileInfo(iip); }
String snapshotRoot, String snapshotName, boolean logRetryCache) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, snapshotRoot, DirOp.WRITE); if (fsd.isPermissionEnabled()) { fsd.checkOwner(pc, iip); ChunkedArrayList<INode> removedINodes = new ChunkedArrayList<>(); INode.ReclaimContext context = new INode.ReclaimContext( fsd.getBlockStoragePolicySuite(), collectedBlocks, removedINodes, null); fsd.writeLock(); try { snapshotManager.deleteSnapshot(iip, snapshotName, context); fsd.updateCount(iip, context.quotaDelta(), false); fsd.removeFromInodeMap(removedINodes); fsd.updateReplicationFactor(context.collectedBlocks() .toUpdateReplicationInfo()); } finally { fsd.writeUnlock(); fsd.getEditLog().logDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache);
if (isPermissionEnabled) { if (overwrite && myFile != null) { dir.checkPathAccess(pc, iip, FsAction.WRITE); dir.checkAncestorAccess(pc, iip, FsAction.WRITE); dir.verifyParentDir(iip, src); final EncryptionZone zone = dir.getEZForPath(iip); if (zone != null) { .createAncestorDirectories(dir, iip, permissions); if (parent != null) { iip = dir.addFile(parent.getKey(), parent.getValue(), permissions, replication, blockSize, holder, clientMachine); newNode = iip != null ? iip.getLastINode().asFile() : null; dir.setFileEncryptionInfo(src, feInfo); newNode = dir.getInode(newNode.getId()).asFile();
if (pos == 1 && existing.getINode(0) == rootDir && isReservedName(inode)) { throw new HadoopIllegalArgumentException( "File name \"" + inode.getLocalName() + "\" is reserved and cannot " verifyMaxComponentLength(inode.getLocalNameBytes(), parentPath); verifyMaxDirItems(parent, parentPath); verifyINodeName(inode.getLocalNameBytes()); final QuotaCounts counts = inode.computeQuotaUsage(getBlockStoragePolicySuite()); updateCount(existing, pos, counts, checkQuota); existing.getLatestSnapshotId()); if (!added) { updateCountNoQuotaCheck(existing, pos, counts.negation()); return null; } else { if (!isRename) { copyINodeDefaultAcl(inode, modes); addToInodeMap(inode);
static void renameSnapshot(FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager, String path, String snapshotOldName, String snapshotNewName, boolean logRetryCache) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, path, DirOp.WRITE); if (fsd.isPermissionEnabled()) { fsd.checkOwner(pc, iip); } verifySnapshotName(fsd, snapshotNewName, path); fsd.writeLock(); try { snapshotManager.renameSnapshot(iip, path, snapshotOldName, snapshotNewName); } finally { fsd.writeUnlock(); } fsd.getEditLog().logRenameSnapshot(path, snapshotOldName, snapshotNewName, logRetryCache); }
/** * Reset the entire namespace tree. */ void reset() { writeLock(); try { rootDir = createRoot(getFSNamesystem()); inodeMap.clear(); addToInodeMap(rootDir); nameCache.reset(); inodeId.setCurrentValue(INodeId.LAST_RESERVED_ID); } finally { writeUnlock(); } }
INodesInPath inodesInPath, Block block, DatanodeStorageInfo[] targets, BlockType blockType) throws IOException { fsd.writeLock(); try { final INodeFile fileINode = inodesInPath.getLastINode().asFile(); ErasureCodingPolicy ecPolicy = FSDirErasureCodingOp.unprotectedGetErasureCodingPolicy( fsd.getFSNamesystem(), inodesInPath); short numDataUnits = (short) ecPolicy.getNumDataUnits(); short numParityUnits = (short) ecPolicy.getNumParityUnits(); fsd.updateCount(inodesInPath, 0, fileINode.getPreferredBlockSize(), numLocations, true); blockInfo = new BlockInfoStriped(block, ecPolicy); } else { fsd.updateCount(inodesInPath, 0, fileINode.getPreferredBlockSize(), fileINode.getFileReplication(), true); HdfsServerConstants.BlockUCState.UNDER_CONSTRUCTION, targets); fsd.getBlockManager().addBlockCollection(blockInfo, fileINode); fileINode.addBlock(blockInfo); fsd.writeUnlock();
@VisibleForTesting public ZoneReencryptionStatus getZoneStatus(final String zone) throws IOException { final FSPermissionChecker pc = dir.getPermissionChecker(); final INode inode; dir.getFSNamesystem().readLock(); dir.readLock(); try { final INodesInPath iip = dir.resolvePath(pc, zone, DirOp.READ); inode = iip.getLastINode(); if (inode == null) { return null; } return getReencryptionStatus().getZoneStatus(inode.getId()); } finally { dir.readUnlock(); dir.getFSNamesystem().readUnlock(); } }
/** * Check whether the path specifies a directory */ boolean isDir(String src) throws UnresolvedLinkException { src = normalizePath(src); readLock(); try { INode node = getINode(src, false); return node != null && node.isDirectory(); } finally { readUnlock(); } }
/** Allow snapshot on a directory. */ static void allowSnapshot(FSDirectory fsd, SnapshotManager snapshotManager, String path) throws IOException { fsd.writeLock(); try { snapshotManager.setSnapshottable(path, true); } finally { fsd.writeUnlock(); } fsd.getEditLog().logAllowSnapshot(path); }
writeLock(); try { long dsOld = oldnode.diskspaceConsumed(); if (updateDiskspace && (dsNew = newnode.diskspaceConsumed()) != dsOld) { try { updateSpaceConsumed(path, null, 0, dsNew-dsOld); } catch (QuotaExceededException e) { replaceNode(path, inodes, newnode, oldnode, false); throw e; BlockInfo info = getFSNamesystem().blocksMap.addINode(b, newnode); writeUnlock();
static void abandonBlock( FSDirectory fsd, FSPermissionChecker pc, ExtendedBlock b, long fileId, String src, String holder) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, src, fileId); src = iip.getPath(); FSNamesystem fsn = fsd.getFSNamesystem(); final INodeFile file = fsn.checkLease(iip, holder, fileId); Preconditions.checkState(file.isUnderConstruction()); if (file.getBlockType() == BlockType.STRIPED) { return; // do not abandon block for striped file } Block localBlock = ExtendedBlock.getLocalBlock(b); fsd.writeLock(); try { // Remove the block from the pending creates list if (!unprotectedRemoveBlock(fsd, src, iip, file, localBlock)) { return; } } finally { fsd.writeUnlock(); } persistBlocks(fsd, src, file, false); }
/** Updates namespace, storagespace and typespaces consumed for all * directories until the parent directory of file represented by path. * * @param iip the INodesInPath instance containing all the INodes for * updating quota usage * @param nsDelta the delta change of namespace * @param ssDelta the delta change of storage space consumed without replication * @param replication the replication factor of the block consumption change * @throws QuotaExceededException if the new count violates any quota limit * @throws FileNotFoundException if path does not exist. */ void updateSpaceConsumed(INodesInPath iip, long nsDelta, long ssDelta, short replication) throws QuotaExceededException, FileNotFoundException, UnresolvedLinkException, SnapshotAccessControlException { writeLock(); try { if (iip.getLastINode() == null) { throw new FileNotFoundException("Path not found: " + iip.getPath()); } updateCount(iip, nsDelta, ssDelta, replication, true); } finally { writeUnlock(); } }
/** * Check whether the path specifies a directory */ boolean isDir(String src) { readLock(); try { INode node = rootDir.getNode(normalizePath(src)); return isDir(node); } finally { readUnlock(); } }