Search in sources :

Example 6 with LockingScheme

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

the class DefaultFileSystemMaster method setAttribute.

@Override
public void setAttribute(AlluxioURI path, SetAttributeContext context) throws FileDoesNotExistException, AccessControlException, InvalidPathException, IOException {
    SetAttributePOptions.Builder options = context.getOptions();
    Metrics.SET_ATTRIBUTE_OPS.inc();
    // for chown
    boolean rootRequired = options.hasOwner();
    // for chgrp, chmod
    boolean ownerRequired = (options.hasGroup()) || (options.hasMode());
    // for other attributes
    boolean writeRequired = !rootRequired && !ownerRequired;
    if (options.hasOwner() && options.hasGroup()) {
        try {
            checkUserBelongsToGroup(options.getOwner(), options.getGroup());
        } catch (IOException e) {
            throw new IOException(String.format("Could not update owner:group for %s to %s:%s. %s", path.toString(), options.getOwner(), options.getGroup(), e.toString()), e);
        }
    }
    String commandName;
    boolean checkWritableMountPoint = false;
    if (options.hasOwner()) {
        commandName = "chown";
        checkWritableMountPoint = true;
    } else if (options.hasGroup()) {
        commandName = "chgrp";
        checkWritableMountPoint = true;
    } else if (options.hasMode()) {
        commandName = "chmod";
        checkWritableMountPoint = true;
    } else {
        commandName = "setAttribute";
    }
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext(commandName, path, null, null)) {
        // Force recursive sync metadata if it is a pinning and unpinning operation
        boolean recursiveSync = options.hasPinned() || options.getRecursive();
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), recursiveSync ? DescendantType.ALL : DescendantType.ONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkSetAttributePermission(inodePath, rootRequired, ownerRequired, writeRequired), false);
        LockingScheme lockingScheme = createLockingScheme(path, options.getCommonOptions(), LockPattern.WRITE_INODE);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            auditContext.setSrcInode(inodePath.getInodeOrNull());
            if (checkWritableMountPoint) {
                mMountTable.checkUnderWritableMountPoint(path);
            }
            if (!inodePath.fullPathExists()) {
                throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
            }
            try {
                mPermissionChecker.checkSetAttributePermission(inodePath, rootRequired, ownerRequired, writeRequired);
                if (context.getOptions().getRecursive()) {
                    try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
                        for (LockedInodePath childPath : descendants) {
                            mPermissionChecker.checkSetAttributePermission(childPath, rootRequired, ownerRequired, writeRequired);
                        }
                    }
                }
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            setAttributeInternal(rpcContext, inodePath, context);
            auditContext.setSucceeded(true);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) LockedInodePathList(alluxio.master.file.meta.LockedInodePathList)

Example 7 with LockingScheme

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

the class DefaultFileSystemMaster method syncMetadata.

/**
 * Sync metadata for an Alluxio path with the UFS.
 *
 * @param rpcContext the current RPC context
 * @param path the path to sync
 * @param options options included with the RPC
 * @param syncDescendantType how deep the sync should be performed
 * @param auditContextSrcInodeFunc the src inode for the audit context, if null, no source inode
 *                                 is set on the audit context
 * @param permissionCheckOperation a consumer that accepts a locked inode path and a
 *                                 {@link PermissionChecker}. The consumer is expected to call one
 *                                 of the permission checkers functions with the given inode path.
 *                                 If null, no permission checking is performed
 * @param isGetFileInfo            true if syncing for a getFileInfo operation
 * @return syncStatus
 */
@VisibleForTesting
InodeSyncStream.SyncStatus syncMetadata(RpcContext rpcContext, AlluxioURI path, FileSystemMasterCommonPOptions options, DescendantType syncDescendantType, @Nullable FileSystemMasterAuditContext auditContext, @Nullable Function<LockedInodePath, Inode> auditContextSrcInodeFunc, @Nullable PermissionCheckFunction permissionCheckOperation, boolean isGetFileInfo) throws AccessControlException, InvalidPathException {
    LockingScheme syncScheme = createSyncLockingScheme(path, options, isGetFileInfo);
    InodeSyncStream sync = new InodeSyncStream(syncScheme, this, rpcContext, syncDescendantType, options, auditContext, auditContextSrcInodeFunc, permissionCheckOperation, isGetFileInfo, false, false, false);
    return sync.sync();
}
Also used : LockingScheme(alluxio.master.file.meta.LockingScheme) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with LockingScheme

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

