Search in sources :

Example 41 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method createFile.

/**
   * Creates a file (not a directory) for a given path.
   * <p>
   * This operation requires {@link Mode.Bits#WRITE} permission on the parent of this path.
   *
   * @param path the file to create
   * @param options method options
   * @return the id of the created file
   * @throws InvalidPathException if an invalid path is encountered
   * @throws FileAlreadyExistsException if the file already exists
   * @throws BlockInfoException if an invalid block information is encountered
   * @throws IOException if the creation fails
   * @throws AccessControlException if permission checking fails
   * @throws FileDoesNotExistException if the parent of the path does not exist and the recursive
   * option is false
   */
public long createFile(AlluxioURI path, CreateFileOptions options) throws AccessControlException, InvalidPathException, FileAlreadyExistsException, BlockInfoException, IOException, FileDoesNotExistException {
    Metrics.CREATE_FILES_OPS.inc();
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
        mMountTable.checkUnderWritableMountPoint(path);
        createFileAndJournal(inodePath, options, journalContext);
        return inodePath.getInode().getId();
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 42 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method free.

// TODO(binfan): throw a better exception rather than UnexpectedAlluxioException. Currently
// UnexpectedAlluxioException is thrown because we want to keep backwards compatibility with
// clients of earlier versions prior to 1.5. If a new exception is added, it will be converted
// into RuntimeException on the client.
/**
   * Frees or evicts all of the blocks of the file from alluxio storage. If the given file is a
   * directory, and the 'recursive' flag is enabled, all descendant files will also be freed.
   * <p>
   * This operation requires users to have {@link Mode.Bits#READ} permission on the path.
   *
   * @param path the path to free
   * @param options options to free
   * @throws FileDoesNotExistException if the file does not exist
   * @throws AccessControlException if permission checking fails
   * @throws InvalidPathException if the given path is invalid
   * @throws UnexpectedAlluxioException if the file or directory can not be freed
   */
public void free(AlluxioURI path, FreeOptions options) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnexpectedAlluxioException {
    Metrics.FREE_FILE_OPS.inc();
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.WRITE)) {
        mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
        freeAndJournal(inodePath, options, journalContext);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 43 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method reinitializeFile.

/**
   * Reinitializes the blocks of an existing open file.
   *
   * @param path the path to the file
   * @param blockSizeBytes the new block size
   * @param ttl the ttl
   * @param ttlAction action to take after Ttl expiry
   * @return the file id
   * @throws InvalidPathException if the path is invalid
   * @throws FileDoesNotExistException if the path does not exist
   */
// Used by lineage master
public long reinitializeFile(AlluxioURI path, long blockSizeBytes, long ttl, TtlAction ttlAction) throws InvalidPathException, FileDoesNotExistException {
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.WRITE)) {
        long id = mInodeTree.reinitializeFile(inodePath, blockSizeBytes, ttl, ttlAction);
        ReinitializeFileEntry reinitializeFile = ReinitializeFileEntry.newBuilder().setPath(path.getPath()).setBlockSizeBytes(blockSizeBytes).setTtl(ttl).setTtlAction(ProtobufUtils.toProtobuf(ttlAction)).build();
        appendJournalEntry(JournalEntry.newBuilder().setReinitializeFile(reinitializeFile).build(), journalContext);
        return id;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) ReinitializeFileEntry(alluxio.proto.journal.File.ReinitializeFileEntry)

Example 44 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method getFileBlockInfoList.

/**
   * Gets the {@link FileBlockInfo} for all blocks of a file. If path is a directory, an exception
   * is thrown.
   * <p>
   * This operation requires the client user to have {@link Mode.Bits#READ} permission on the
   * the path.
   *
   * @param path the path to get the info for
   * @return a list of {@link FileBlockInfo} for all the blocks of the given path
   * @throws FileDoesNotExistException if the file does not exist or path is a directory
   * @throws InvalidPathException if the path of the given file is invalid
   * @throws AccessControlException if permission checking fails
   */
public List<FileBlockInfo> getFileBlockInfoList(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
    Metrics.GET_FILE_BLOCK_INFO_OPS.inc();
    try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.READ)) {
        mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
        List<FileBlockInfo> ret = getFileBlockInfoListInternal(inodePath);
        Metrics.FILE_BLOCK_INFOS_GOT.inc();
        return ret;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileBlockInfo(alluxio.wire.FileBlockInfo)

Example 45 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method mountFromEntry.

/**
   * @param entry the entry to use
   * @throws FileAlreadyExistsException if the mount point already exists
   * @throws InvalidPathException if an invalid path is encountered
   * @throws IOException if an I/O exception occurs
   */
private void mountFromEntry(AddMountPointEntry entry) throws FileAlreadyExistsException, InvalidPathException, IOException {
    AlluxioURI alluxioURI = new AlluxioURI(entry.getAlluxioPath());
    AlluxioURI ufsURI = new AlluxioURI(entry.getUfsPath());
    try (LockedInodePath inodePath = mInodeTree.lockInodePath(alluxioURI, InodeTree.LockMode.WRITE)) {
        mountInternal(inodePath, ufsURI, true, /* replayed */
        new MountOptions(entry));
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) MountOptions(alluxio.master.file.options.MountOptions) 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