Search in sources :

Example 1 with LoadMetadataOptions

use of alluxio.master.file.options.LoadMetadataOptions in project alluxio by Alluxio.

the class FileSystemMaster method loadMetadataAndJournal.

/**
   * Loads metadata for the object identified by the given path from UFS into Alluxio.
   * <p>
   * Writes to the journal.
   *
   * @param inodePath the path for which metadata should be loaded
   * @param options the load metadata options
   * @param journalContext the journal context
   * @throws InvalidPathException if invalid path is encountered
   * @throws FileDoesNotExistException if there is no UFS path
   * @throws BlockInfoException if an invalid block size is encountered
   * @throws FileAlreadyCompletedException if the file is already completed
   * @throws InvalidFileSizeException if invalid file size is encountered
   * @throws AccessControlException if permission checking fails
   * @throws IOException if an I/O error occurs
   */
private void loadMetadataAndJournal(LockedInodePath inodePath, LoadMetadataOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, BlockInfoException, FileAlreadyCompletedException, InvalidFileSizeException, AccessControlException, IOException {
    AlluxioURI path = inodePath.getUri();
    MountTable.Resolution resolution = mMountTable.resolve(path);
    AlluxioURI ufsUri = resolution.getUri();
    UnderFileSystem ufs = resolution.getUfs();
    try {
        if (options.getUnderFileStatus() == null && !ufs.exists(ufsUri.toString())) {
            // uri does not exist in ufs
            InodeDirectory inode = (InodeDirectory) inodePath.getInode();
            inode.setDirectChildrenLoaded(true);
        }
        boolean isFile;
        if (options.getUnderFileStatus() != null) {
            isFile = options.getUnderFileStatus().isFile();
        } else {
            isFile = ufs.isFile(ufsUri.toString());
        }
        if (isFile) {
            loadFileMetadataAndJournal(inodePath, resolution, options, journalContext);
        } else {
            loadDirectoryMetadataAndJournal(inodePath, options, journalContext);
            InodeDirectory inode = (InodeDirectory) inodePath.getInode();
            if (options.isLoadDirectChildren()) {
                UnderFileStatus[] files = ufs.listStatus(ufsUri.toString());
                for (UnderFileStatus file : files) {
                    if (PathUtils.isTemporaryFileName(file.getName()) || inode.getChild(file.getName()) != null) {
                        continue;
                    }
                    TempInodePathForChild tempInodePath = new TempInodePathForChild(inodePath, file.getName());
                    LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setLoadDirectChildren(false).setCreateAncestors(false).setUnderFileStatus(file);
                    loadMetadataAndJournal(tempInodePath, loadMetadataOptions, journalContext);
                }
                inode.setDirectChildrenLoaded(true);
            }
        }
    } catch (IOException e) {
        LOG.error(ExceptionUtils.getStackTrace(e));
        throw e;
    }
}
Also used : LoadMetadataOptions(alluxio.master.file.options.LoadMetadataOptions) InodeDirectory(alluxio.master.file.meta.InodeDirectory) TempInodePathForChild(alluxio.master.file.meta.TempInodePathForChild) UnderFileStatus(alluxio.underfs.UnderFileStatus) IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 2 with LoadMetadataOptions

use of alluxio.master.file.options.LoadMetadataOptions in project alluxio by Alluxio.

the class FileSystemMaster method listStatus.

/**
   * Returns a list of {@link FileInfo} for a given path. If the given path is a file, the list only
   * contains a single object. If it is a directory, the resulting list contains all direct children
   * of the directory.
   * <p>
   * This operation requires users to have
   * {@link Mode.Bits#READ} permission on the path, and also
   * {@link Mode.Bits#EXECUTE} permission on the path if it is a directory.
   *
   * @param path the path to get the {@link FileInfo} list for
   * @param listStatusOptions the {@link alluxio.master.file.options.ListStatusOptions}
   * @return the list of {@link FileInfo}s
   * @throws AccessControlException if permission checking fails
   * @throws FileDoesNotExistException if the file does not exist
   * @throws InvalidPathException if the path is invalid
   */
public List<FileInfo> listStatus(AlluxioURI path, ListStatusOptions listStatusOptions) throws AccessControlException, FileDoesNotExistException, InvalidPathException {
    Metrics.GET_FILE_INFO_OPS.inc();
    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);
        LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(listStatusOptions.getLoadMetadataType() != LoadMetadataType.Never);
        Inode<?> inode;
        if (inodePath.fullPathExists()) {
            inode = inodePath.getInode();
            if (inode.isDirectory() && listStatusOptions.getLoadMetadataType() != LoadMetadataType.Always && ((InodeDirectory) inode).isDirectChildrenLoaded()) {
                loadMetadataOptions.setLoadDirectChildren(false);
            }
        }
        loadMetadataIfNotExistAndJournal(inodePath, loadMetadataOptions, journalContext);
        mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
        inode = inodePath.getInode();
        List<FileInfo> ret = new ArrayList<>();
        if (inode.isDirectory()) {
            TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
            mPermissionChecker.checkPermission(Mode.Bits.EXECUTE, inodePath);
            for (Inode<?> child : ((InodeDirectory) inode).getChildren()) {
                child.lockReadAndCheckParent(inode);
                try {
                    // the path to child for getPath should already be locked.
                    tempInodePath.setDescendant(child, mInodeTree.getPath(child));
                    ret.add(getFileInfoInternal(tempInodePath));
                } finally {
                    child.unlockRead();
                }
            }
        } else {
            ret.add(getFileInfoInternal(inodePath));
        }
        Metrics.FILE_INFOS_GOT.inc();
        return ret;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LoadMetadataOptions(alluxio.master.file.options.LoadMetadataOptions) InodeDirectory(alluxio.master.file.meta.InodeDirectory) TempInodePathForDescendant(alluxio.master.file.meta.TempInodePathForDescendant) FileInfo(alluxio.wire.FileInfo) ArrayList(java.util.ArrayList)

Aggregations

InodeDirectory (alluxio.master.file.meta.InodeDirectory)2 LoadMetadataOptions (alluxio.master.file.options.LoadMetadataOptions)2 AlluxioURI (alluxio.AlluxioURI)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MountTable (alluxio.master.file.meta.MountTable)1 TempInodePathForChild (alluxio.master.file.meta.TempInodePathForChild)1 TempInodePathForDescendant (alluxio.master.file.meta.TempInodePathForDescendant)1 UnderFileStatus (alluxio.underfs.UnderFileStatus)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 FileInfo (alluxio.wire.FileInfo)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1