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);
}
}
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);
}
}
Aggregations