use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method getNewBlockIdForFile.
/**
* Gets a new block id for the next block of a given file to write to.
* <p>
* This operation requires users to have {@link Mode.Bits#WRITE} permission on the path as
* this API is called when creating a new block for a file.
*
* @param path the path of the file to get the next block id for
* @return the next block id for the given file
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the given path is not valid
* @throws AccessControlException if permission checking fails
*/
public long getNewBlockIdForFile(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
Metrics.GET_NEW_BLOCK_OPS.inc();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.WRITE)) {
mPermissionChecker.checkPermission(Mode.Bits.WRITE, inodePath);
Metrics.NEW_BLOCKS_GOT.inc();
return inodePath.getInodeFile().getNewBlockId();
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method setAttribute.
/**
* Sets the file attribute.
* <p>
* This operation requires users to have {@link Mode.Bits#WRITE} permission on the path. In
* addition, the client user must be a super user when setting the owner, and must be a super user
* or the owner when setting the group or permission.
*
* @param path the path to set attribute for
* @param options attributes to be set, see {@link SetAttributeOptions}
* @throws FileDoesNotExistException if the file does not exist
* @throws AccessControlException if permission checking fails
* @throws InvalidPathException if the given path is invalid
*/
public void setAttribute(AlluxioURI path, SetAttributeOptions options) throws FileDoesNotExistException, AccessControlException, InvalidPathException {
Metrics.SET_ATTRIBUTE_OPS.inc();
// for chown
boolean rootRequired = options.getOwner() != null;
// for chgrp, chmod
boolean ownerRequired = (options.getGroup() != null) || (options.getMode() != Constants.INVALID_MODE);
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.WRITE)) {
mPermissionChecker.checkSetAttributePermission(inodePath, rootRequired, ownerRequired);
setAttributeAndJournal(inodePath, rootRequired, ownerRequired, options, journalContext);
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method reportLostFile.
/**
* Reports a file as lost.
*
* @param fileId the id of the file
* @throws FileDoesNotExistException if the file does not exist
*/
// Currently used by Lineage Master
// TODO(binfan): Add permission checking for internal APIs
public void reportLostFile(long fileId) throws FileDoesNotExistException {
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.READ)) {
Inode<?> inode = inodePath.getInode();
if (inode.isDirectory()) {
LOG.warn("Reported file is a directory {}", inode);
return;
}
List<Long> blockIds = new ArrayList<>();
try {
for (FileBlockInfo fileBlockInfo : getFileBlockInfoListInternal(inodePath)) {
blockIds.add(fileBlockInfo.getBlockInfo().getBlockId());
}
} catch (InvalidPathException e) {
LOG.info("Failed to get file info {}", fileId, e);
}
mBlockMaster.reportLostBlocks(blockIds);
LOG.info("Reported file loss of blocks {}. Alluxio will recompute it: {}", blockIds, fileId);
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method getFileInfo.
/**
* Returns the {@link FileInfo} for a given path.
* <p>
* This operation requires users to have {@link Mode.Bits#READ} permission on the path.
*
* @param path the path to get the {@link FileInfo} for
* @return the {@link FileInfo} for the given file id
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the file path is not valid
* @throws AccessControlException if permission checking fails
*/
// TODO(peis): Add an option not to load metadata.
public FileInfo getFileInfo(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
Metrics.GET_FILE_INFO_OPS.inc();
// metadata for direct children is disabled by default.
try (LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.READ)) {
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
if (inodePath.fullPathExists()) {
// The file already exists, so metadata does not need to be loaded.
return getFileInfoInternal(inodePath);
}
}
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
// This is WRITE locked, since loading metadata is possible.
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
loadMetadataIfNotExistAndJournal(inodePath, LoadMetadataOptions.defaults().setCreateAncestors(true), journalContext);
mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
return getFileInfoInternal(inodePath);
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method renameFromEntry.
/**
* @param entry the entry to use
*/
private void renameFromEntry(RenameEntry entry) {
Metrics.RENAME_PATH_OPS.inc();
// Determine the srcPath and dstPath
AlluxioURI srcPath;
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(entry.getId(), InodeTree.LockMode.READ)) {
srcPath = inodePath.getUri();
} catch (Exception e) {
throw new RuntimeException(e);
}
AlluxioURI dstPath = new AlluxioURI(entry.getDstPath());
// Both src and dst paths should lock WRITE_PARENT, to modify the parent inodes for both paths.
try (InodePathPair inodePathPair = mInodeTree.lockInodePathPair(srcPath, InodeTree.LockMode.WRITE_PARENT, dstPath, InodeTree.LockMode.WRITE_PARENT)) {
LockedInodePath srcInodePath = inodePathPair.getFirst();
LockedInodePath dstInodePath = inodePathPair.getSecond();
RenameOptions options = RenameOptions.defaults().setOperationTimeMs(entry.getOpTimeMs());
renameInternal(srcInodePath, dstInodePath, true, options);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations