Search in sources :

Example 56 with LockedInodePath

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

the class ReplicationChecker method checkMisreplicated.

private void checkMisreplicated(Set<Long> inodes, ReplicationHandler handler) throws InterruptedException {
    for (long inodeId : inodes) {
        if (mActiveJobToInodeID.size() >= mMaxActiveJobs) {
            return;
        }
        if (mActiveJobToInodeID.containsValue(inodeId)) {
            continue;
        }
        // Throw if interrupted.
        if (Thread.interrupted()) {
            throw new InterruptedException("ReplicationChecker interrupted.");
        }
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(inodeId, LockPattern.READ)) {
            InodeFile file = inodePath.getInodeFile();
            for (long blockId : file.getBlockIds()) {
                BlockInfo blockInfo = null;
                try {
                    blockInfo = mBlockMaster.getBlockInfo(blockId);
                } catch (BlockInfoException e) {
                // Cannot find this block in Alluxio from BlockMaster, possibly persisted in UFS
                } catch (UnavailableException e) {
                    // The block master is not available, wait for the next heartbeat
                    LOG.warn("The block master is not available: {}", e.toString());
                    return;
                }
                if (blockInfo == null) {
                    // no block info available, we simply log and return;
                    LOG.warn("Block info is null");
                    return;
                }
                for (Map.Entry<String, String> entry : findMisplacedBlock(file, blockInfo).entrySet()) {
                    try {
                        final long jobId = handler.migrate(inodePath.getUri(), blockId, entry.getKey(), entry.getValue());
                        mActiveJobToInodeID.put(jobId, inodeId);
                    } catch (Exception e) {
                        LOG.warn("Unexpected exception encountered when starting a migration job (uri={}," + " block ID={}, workerHost= {}) : {}", inodePath.getUri(), blockId, entry.getKey(), e.toString());
                        LOG.debug("Exception: ", e);
                    }
                }
            }
        } catch (FileDoesNotExistException e) {
            LOG.warn("Failed to check replication level for inode id {} : {}", inodeId, e.toString());
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) BlockInfo(alluxio.wire.BlockInfo) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) InodeFile(alluxio.master.file.meta.InodeFile) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(com.google.common.collect.HashBiMap) JobDoesNotExistException(alluxio.exception.JobDoesNotExistException) ResourceExhaustedException(alluxio.exception.status.ResourceExhaustedException) BlockInfoException(alluxio.exception.BlockInfoException) IOException(java.io.IOException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 57 with LockedInodePath

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

the class AccessTimeUpdaterTest method updateAccessTimePrecision.

@Test
public void updateAccessTimePrecision() throws Exception {
    mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 0, Constants.HOUR_MS, 0);
    mAccessTimeUpdater.start();
    String path = "/foo";
    createInode(path, CreateFileContext.defaults());
    JournalContext journalContext = mock(JournalContext.class);
    when(journalContext.get()).thenReturn(journalContext);
    when(mFileSystemMaster.createJournalContext()).thenReturn(journalContext);
    long accessTime = CommonUtils.getCurrentMs() + 100L;
    long inodeId;
    try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
        mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), accessTime);
        inodeId = lockedInodes.getInode().getId();
    }
    // verify inode attribute is not updated
    assertNotEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
    // verify journal entry is not logged yet
    verify(journalContext, never()).append(any(Journal.JournalEntry.class));
    long newAccessTime = CommonUtils.getCurrentMs() + 2 * Constants.HOUR_MS;
    // update access time with a much later timestamp
    try (LockedInodePath lockedInodes = mInodeTree.lockFullInodePath(new AlluxioURI(path), InodeTree.LockPattern.READ)) {
        mAccessTimeUpdater.updateAccessTime(journalContext, lockedInodes.getInode(), newAccessTime);
        inodeId = lockedInodes.getInode().getId();
    }
    // verify inode attribute is updated
    assertEquals(newAccessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
    // / verify journal entry is logged
    ArgumentCaptor<Journal.JournalEntry> captor = ArgumentCaptor.forClass(Journal.JournalEntry.class);
    verify(journalContext).append(captor.capture());
    assertTrue(captor.getValue().hasUpdateInode());
    assertEquals(inodeId, captor.getValue().getUpdateInode().getId());
    assertEquals(newAccessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) NoopJournalContext(alluxio.master.journal.NoopJournalContext) JournalContext(alluxio.master.journal.JournalContext) Journal(alluxio.proto.journal.Journal) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 58 with LockedInodePath

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

the class DefaultFileSystemMaster method checkAccess.

@Override
public void checkAccess(AlluxioURI path, CheckAccessContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
    try (RpcContext rpcContext = createRpcContext(context);
        FileSystemMasterAuditContext auditContext = createAuditContext("checkAccess", path, null, null)) {
        Mode.Bits bits = Mode.Bits.fromProto(context.getOptions().getBits());
        syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.NONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(bits, inodePath), false);
        LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ);
        try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
            mPermissionChecker.checkPermission(bits, inodePath);
            if (!inodePath.fullPathExists()) {
                throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
            }
            auditContext.setSucceeded(true);
        }
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LockingScheme(alluxio.master.file.meta.LockingScheme) Mode(alluxio.security.authorization.Mode) UfsMode(alluxio.underfs.UfsMode)

Example 59 with LockedInodePath

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

the class DefaultFileSystemMaster method getNewBlockIdForFile.

@Override
public long getNewBlockIdForFile(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnavailableException {
    Metrics.GET_NEW_BLOCK_OPS.inc();
    try (RpcContext rpcContext = createRpcContext();
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.WRITE_INODE);
        FileSystemMasterAuditContext auditContext = createAuditContext("getNewBlockIdForFile", path, null, inodePath.getInodeOrNull())) {
        try {
            mPermissionChecker.checkPermission(Mode.Bits.WRITE, inodePath);
        } catch (AccessControlException e) {
            auditContext.setAllowed(false);
            throw e;
        }
        Metrics.NEW_BLOCKS_GOT.inc();
        long blockId = mInodeTree.newBlock(rpcContext, NewBlockEntry.newBuilder().setId(inodePath.getInode().getId()).build());
        auditContext.setSucceeded(true);
        return blockId;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) AccessControlException(alluxio.exception.AccessControlException)

Example 60 with LockedInodePath

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

the class DefaultFileSystemMaster method free.

@Override
public void free(AlluxioURI path, FreeContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnexpectedAlluxioException, IOException {
    Metrics.FREE_FILE_OPS.inc();
    // No need to syncMetadata before free.
    try (RpcContext rpcContext = createRpcContext(context);
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.WRITE_INODE);
        FileSystemMasterAuditContext auditContext = createAuditContext("free", path, null, inodePath.getInodeOrNull())) {
        try {
            mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
        } catch (AccessControlException e) {
            auditContext.setAllowed(false);
            throw e;
        }
        freeInternal(rpcContext, inodePath, context);
        auditContext.setSucceeded(true);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) AccessControlException(alluxio.exception.AccessControlException)

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