Search in sources :

Example 6 with LockedInodePathList

use of alluxio.master.file.meta.LockedInodePathList 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 LockedInodePathList

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

the class DefaultFileSystemMaster method freeInternal.

/**
 * Implements free operation.
 *
 * @param rpcContext the rpc context
 * @param inodePath inode of the path to free
 * @param context context to free method
 */
private void freeInternal(RpcContext rpcContext, LockedInodePath inodePath, FreeContext context) throws FileDoesNotExistException, UnexpectedAlluxioException, IOException, InvalidPathException, AccessControlException {
    Inode inode = inodePath.getInode();
    if (inode.isDirectory() && !context.getOptions().getRecursive() && mInodeStore.hasChildren(inode.asDirectory())) {
        // inode is nonempty, and we don't free a nonempty directory unless recursive is true
        throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_EMPTY_DIR.getMessage(mInodeTree.getPath(inode)));
    }
    long opTimeMs = System.currentTimeMillis();
    List<Inode> freeInodes = new ArrayList<>();
    freeInodes.add(inode);
    try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
        for (LockedInodePath descedant : Iterables.concat(descendants, Collections.singleton(inodePath))) {
            Inode freeInode = descedant.getInodeOrNull();
            if (freeInode != null && freeInode.isFile()) {
                if (freeInode.getPersistenceState() != PersistenceState.PERSISTED) {
                    throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_PERSISTED_FILE.getMessage(mInodeTree.getPath(freeInode)));
                }
                if (freeInode.isPinned()) {
                    if (!context.getOptions().getForced()) {
                        throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_PINNED_FILE.getMessage(mInodeTree.getPath(freeInode)));
                    }
                    SetAttributeContext setAttributeContext = SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setRecursive(false).setPinned(false));
                    setAttributeSingleFile(rpcContext, descedant, true, opTimeMs, setAttributeContext);
                }
                // Remove corresponding blocks from workers.
                mBlockMaster.removeBlocks(freeInode.asFile().getBlockIds(), false);
            }
        }
    }
    Metrics.FILES_FREED.inc(freeInodes.size());
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAttributeContext(alluxio.master.file.contexts.SetAttributeContext) Inode(alluxio.master.file.meta.Inode) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException) ArrayList(java.util.ArrayList) LockedInodePathList(alluxio.master.file.meta.LockedInodePathList)

Example 8 with LockedInodePathList

use of alluxio.master.file.meta.LockedInodePathList 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

LockedInodePath (alluxio.master.file.meta.LockedInodePath)8 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)8 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 AccessControlException (alluxio.exception.AccessControlException)4 Inode (alluxio.master.file.meta.Inode)4 LockingScheme (alluxio.master.file.meta.LockingScheme)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)2 ArrayList (java.util.ArrayList)2 AlluxioURI (alluxio.AlluxioURI)1 ClientContext (alluxio.ClientContext)1 Constants (alluxio.Constants)1 Server (alluxio.Server)1 JobMasterClient (alluxio.client.job.JobMasterClient)1 JobMasterClientPool (alluxio.client.job.JobMasterClientPool)1 SystemClock (alluxio.clock.SystemClock)1 Pair (alluxio.collections.Pair)1 PrefixList (alluxio.collections.PrefixList)1 PropertyKey (alluxio.conf.PropertyKey)1