Search in sources :

Example 16 with LockedInodePath

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

the class DefaultFileSystemMaster method checkConsistencyRecursive.

private void checkConsistencyRecursive(LockedInodePath inodePath, List<AlluxioURI> inconsistentUris, boolean assertInconsistent, boolean metadataSynced) throws IOException, FileDoesNotExistException {
    Inode inode = inodePath.getInode();
    try {
        if (assertInconsistent || !checkConsistencyInternal(inodePath)) {
            inconsistentUris.add(inodePath.getUri());
            // If a dir in Alluxio is inconsistent with underlying storage,
            // we can assert the children is inconsistent.
            // If a file is inconsistent, please ignore this parameter cause it has no child node.
            assertInconsistent = true;
        }
        if (inode.isDirectory()) {
            InodeDirectory inodeDir = inode.asDirectory();
            Iterable<? extends Inode> children = mInodeStore.getChildren(inodeDir);
            for (Inode child : children) {
                try (LockedInodePath childPath = inodePath.lockChild(child, LockPattern.READ)) {
                    checkConsistencyRecursive(childPath, inconsistentUris, assertInconsistent, metadataSynced);
                }
            }
            // if the metadata has already been synced, then we could skip it.
            if (metadataSynced) {
                return;
            }
            MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
            UfsStatus[] statuses;
            try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
                UnderFileSystem ufs = ufsResource.get();
                String ufsPath = resolution.getUri().getPath();
                statuses = ufs.listStatus(ufsPath);
            }
            if (statuses != null) {
                HashSet<String> alluxioFileNames = Streams.stream(children).map(Inode::getName).collect(Collectors.toCollection(HashSet::new));
                Arrays.stream(statuses).forEach(status -> {
                    if (!alluxioFileNames.contains(status.getName())) {
                        inconsistentUris.add(inodePath.getUri().join(status.getName()));
                    }
                });
            }
        }
    } catch (InvalidPathException e) {
        LOG.debug("Path \"{}\" is invalid, has been ignored.", PathUtils.concatPath(inodePath.getUri().getPath()));
    }
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) MountTable(alluxio.master.file.meta.MountTable) InvalidPathException(alluxio.exception.InvalidPathException) LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeDirectory(alluxio.master.file.meta.InodeDirectory) Inode(alluxio.master.file.meta.Inode) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 17 with LockedInodePath

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

the class DefaultFileSystemMaster method setAttributeInternal.

/**
 * Sets the file attribute.
 *
 * @param rpcContext the rpc context
 * @param inodePath the {@link LockedInodePath} to set attribute for
 * @param context attributes to be set, see {@link SetAttributePOptions}
 */
private void setAttributeInternal(RpcContext rpcContext, LockedInodePath inodePath, SetAttributeContext context) throws InvalidPathException, FileDoesNotExistException, AccessControlException, IOException {
    Inode targetInode = inodePath.getInode();
    long opTimeMs = System.currentTimeMillis();
    if (context.getOptions().getRecursive() && targetInode.isDirectory()) {
        try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
            for (LockedInodePath childPath : descendants) {
                rpcContext.throwIfCancelled();
                setAttributeSingleFile(rpcContext, childPath, true, opTimeMs, context);
            }
        }
    }
    setAttributeSingleFile(rpcContext, inodePath, true, opTimeMs, context);
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) Inode(alluxio.master.file.meta.Inode) LockedInodePathList(alluxio.master.file.meta.LockedInodePathList)

Example 18 with LockedInodePath

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

the class DefaultFileSystemMaster method getInAlluxioFiles.

