Search in sources :

Example 71 with LockedInodePath

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

the class DefaultFileSystemMaster method recordActiveSyncTxid.

@Override
public boolean recordActiveSyncTxid(long txId, long mountId) {
    MountInfo mountInfo = mMountTable.getMountInfo(mountId);
    if (mountInfo == null) {
        return false;
    }
    AlluxioURI mountPath = mountInfo.getAlluxioUri();
    try (RpcContext rpcContext = createRpcContext();
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(mountPath, LockPattern.READ)) {
        File.ActiveSyncTxIdEntry txIdEntry = File.ActiveSyncTxIdEntry.newBuilder().setTxId(txId).setMountId(mountId).build();
        rpcContext.journal(JournalEntry.newBuilder().setActiveSyncTxId(txIdEntry).build());
    } catch (UnavailableException | InvalidPathException | FileDoesNotExistException e) {
        LOG.warn("Exception when recording activesync txid, path {}, exception {}", mountPath, e);
        return false;
    }
    return true;
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) MountInfo(alluxio.master.file.meta.options.MountInfo) InodeFile(alluxio.master.file.meta.InodeFile) PersistFile(alluxio.wire.PersistFile) File(alluxio.proto.journal.File) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 72 with LockedInodePath

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

the class DefaultFileSystemMaster method rename.

@Override
public void rename(AlluxioURI srcPath, AlluxioURI dstPath, RenameContext context) throws FileAlreadyExistsException, FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    if (isOperationComplete(context)) {
        Metrics.COMPLETED_OPERATION_RETRIED_COUNT.inc();
        LOG.warn("A completed \"rename\" operation has been retried. {}", context);
        return;
    }
    Metrics.RENAME_PATH_OPS.inc();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("rename", srcPath, dstPath, null)) {
        syncMetadata(rpcContext, srcPath, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getParentInodeOrNull, (inodePath, permChecker) -> permChecker.checkParentPermission(Mode.Bits.WRITE, inodePath), false);
        syncMetadata(rpcContext, dstPath, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getParentInodeOrNull, (inodePath, permChecker) -> permChecker.checkParentPermission(Mode.Bits.WRITE, inodePath), false);
        LockingScheme srcLockingScheme = createLockingScheme(srcPath, context.getOptions().getCommonOptions(), LockPattern.WRITE_EDGE);
        LockingScheme dstLockingScheme = createLockingScheme(dstPath, context.getOptions().getCommonOptions(), LockPattern.WRITE_EDGE);
        try (InodePathPair inodePathPair = mInodeTree.lockInodePathPair(srcLockingScheme.getPath(), srcLockingScheme.getPattern(), dstLockingScheme.getPath(), dstLockingScheme.getPattern())) {
            LockedInodePath srcInodePath = inodePathPair.getFirst();
            LockedInodePath dstInodePath = inodePathPair.getSecond();
            auditContext.setSrcInode(srcInodePath.getParentInodeOrNull());
            try {
                mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, srcInodePath);
                mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, dstInodePath);
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            mMountTable.checkUnderWritableMountPoint(srcPath);
            mMountTable.checkUnderWritableMountPoint(dstPath);
            renameInternal(rpcContext, srcInodePath, dstInodePath, context);
            auditContext.setSrcInode(srcInodePath.getInode()).setSucceeded(true);
            cacheOperation(context);
            LOG.debug("Renamed {} to {}", srcPath, dstPath);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException) InodePathPair(alluxio.master.file.meta.InodePathPair)

Example 73 with LockedInodePath

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

the class DefaultFileSystemMaster method mount.

@Override
public void mount(AlluxioURI alluxioPath, AlluxioURI ufsPath, MountContext context) throws FileAlreadyExistsException, FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    Metrics.MOUNT_OPS.inc();
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("mount", alluxioPath, null, null)) {
        ufsPath = new AlluxioURI(PathUtils.normalizePath(ufsPath.toString(), AlluxioURI.SEPARATOR));
        syncMetadata(rpcContext, alluxioPath, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getParentInodeOrNull, (inodePath, permChecker) -> permChecker.checkParentPermission(Mode.Bits.WRITE, inodePath), false);
        LockingScheme lockingScheme = createLockingScheme(alluxioPath, context.getOptions().getCommonOptions(), LockPattern.WRITE_EDGE);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            auditContext.setSrcInode(inodePath.getParentInodeOrNull());
            try {
                mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
            } catch (AccessControlException e) {
                auditContext.setAllowed(false);
                throw e;
            }
            mMountTable.checkUnderWritableMountPoint(alluxioPath);
            mountInternal(rpcContext, inodePath, ufsPath, context);
            auditContext.setSucceeded(true);
            Metrics.PATHS_MOUNTED.inc();
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LockingScheme(alluxio.master.file.meta.LockingScheme) AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI)

Example 74 with LockedInodePath

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

the class DefaultFileSystemMaster method exists.

@Override
public boolean exists(AlluxioURI path, ExistsContext context) throws AccessControlException, IOException {
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("exists", path, null, null)) {
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(Mode.Bits.READ, inodePath), false);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ))) {
            LoadMetadataContext lmCtx = LoadMetadataContext.create(LoadMetadataPOptions.newBuilder().setCommonOptions(context.getOptions().getCommonOptions()).setLoadType(context.getOptions().getLoadMetadataType()));
            if (shouldLoadMetadataIfNotExists(inodePath, lmCtx)) {
                checkLoadMetadataOptions(context.getOptions().getLoadMetadataType(), path);
                loadMetadataIfNotExist(rpcContext, path, lmCtx, false);
            }
        } catch (FileDoesNotExistException e) {
            return false;
        }
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ))) {
            auditContext.setSucceeded(true);
            return inodePath.fullPathExists();
        }
    } catch (InvalidPathException e) {
        return false;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LoadMetadataContext(alluxio.master.file.contexts.LoadMetadataContext) InvalidPathException(alluxio.exception.InvalidPathException)

Example 75 with LockedInodePath

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

the class DefaultFileSystemMaster method getInMemoryFiles.

@Override
public List<AlluxioURI> getInMemoryFiles() throws UnavailableException {
    List<AlluxioURI> files = new ArrayList<>();
    LockedInodePath rootPath;
    try {
        rootPath = mInodeTree.lockFullInodePath(new AlluxioURI(AlluxioURI.SEPARATOR), LockPattern.READ);
    } catch (FileDoesNotExistException | InvalidPathException e) {
        // Root should always exist.
        throw new RuntimeException(e);
    }
    try (LockedInodePath inodePath = rootPath) {
        getInMemoryFilesInternal(inodePath, files);
    }
    return files;
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

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