Search in sources :

Example 46 with LockedInodePath

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();
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 47 with LockedInodePath

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);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 48 with LockedInodePath

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);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) InvalidPathException(alluxio.exception.InvalidPathException)

Example 49 with LockedInodePath

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);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 50 with LockedInodePath

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);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) RenameOptions(alluxio.master.file.options.RenameOptions) InodePathPair(alluxio.master.file.meta.InodePathPair) AlluxioException(alluxio.exception.AlluxioException) BlockInfoException(alluxio.exception.BlockInfoException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AccessControlException(alluxio.exception.AccessControlException) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

LockedInodePath (alluxio.master.file.meta.LockedInodePath)79 AlluxioURI (alluxio.AlluxioURI)27 AccessControlException (alluxio.exception.AccessControlException)24 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)23 InvalidPathException (alluxio.exception.InvalidPathException)18 LockingScheme (alluxio.master.file.meta.LockingScheme)16 Inode (alluxio.master.file.meta.Inode)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 Mode (alluxio.security.authorization.Mode)10 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)9 BlockInfoException (alluxio.exception.BlockInfoException)8 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)8 IOException (java.io.IOException)8 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)7 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)7 LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)7 InodeFile (alluxio.master.file.meta.InodeFile)7 MountTable (alluxio.master.file.meta.MountTable)7 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)6