Search in sources :

Example 1 with InodePathPair

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

the class FileSystemMaster method rename.

/**
   * Renames a file to a destination.
   * <p>
   * This operation requires users to have
   * {@link Mode.Bits#WRITE} permission on the parent of the src path, and
   * {@link Mode.Bits#WRITE} permission on the parent of the dst path.
   *
   * @param srcPath the source path to rename
   * @param dstPath the destination path to rename the file to
   * @param options method options
   * @throws FileDoesNotExistException if a non-existent file is encountered
   * @throws InvalidPathException if an invalid path is encountered
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if permission checking fails
   * @throws FileAlreadyExistsException if the file already exists
   */
public void rename(AlluxioURI srcPath, AlluxioURI dstPath, RenameOptions options) throws FileAlreadyExistsException, FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    Metrics.RENAME_PATH_OPS.inc();
    // modify operations on the parent inodes are thread safe so WRITE locks are not required.
    try (JournalContext journalContext = createJournalContext();
        InodePathPair inodePathPair = mInodeTree.lockInodePathPair(srcPath, InodeTree.LockMode.WRITE, dstPath, InodeTree.LockMode.READ)) {
        LockedInodePath srcInodePath = inodePathPair.getFirst();
        LockedInodePath dstInodePath = inodePathPair.getSecond();
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, srcInodePath);
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, dstInodePath);
        mMountTable.checkUnderWritableMountPoint(srcPath);
        mMountTable.checkUnderWritableMountPoint(dstPath);
        renameAndJournal(srcInodePath, dstInodePath, options, journalContext);
        LOG.debug("Renamed {} to {}", srcPath, dstPath);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodePathPair(alluxio.master.file.meta.InodePathPair)

Example 2 with InodePathPair

use of alluxio.master.file.meta.InodePathPair 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

InodePathPair (alluxio.master.file.meta.InodePathPair)2 LockedInodePath (alluxio.master.file.meta.LockedInodePath)2 AlluxioURI (alluxio.AlluxioURI)1 AccessControlException (alluxio.exception.AccessControlException)1 AlluxioException (alluxio.exception.AlluxioException)1 BlockInfoException (alluxio.exception.BlockInfoException)1 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)1 RenameOptions (alluxio.master.file.options.RenameOptions)1 IOException (java.io.IOException)1