Search in sources :

Example 16 with LockingScheme

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

the class DefaultFileSystemMaster method loadMetadataIfNotExist.

/**
 * Loads metadata for the path if it is (non-existing || load direct children is set).
 *
 * See {@link #shouldLoadMetadataIfNotExists(LockedInodePath, LoadMetadataContext)}.
 *
 * @param rpcContext the rpc context
 * @param path the path to load metadata for
 * @param context the {@link LoadMetadataContext}
 * @param isGetFileInfo whether this is loading for a {@link #getFileInfo} call
 */
private void loadMetadataIfNotExist(RpcContext rpcContext, AlluxioURI path, LoadMetadataContext context, boolean isGetFileInfo) throws InvalidPathException, AccessControlException {
    DescendantType syncDescendantType = GrpcUtils.fromProto(context.getOptions().getLoadDescendantType());
    FileSystemMasterCommonPOptions commonOptions = context.getOptions().getCommonOptions();
    boolean loadAlways = context.getOptions().hasLoadType() && (context.getOptions().getLoadType().equals(LoadMetadataPType.ALWAYS));
    // load metadata only and force sync
    InodeSyncStream sync = new InodeSyncStream(new LockingScheme(path, LockPattern.READ, false), this, rpcContext, syncDescendantType, commonOptions, isGetFileInfo, true, true, loadAlways);
    if (sync.sync().equals(FAILED)) {
        LOG.debug("Failed to load metadata for path from UFS: {}", path);
    }
}
Also used : LockingScheme(alluxio.master.file.meta.LockingScheme) FileSystemMasterCommonPOptions(alluxio.grpc.FileSystemMasterCommonPOptions) DescendantType(alluxio.file.options.DescendantType)

Example 17 with LockingScheme

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

the class DefaultFileSystemMaster method delete.

@Override
public void delete(AlluxioURI path, DeleteContext context) throws IOException, FileDoesNotExistException, DirectoryNotEmptyException, InvalidPathException, AccessControlException {
    if (isOperationComplete(context)) {
        Metrics.COMPLETED_OPERATION_RETRIED_COUNT.inc();
        LOG.warn("A completed \"delete\" operation has been retried. {}", context);
        return;
    }
    Metrics.DELETE_PATHS_OPS.inc();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("delete", path, null, null)) {
        if (context.getOptions().getAlluxioOnly()) {
            LOG.debug("alluxio-only deletion on path {} skips metadata sync", path);
        } else {
            syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), context.getOptions().getRecursive() ? DescendantType.ALL : DescendantType.ONE, auditContext, LockedInodePath::getInodeOrNull, (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)) {
            mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
            if (context.getOptions().getRecursive()) {
                List<String> failedChildren = new ArrayList<>();
                try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
                    for (LockedInodePath childPath : descendants) {
                        try {
                            mPermissionChecker.checkPermission(Mode.Bits.WRITE, childPath);
                            if (mMountTable.isMountPoint(childPath.getUri())) {
                                mMountTable.checkUnderWritableMountPoint(childPath.getUri());
                            }
                        } catch (AccessControlException e) {
                            failedChildren.add(e.getMessage());
                        }
                    }
                    if (failedChildren.size() > 0) {
                        throw new AccessControlException(ExceptionMessage.DELETE_FAILED_DIR_CHILDREN.getMessage(path, StringUtils.join(failedChildren, ",")));
                    }
                } catch (AccessControlException e) {
                    auditContext.setAllowed(false);
                    throw e;
                }
            }
            mMountTable.checkUnderWritableMountPoint(path);
            if (!inodePath.fullPathExists()) {
                throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
            }
            deleteInternal(rpcContext, inodePath, context);
            auditContext.setSucceeded(true);
            cacheOperation(context);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LockingScheme(alluxio.master.file.meta.LockingScheme) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) LockedInodePathList(alluxio.master.file.meta.LockedInodePathList)

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