Search in sources :

Example 31 with LockedInodePath

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

the class AccessTimeUpdaterTest method updateAccessTimePrecisionAsync.

@Test
public void updateAccessTimePrecisionAsync() throws Exception {
    mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), Constants.MINUTE_MS, Constants.HOUR_MS, 0);
    mAccessTimeUpdater.start(mScheduler);
    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();
    }
    mScheduler.jumpAndExecute(2, TimeUnit.MINUTES);
    // verify inode attribute is not updated
    assertNotEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
    // verify journal entry is not logged
    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());
    mScheduler.jumpAndExecute(2, TimeUnit.SECONDS);
    // verify journal entry is not logged
    verify(journalContext, never()).append(any(Journal.JournalEntry.class));
    mScheduler.jumpAndExecute(2, TimeUnit.MINUTES);
    // / verify journal entry is logged after the flush interval
    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 32 with LockedInodePath

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

the class AccessTimeUpdaterTest method updateAccessTimeAsync.

@Test
public void updateAccessTimeAsync() throws Exception {
    mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 10 * Constants.SECOND_MS, 0, 0);
    mAccessTimeUpdater.start(mScheduler);
    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 updated
    assertEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
    mScheduler.jumpAndExecute(1, TimeUnit.SECONDS);
    // verify journal entry is NOT logged yet
    verify(journalContext, never()).append(any(Journal.JournalEntry.class));
    // wait for the flush to complete
    mScheduler.jumpAndExecute(11, TimeUnit.SECONDS);
    // / verify journal entry is logged after the flush interval
    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(accessTime, 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 33 with LockedInodePath

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

the class PermissionCheckerTest method getPermission.

@Test
public void getPermission() throws Exception {
    try (LockedInodePath path = sTree.lockInodePath(new AlluxioURI(TEST_WEIRD_FILE_URI), LockPattern.READ)) {
        // user is admin
        AuthenticatedClientUser.set(TEST_USER_ADMIN.getUser());
        Mode.Bits perm = mPermissionChecker.getPermission(path);
        Assert.assertEquals(Mode.Bits.ALL, perm);
        // user is owner
        AuthenticatedClientUser.set(TEST_USER_1.getUser());
        perm = mPermissionChecker.getPermission(path);
        Assert.assertEquals(TEST_WEIRD_MODE.getOwnerBits(), perm);
        // user is not owner but in group
        AuthenticatedClientUser.set(TEST_USER_3.getUser());
        perm = mPermissionChecker.getPermission(path);
        Assert.assertEquals(TEST_WEIRD_MODE.getGroupBits(), perm);
        // user is other
        AuthenticatedClientUser.set(TEST_USER_2.getUser());
        perm = mPermissionChecker.getPermission(path);
        Assert.assertEquals(TEST_WEIRD_MODE.getOtherBits(), perm);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) Mode(alluxio.security.authorization.Mode) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 34 with LockedInodePath

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

the class ReplicationCheckerTest method createBlockHelper.

/**
 * Helper to create a file with a single block.
 *
 * @param path Alluxio path of the file
 * @param context context to create the file
 * @param pinLocation
 * @return the block ID
 */
private long createBlockHelper(AlluxioURI path, CreatePathContext<?, ?> context, String pinLocation) throws Exception {
    try (LockedInodePath inodePath = mInodeTree.lockInodePath(path, LockPattern.WRITE_EDGE)) {
        List<Inode> created = mInodeTree.createPath(RpcContext.NOOP, inodePath, context);
        if (!pinLocation.equals("")) {
            mInodeTree.setPinned(RpcContext.NOOP, inodePath, true, ImmutableList.of(pinLocation), 0);
        }
        MutableInodeFile inodeFile = mInodeStore.getMutable(created.get(0).getId()).get().asFile();
        inodeFile.setBlockSizeBytes(1);
        inodeFile.setBlockIds(Arrays.asList(inodeFile.getNewBlockId()));
        inodeFile.setCompleted(true);
        mInodeStore.writeInode(inodeFile);
        return inodeFile.getBlockIdByIndex(0);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) MutableInodeFile(alluxio.master.file.meta.MutableInodeFile) Inode(alluxio.master.file.meta.Inode)

Example 35 with LockedInodePath

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

the class BlockMasterIntegrityIntegrationTest method removeFileMetadata.

private void removeFileMetadata(AlluxioURI uri) throws Exception {
    FileSystemMaster fsm = mCluster.getLocalAlluxioMaster().getMasterProcess().getMaster(FileSystemMaster.class);
    InodeTree tree = Whitebox.getInternalState(fsm, "mInodeTree");
    LockedInodePath path = tree.lockInodePath(uri, LockPattern.WRITE_EDGE);
    RpcContext rpcContext = ((DefaultFileSystemMaster) fsm).createRpcContext();
    ((DefaultFileSystemMaster) fsm).deleteInternal(rpcContext, path, DeleteContext.defaults());
    path.close();
    rpcContext.close();
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) RpcContext(alluxio.master.file.RpcContext) DefaultFileSystemMaster(alluxio.master.file.DefaultFileSystemMaster) DefaultFileSystemMaster(alluxio.master.file.DefaultFileSystemMaster) FileSystemMaster(alluxio.master.file.FileSystemMaster) InodeTree(alluxio.master.file.meta.InodeTree)

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