Search in sources :

Example 36 with LockedInodePath

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

the class PermissionCheckTest method getPermissionOther.

@Test
public void getPermissionOther() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_2.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.READ, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 37 with LockedInodePath

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

the class PermissionCheckTest method getPermissionGroup.

@Test
public void getPermissionGroup() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_3.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.READ_EXECUTE, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with LockedInodePath

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

the class FileSystemMaster method setAttributeAndJournal.

/**
   * Sets the file attribute.
   * <p>
   * Writes to the journal.
   *
   * @param inodePath the {@link LockedInodePath} to set attribute for
   * @param rootRequired indicates whether it requires to be the superuser
   * @param ownerRequired indicates whether it requires to be the owner of this path
   * @param options attributes to be set, see {@link SetAttributeOptions}
   * @param journalContext the journal context
   * @throws InvalidPathException if the given path is invalid
   * @throws FileDoesNotExistException if the file does not exist
   * @throws AccessControlException if permission checking fails
   */
private void setAttributeAndJournal(LockedInodePath inodePath, boolean rootRequired, boolean ownerRequired, SetAttributeOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, AccessControlException {
    Inode<?> targetInode = inodePath.getInode();
    long opTimeMs = System.currentTimeMillis();
    if (options.isRecursive() && targetInode.isDirectory()) {
        try (InodeLockList lockList = mInodeTree.lockDescendants(inodePath, InodeTree.LockMode.WRITE)) {
            List<Inode<?>> inodeChildren = lockList.getInodes();
            for (Inode<?> inode : inodeChildren) {
                // the path to inode for getPath should already be locked.
                try (LockedInodePath childPath = mInodeTree.lockFullInodePath(mInodeTree.getPath(inode), InodeTree.LockMode.READ)) {
                    // TODO(gpang): a better way to check permissions
                    mPermissionChecker.checkSetAttributePermission(childPath, rootRequired, ownerRequired);
                }
            }
            TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
            for (Inode<?> inode : inodeChildren) {
                // the path to inode for getPath should already be locked.
                tempInodePath.setDescendant(inode, mInodeTree.getPath(inode));
                List<Inode<?>> persistedInodes = setAttributeInternal(tempInodePath, false, opTimeMs, options);
                journalPersistedInodes(persistedInodes, journalContext);
                journalSetAttribute(tempInodePath, opTimeMs, options, journalContext);
            }
        }
    }
    List<Inode<?>> persistedInodes = setAttributeInternal(inodePath, false, opTimeMs, options);
    journalPersistedInodes(persistedInodes, journalContext);
    journalSetAttribute(inodePath, opTimeMs, options, journalContext);
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) Inode(alluxio.master.file.meta.Inode) TempInodePathForDescendant(alluxio.master.file.meta.TempInodePathForDescendant) InodeLockList(alluxio.master.file.meta.InodeLockList)

Example 39 with LockedInodePath

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

the class FileSystemMaster method getFileId.

/**
   * Returns the file id for a given path. If the given path does not exist in Alluxio, the method
   * attempts to load it from UFS.
   * <p>
   * This operation requires users to have {@link Mode.Bits#READ} permission of the path.
   *
   * @param path the path to get the file id for
   * @return the file id for a given path, or -1 if there is no file at that path
   * @throws AccessControlException if permission checking fails
   */
public long getFileId(AlluxioURI path) throws AccessControlException {
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
        // This is WRITE locked, since loading metadata is possible.
        mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
        loadMetadataIfNotExistAndJournal(inodePath, LoadMetadataOptions.defaults().setCreateAncestors(true), journalContext);
        mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
        return inodePath.getInode().getId();
    } catch (InvalidPathException | FileDoesNotExistException e) {
        return IdUtils.INVALID_FILE_ID;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 40 with LockedInodePath

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

the class FileSystemMaster method processJournalEntry.

@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
    if (entry.hasInodeFile()) {
        mInodeTree.addInodeFileFromJournal(entry.getInodeFile());
        // Add the file to TTL buckets, the insert automatically rejects files w/ Constants.NO_TTL
        InodeFileEntry inodeFileEntry = entry.getInodeFile();
        if (inodeFileEntry.hasTtl()) {
            mTtlBuckets.insert(InodeFile.fromJournalEntry(inodeFileEntry));
        }
    } else if (entry.hasInodeDirectory()) {
        try {
            // Add the directory to TTL buckets, the insert automatically rejects directory
            // w/ Constants.NO_TTL
            InodeDirectoryEntry inodeDirectoryEntry = entry.getInodeDirectory();
            if (inodeDirectoryEntry.hasTtl()) {
                mTtlBuckets.insert(InodeDirectory.fromJournalEntry(inodeDirectoryEntry));
            }
            mInodeTree.addInodeDirectoryFromJournal(entry.getInodeDirectory());
        } catch (AccessControlException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasInodeLastModificationTime()) {
        InodeLastModificationTimeEntry modTimeEntry = entry.getInodeLastModificationTime();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(modTimeEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setLastModificationTimeMs(modTimeEntry.getLastModificationTimeMs(), true);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasPersistDirectory()) {
        PersistDirectoryEntry typedEntry = entry.getPersistDirectory();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(typedEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setPersistenceState(PersistenceState.PERSISTED);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasCompleteFile()) {
        try {
            completeFileFromEntry(entry.getCompleteFile());
        } catch (InvalidPathException | InvalidFileSizeException | FileAlreadyCompletedException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasSetAttribute()) {
        try {
            setAttributeFromEntry(entry.getSetAttribute());
        } catch (AccessControlException | FileDoesNotExistException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteFile()) {
        deleteFromEntry(entry.getDeleteFile());
    } else if (entry.hasRename()) {
        renameFromEntry(entry.getRename());
    } else if (entry.hasInodeDirectoryIdGenerator()) {
        mDirectoryIdGenerator.initFromJournalEntry(entry.getInodeDirectoryIdGenerator());
    } else if (entry.hasReinitializeFile()) {
        resetBlockFileFromEntry(entry.getReinitializeFile());
    } else if (entry.hasAddMountPoint()) {
        try {
            mountFromEntry(entry.getAddMountPoint());
        } catch (FileAlreadyExistsException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteMountPoint()) {
        try {
            unmountFromEntry(entry.getDeleteMountPoint());
        } catch (InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasAsyncPersistRequest()) {
        try {
            long fileId = (entry.getAsyncPersistRequest()).getFileId();
            try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) {
                scheduleAsyncPersistenceInternal(inodePath);
            }
            // NOTE: persistence is asynchronous so there is no guarantee the path will still exist
            mAsyncPersistHandler.scheduleAsyncPersistence(getPath(fileId));
        } catch (AlluxioException e) {
            // It's possible that rescheduling the async persist calls fails, because the blocks may no
            // longer be in the memory
            LOG.error(e.getMessage());
        }
    } else {
        throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InodeFileEntry(alluxio.proto.journal.File.InodeFileEntry) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InodeLastModificationTimeEntry(alluxio.proto.journal.File.InodeLastModificationTimeEntry) PersistDirectoryEntry(alluxio.proto.journal.File.PersistDirectoryEntry) InvalidPathException(alluxio.exception.InvalidPathException) LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeDirectoryEntry(alluxio.proto.journal.File.InodeDirectoryEntry) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioException(alluxio.exception.AlluxioException) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException)

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