the class DefaultFileSystemMaster method createDirectory.

@Override
public long createDirectory(AlluxioURI path, CreateDirectoryContext context) throws InvalidPathException, FileAlreadyExistsException, IOException, AccessControlException, FileDoesNotExistException {
    if (isOperationComplete(context)) {
        Metrics.COMPLETED_OPERATION_RETRIED_COUNT.inc();
        LOG.warn("A completed \"createDirectory\" operation has been retried. {}", context);
        return getFileInfo(path, GetStatusContext.create(GetStatusPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(-1)).setLoadMetadataType(LoadMetadataPType.NEVER).setUpdateTimestamps(false))).getFileId();
    }
    Metrics.CREATE_DIRECTORIES_OPS.inc();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("mkdir", path, null, null)) {
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, inodePath -> context.getOptions().getRecursive() ? inodePath.getLastExistingInode() : inodePath.getParentInodeOrNull(), (inodePath, permChecker) -> permChecker.checkParentPermission(Mode.Bits.WRITE, inodePath), false);
        LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.WRITE_EDGE);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            auditContext.setSrcInode(inodePath.getParentInodeOrNull());
            if (context.getOptions().getRecursive()) {
                auditContext.setSrcInode(inodePath.getLastExistingInode());
            }
            try {
                mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            mMountTable.checkUnderWritableMountPoint(path);
            if (context.isPersisted()) {
                checkUfsMode(path, OperationType.WRITE);
            }
            createDirectoryInternal(rpcContext, inodePath, context);
            auditContext.setSrcInode(inodePath.getInode()).setSucceeded(true);
            cacheOperation(context);
            return inodePath.getInode().getId();
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException)

Example 9 with LockingScheme

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

the class DefaultFileSystemMaster method checkConsistency.

@Override
public List<AlluxioURI> checkConsistency(AlluxioURI path, CheckConsistencyContext context) throws AccessControlException, FileDoesNotExistException, InvalidPathException, IOException {
    List<AlluxioURI> inconsistentUris = new ArrayList<>();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("checkConsistency", path, null, null)) {
        InodeSyncStream.SyncStatus syncStatus = syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.ALL, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(Mode.Bits.READ, inodePath), false);
        LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ);
        try (LockedInodePath parent = mInodeTree.lockInodePath(lockingScheme.getPath(), lockingScheme.getPattern())) {
            auditContext.setSrcInode(parent.getInodeOrNull());
            try {
                mPermissionChecker.checkPermission(Mode.Bits.READ, parent);
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            checkConsistencyRecursive(parent, inconsistentUris, false, syncStatus == OK);
            auditContext.setSucceeded(true);
        }
    }
    return inconsistentUris;
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI)

Example 10 with LockingScheme

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

the class DefaultFileSystemMaster method updateMount.

@Override
public void updateMount(AlluxioURI alluxioPath, MountContext context) throws FileAlreadyExistsException, FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    LockingScheme lockingScheme = createLockingScheme(alluxioPath, context.getOptions().getCommonOptions(), LockPattern.WRITE_EDGE);
    try (RpcContext rpcContext = createRpcContext(context);
        LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme.getPath(), lockingScheme.getPattern());
        FileSystemMasterAuditContext auditContext = createAuditContext("updateMount", alluxioPath, null, inodePath.getParentInodeOrNull())) {
        try {
            mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
        } catch (AccessControlException e) {
            auditContext.setAllowed(false);
            throw e;
        }
        MountInfo mountInfo = mMountTable.getMountTable().get(alluxioPath.getPath());
        if (mountInfo == null) {
            throw new InvalidPathException("Failed to update mount properties for " + inodePath.getUri() + ". Please ensure the path is an existing mount point.");
        }
        updateMountInternal(rpcContext, inodePath, mountInfo.getUfsUri(), mountInfo, context);
        auditContext.setSucceeded(true);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException) MountInfo(alluxio.master.file.meta.options.MountInfo) InvalidPathException(alluxio.exception.InvalidPathException)

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