@Override
public List<AlluxioURI> getInAlluxioFiles() throws UnavailableException {
    List<AlluxioURI> files = new ArrayList<>();
    LockedInodePath rootPath;
    try {
        rootPath = mInodeTree.lockFullInodePath(new AlluxioURI(AlluxioURI.SEPARATOR), LockPattern.READ);
    } catch (FileDoesNotExistException | InvalidPathException e) {
        // Root should always exist.
        throw new RuntimeException(e);
    }
    try (LockedInodePath inodePath = rootPath) {
        getInAlluxioFilesInternal(inodePath, files);
    }
    return files;
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 19 with LockedInodePath

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

the class DefaultFileSystemMaster method getFileInfo.

@Override
public FileInfo getFileInfo(AlluxioURI path, GetStatusContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
    Metrics.GET_FILE_INFO_OPS.inc();
    boolean ufsAccessed = false;
    long opTimeMs = System.currentTimeMillis();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("getFileInfo", path, null, null)) {
        if (!syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(Mode.Bits.READ, inodePath), true).equals(NOT_NEEDED)) {
            // If synced, do not load metadata.
            context.getOptions().setLoadMetadataType(LoadMetadataPType.NEVER);
            ufsAccessed = true;
        }
        LoadMetadataContext lmCtx = LoadMetadataContext.mergeFrom(LoadMetadataPOptions.newBuilder().setCreateAncestors(true).setLoadType(context.getOptions().getLoadMetadataType()).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction())));
        /*
      See the comments in #getFileIdInternal for an explanation on why the loop here is required.
       */
        boolean run = true;
        boolean loadMetadata = false;
        FileInfo ret = null;
        while (run) {
            run = false;
            if (loadMetadata) {
                checkLoadMetadataOptions(context.getOptions().getLoadMetadataType(), path);
                loadMetadataIfNotExist(rpcContext, path, lmCtx, true);
                ufsAccessed = true;
            }
            LockingScheme lockingScheme = new LockingScheme(path, LockPattern.READ, false);
            try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
                auditContext.setSrcInode(inodePath.getInodeOrNull());
                try {
                    mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
                } catch (AccessControlException e) {
                    auditContext.setAllowed(false);
                    throw e;
                }
                if (!loadMetadata && shouldLoadMetadataIfNotExists(inodePath, lmCtx)) {
                    loadMetadata = true;
                    run = true;
                    continue;
                }
                ensureFullPathAndUpdateCache(inodePath);
                FileInfo fileInfo = getFileInfoInternal(inodePath);
                if (!fileInfo.isFolder() && (!fileInfo.isCompleted())) {
                    LOG.debug("File {} is not yet completed. getStatus will see incomplete metadata.", fileInfo.getPath());
                }
                if (ufsAccessed) {
                    MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
                    Metrics.getUfsOpsSavedCounter(resolution.getUfsMountPointUri(), Metrics.UFSOps.GET_FILE_INFO).dec();
                }
                Mode.Bits accessMode = Mode.Bits.fromProto(context.getOptions().getAccessMode());
                if (context.getOptions().getUpdateTimestamps() && context.getOptions().hasAccessMode() && (accessMode.imply(Mode.Bits.READ) || accessMode.imply(Mode.Bits.WRITE))) {
                    mAccessTimeUpdater.updateAccessTime(rpcContext.getJournalContext(), inodePath.getInode(), opTimeMs);
                }
                auditContext.setSrcInode(inodePath.getInode()).setSucceeded(true);
                ret = fileInfo;
            }
        }
        return ret;
    }
}
Also used : Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode) AccessControlException(alluxio.exception.AccessControlException) MountTable(alluxio.master.file.meta.MountTable) LockedInodePath(alluxio.master.file.meta.LockedInodePath) LoadMetadataContext(alluxio.master.file.contexts.LoadMetadataContext) FileInfo(alluxio.wire.FileInfo) LockingScheme(alluxio.master.file.meta.LockingScheme)

Example 20 with LockedInodePath

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

the class DefaultFileSystemMaster method getFileBlockInfoList.

@Override
public List<FileBlockInfo> getFileBlockInfoList(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnavailableException {
    Metrics.GET_FILE_BLOCK_INFO_OPS.inc();
    try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.READ);
        FileSystemMasterAuditContext auditContext = createAuditContext("getFileBlockInfoList", path, null, inodePath.getInodeOrNull())) {
        try {
            mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
        } catch (AccessControlException e) {
            auditContext.setAllowed(false);
            throw e;
        }
        List<FileBlockInfo> ret = getFileBlockInfoListInternal(inodePath);
        Metrics.FILE_BLOCK_INFOS_GOT.inc();
        auditContext.setSucceeded(true);
        return ret;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) AccessControlException(alluxio.exception.AccessControlException) FileBlockInfo(alluxio.wire.FileBlockInfo)

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