Search in sources :

Example 1 with LockingScheme

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

the class DefaultFileSystemMaster method stopSync.

@Override
public void stopSync(AlluxioURI syncPoint) throws IOException, InvalidPathException, AccessControlException {
    try (RpcContext rpcContext = createRpcContext()) {
        boolean isSuperUser = true;
        try {
            mPermissionChecker.checkSuperUser();
        } catch (AccessControlException e) {
            isSuperUser = false;
        }
        if (isSuperUser) {
            // TODO(AM): Remove once we don't require a write lock on the sync point during a full sync
            // Stop sync w/o acquiring an inode lock to terminate an initial full scan (if running)
            mSyncManager.stopSyncAndJournal(rpcContext, syncPoint);
        }
        LockingScheme lockingScheme = new LockingScheme(syncPoint, LockPattern.READ, false);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme.getPath(), lockingScheme.getPattern());
            FileSystemMasterAuditContext auditContext = createAuditContext("stopSync", syncPoint, null, inodePath.getParentInodeOrNull())) {
            try {
                mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            if (!isSuperUser) {
                // Stop sync here only if not terminated w/o holding the inode lock
                mSyncManager.stopSyncAndJournal(rpcContext, syncPoint);
            }
            auditContext.setSucceeded(true);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException)

Example 2 with LockingScheme

use of alluxio.master.file.meta.LockingScheme 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 3 with LockingScheme

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

the class DefaultFileSystemMaster method activeSyncMetadata.

/**
 * Actively sync metadata, based on a list of changed files.
 *
 * @param path the path to sync
 * @param changedFiles collection of files that are changed under the path to sync, if this is
 *        null, force sync the entire directory
 * @param executorService executor to execute the parallel incremental sync
 */
public void activeSyncMetadata(AlluxioURI path, Collection<AlluxioURI> changedFiles, ExecutorService executorService) throws IOException {
    if (changedFiles == null) {
        LOG.info("Start an active full sync of {}", path.toString());
    } else {
        LOG.info("Start an active incremental sync of {} files", changedFiles.size());
    }
    long start = System.currentTimeMillis();
    if (changedFiles != null && changedFiles.isEmpty()) {
        return;
    }
    try (RpcContext rpcContext = createRpcContext()) {
        if (changedFiles == null) {
            // full sync
            // Set sync interval to 0 to force a sync.
            FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
            LockingScheme scheme = createSyncLockingScheme(path, options, false);
            InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ALL, options, false, false, false, false);
            if (sync.sync().equals(FAILED)) {
                LOG.debug("Active full sync on {} didn't sync any paths.", path);
            }
            long end = System.currentTimeMillis();
            LOG.info("Ended an active full sync of {} in {}ms", path.toString(), end - start);
            return;
        } else {
            // incremental sync
            Set<Callable<Void>> callables = new HashSet<>();
            for (AlluxioURI changedFile : changedFiles) {
                callables.add(() -> {
                    // Set sync interval to 0 to force a sync.
                    FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
                    LockingScheme scheme = createSyncLockingScheme(changedFile, options, false);
                    InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ONE, options, false, false, false, false);
                    if (sync.sync().equals(FAILED)) {
                        // Use debug because this can be a noisy log
                        LOG.debug("Incremental sync on {} didn't sync any paths.", path);
                    }
                    return null;
                });
            }
            executorService.invokeAll(callables);
        }
    } catch (InterruptedException e) {
        LOG.warn("InterruptedException during active sync: {}", e.toString());
        Thread.currentThread().interrupt();
        return;
    } catch (InvalidPathException | AccessControlException e) {
        LogUtils.warnWithException(LOG, "Failed to active sync on path {}", path, e);
    }
    if (changedFiles != null) {
        long end = System.currentTimeMillis();
        LOG.info("Ended an active incremental sync of {} files in {}ms", changedFiles.size(), end - start);
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) Callable(java.util.concurrent.Callable) InvalidPathException(alluxio.exception.InvalidPathException) LockingScheme(alluxio.master.file.meta.LockingScheme) FileSystemMasterCommonPOptions(alluxio.grpc.FileSystemMasterCommonPOptions) HashSet(java.util.HashSet) AlluxioURI(alluxio.AlluxioURI)

Example 4 with LockingScheme

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

the class DefaultFileSystemMaster method setAcl.

@Override
public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclContext context) throws FileDoesNotExistException, AccessControlException, InvalidPathException, IOException {
    Metrics.SET_ACL_OPS.inc();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("setAcl", path, null, null)) {
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), context.getOptions().getRecursive() ? DescendantType.ALL : DescendantType.NONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkSetAttributePermission(inodePath, false, true, false), false);
        LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.WRITE_INODE);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            mPermissionChecker.checkSetAttributePermission(inodePath, false, true, false);
            if (context.getOptions().getRecursive()) {
                try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
                    for (LockedInodePath child : descendants) {
                        mPermissionChecker.checkSetAttributePermission(child, false, true, false);
                    }
                } catch (AccessControlException e) {
                    auditContext.setAllowed(false);
                    throw e;
                }
            }
            if (!inodePath.fullPathExists()) {
                throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
            }
            setAclInternal(rpcContext, action, inodePath, entries, context);
            auditContext.setSucceeded(true);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException) LockedInodePathList(alluxio.master.file.meta.LockedInodePathList)

Example 5 with LockingScheme

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

the class DefaultFileSystemMaster method checkAccess.

@Override
public void checkAccess(AlluxioURI path, CheckAccessContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("checkAccess", path, null, null)) {
        Mode.Bits bits = Mode.Bits.fromProto(context.getOptions().getBits());
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.NONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(bits, inodePath), false);
        LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            mPermissionChecker.checkPermission(bits, inodePath);
            if (!inodePath.fullPathExists()) {
                throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
            }
            auditContext.setSucceeded(true);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LockingScheme(alluxio.master.file.meta.LockingScheme) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode)

Aggregations

LockingScheme (alluxio.master.file.meta.LockingScheme)17 AccessControlException (alluxio.exception.AccessControlException)14 LockedInodePath (alluxio.master.file.meta.LockedInodePath)14 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 AlluxioURI (alluxio.AlluxioURI)3 InvalidPathException (alluxio.exception.InvalidPathException)3 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)3 DescendantType (alluxio.file.options.DescendantType)2 FileSystemMasterCommonPOptions (alluxio.grpc.FileSystemMasterCommonPOptions)2 LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)2 MountTable (alluxio.master.file.meta.MountTable)2 Mode (alluxio.security.authorization.Mode)2 UfsMode (alluxio.underfs.UfsMode)2 ArrayList (java.util.ArrayList)2 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)1 Inode (alluxio.master.file.meta.Inode)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 InodePathPair (alluxio.master.file.meta.InodePathPair)1 MountInfo (alluxio.master.file.meta.options.MountInfo)1 FileInfo (alluxio.wire.FileInfo)1