Search in sources :

Example 6 with LoadMetadataContext

use of alluxio.master.file.contexts.LoadMetadataContext in project alluxio by Alluxio.

the class InodeSyncStream method loadMetadata.

/**
 * This method creates inodes containing the metadata from the UFS. The {@link UfsStatus} object
 * must be set in the {@link LoadMetadataContext} in order to successfully create the inodes.
 */
private void loadMetadata(LockedInodePath inodePath, LoadMetadataContext context) throws AccessControlException, BlockInfoException, FileAlreadyCompletedException, FileDoesNotExistException, InvalidFileSizeException, InvalidPathException, IOException {
    AlluxioURI path = inodePath.getUri();
    MountTable.Resolution resolution = mMountTable.resolve(path);
    int failedSync = 0;
    try {
        if (context.getUfsStatus() == null) {
            // uri does not exist in ufs
            Inode inode = inodePath.getInode();
            if (inode.isFile()) {
                throw new IllegalArgumentException(String.format("load metadata cannot be called on a file if no ufs " + "status is present in the context. %s", inodePath.getUri()));
            }
            mInodeTree.setDirectChildrenLoaded(mRpcContext, inode.asDirectory());
            return;
        }
        if (context.getUfsStatus().isFile()) {
            loadFileMetadataInternal(mRpcContext, inodePath, resolution, context, mFsMaster);
        } else {
            loadDirectoryMetadata(mRpcContext, inodePath, context, mMountTable, mFsMaster);
            // now load all children if required
            LoadDescendantPType type = context.getOptions().getLoadDescendantType();
            if (type != LoadDescendantPType.NONE) {
                Collection<UfsStatus> children = mStatusCache.fetchChildrenIfAbsent(mRpcContext, inodePath.getUri(), mMountTable);
                if (children == null) {
                    LOG.debug("fetching children for {} returned null", inodePath.getUri());
                    return;
                }
                for (UfsStatus childStatus : children) {
                    if (PathUtils.isTemporaryFileName(childStatus.getName())) {
                        continue;
                    }
                    AlluxioURI childURI = new AlluxioURI(PathUtils.concatPath(inodePath.getUri(), childStatus.getName()));
                    if (mInodeTree.inodePathExists(childURI) && (childStatus.isFile() || context.getOptions().getLoadDescendantType() != LoadDescendantPType.ALL)) {
                        // loading all descendants.
                        continue;
                    }
                    LoadMetadataContext loadMetadataContext = LoadMetadataContext.mergeFrom(LoadMetadataPOptions.newBuilder().setLoadDescendantType(LoadDescendantPType.NONE).setCommonOptions(NO_TTL_OPTION).setCreateAncestors(false)).setUfsStatus(childStatus);
                    try (LockedInodePath descendant = inodePath.lockDescendant(inodePath.getUri().joinUnsafe(childStatus.getName()), LockPattern.READ)) {
                        loadMetadata(descendant, loadMetadataContext);
                    } catch (FileNotFoundException e) {
                        LOG.debug("Failed to loadMetadata because file is not in ufs:" + " inodePath={}, options={}.", childURI, loadMetadataContext, e);
                    } catch (BlockInfoException | FileAlreadyCompletedException | FileDoesNotExistException | InvalidFileSizeException | IOException e) {
                        LOG.debug("Failed to loadMetadata because the ufs file or directory" + " is {}, options={}.", childStatus, loadMetadataContext, e);
                        failedSync++;
                    }
                }
                mInodeTree.setDirectChildrenLoaded(mRpcContext, inodePath.getInode().asDirectory());
            }
        }
    } catch (IOException | InterruptedException e) {
        LOG.debug("Failed to loadMetadata: inodePath={}, context={}.", inodePath.getUri(), context, e);
        throw new IOException(e);
    }
    if (failedSync > 0) {
        throw new IOException(String.format("Failed to load metadata of %s files or directories " + "under %s", failedSync, path));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UfsStatus(alluxio.underfs.UfsStatus) FileNotFoundException(java.io.FileNotFoundException) BlockInfoException(alluxio.exception.BlockInfoException) IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) LoadDescendantPType(alluxio.grpc.LoadDescendantPType) Fingerprint(alluxio.underfs.Fingerprint) LockedInodePath(alluxio.master.file.meta.LockedInodePath) Inode(alluxio.master.file.meta.Inode) LoadMetadataContext(alluxio.master.file.contexts.LoadMetadataContext) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)6 LockedInodePath (alluxio.master.file.meta.LockedInodePath)5 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)4 InvalidPathException (alluxio.exception.InvalidPathException)3 MountTable (alluxio.master.file.meta.MountTable)3 AccessControlException (alluxio.exception.AccessControlException)2 DescendantType (alluxio.file.options.DescendantType)2 Inode (alluxio.master.file.meta.Inode)2 LockingScheme (alluxio.master.file.meta.LockingScheme)2 UfsStatus (alluxio.underfs.UfsStatus)2 AlluxioURI (alluxio.AlluxioURI)1 BlockInfoException (alluxio.exception.BlockInfoException)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)1 LoadDescendantPType (alluxio.grpc.LoadDescendantPType)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 Mode (alluxio.security.authorization.Mode)1 Fingerprint (alluxio.underfs.Fingerprint)1 UfsMode (alluxio.underfs.UfsMode)1 FileInfo (alluxio.wire.FileInfo)1