Search in sources :

Example 61 with LockedInodePath

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

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

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

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

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

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