Search in sources :

Example 11 with JournalContext

use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.

the class AccessTimeUpdaterTest method updateAccessTimeImmediately.

@Test
public void updateAccessTimeImmediately() throws Exception {
    mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 0, 0, 0);
    mAccessTimeUpdater.start();
    String path = "/foo";
    JournalContext journalContext = mock(JournalContext.class);
    when(journalContext.get()).thenReturn(journalContext);
    createInode(path, CreateFileContext.defaults());
    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 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(accessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
    // verify inode attribute is updated
    assertEquals(accessTime, mInodeStore.get(inodeId).get().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 12 with JournalContext

use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.

the class AccessTimeUpdaterTest method updateAccessTimeAsyncOnShutdown.

@Test
public void updateAccessTimeAsyncOnShutdown() 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
    mContext.getJournalSystem().stop();
    // / 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 13 with JournalContext

use of alluxio.master.journal.JournalContext 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 14 with JournalContext

use of alluxio.master.journal.JournalContext 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 15 with JournalContext

use of alluxio.master.journal.JournalContext in project alluxio by Alluxio.

the class UfsStatusCacheTest method testFetchCancel.

@Test
public void testFetchCancel() throws Exception {
    spyUfs();
    doAnswer((Answer<UfsStatus[]>) invocation -> {
        Thread.sleep(30 * Constants.HOUR_MS);
        return new UfsStatus[] { Mockito.mock(UfsStatus.class) };
    }).when(mUfs).listStatus(any(String.class));
    mCache.prefetchChildren(new AlluxioURI("/"), mMountTable);
    final BlockDeletionContext bdc = mock(BlockDeletionContext.class);
    final JournalContext jc = mock(JournalContext.class);
    final OperationContext oc = mock(OperationContext.class);
    when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList());
    final RpcContext rpcContext = new RpcContext(bdc, jc, oc);
    AtomicReference<RuntimeException> ref = new AtomicReference<>(null);
    Thread t = new Thread(() -> {
        try {
            mCache.fetchChildrenIfAbsent(rpcContext, new AlluxioURI("/"), mMountTable);
            fail("Should not have been able to fetch children");
        } catch (RuntimeException e) {
            ref.set(e);
        } catch (InterruptedException | InvalidPathException e) {
        // do nothing
        }
    });
    t.start();
    when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList(new CallTracker() {

        @Override
        public boolean isCancelled() {
            return true;
        }

        @Override
        public Type getType() {
            return Type.GRPC_CLIENT_TRACKER;
        }
    }));
    t.join();
    final RuntimeException runtimeException = ref.get();
    assertNotNull(runtimeException);
    MatcherAssert.assertThat(runtimeException.getMessage(), Matchers.stringContainsInOrder("Call cancelled"));
}
Also used : Mockito.doThrow(org.mockito.Mockito.doThrow) Future(java.util.concurrent.Future) InvalidPathException(alluxio.exception.InvalidPathException) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Assert.fail(org.junit.Assert.fail) LocalUnderFileSystem(alluxio.underfs.local.LocalUnderFileSystem) ServerConfiguration(alluxio.conf.ServerConfiguration) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) NoopUfsAbsentPathCache(alluxio.master.file.meta.NoopUfsAbsentPathCache) MatcherAssert(org.hamcrest.MatcherAssert) Assert.assertFalse(org.junit.Assert.assertFalse) RpcContext(alluxio.master.file.RpcContext) JournalContext(alluxio.master.journal.JournalContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OperationContext(alluxio.master.file.contexts.OperationContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) PathUtils(alluxio.util.io.PathUtils) Answer(org.mockito.stubbing.Answer) Lists(com.google.common.collect.Lists) Constants(alluxio.Constants) MountInfo(alluxio.master.file.meta.options.MountInfo) AlluxioURI(alluxio.AlluxioURI) MountPOptions(alluxio.grpc.MountPOptions) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ReentrantLock(java.util.concurrent.locks.ReentrantLock) IdUtils(alluxio.util.IdUtils) Assert.assertNotNull(org.junit.Assert.assertNotNull) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) UfsAbsentPathCache(alluxio.master.file.meta.UfsAbsentPathCache) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Lock(java.util.concurrent.locks.Lock) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) CallTracker(alluxio.master.file.contexts.CallTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MountTable(alluxio.master.file.meta.MountTable) TemporaryFolder(org.junit.rules.TemporaryFolder) OperationContext(alluxio.master.file.contexts.OperationContext) JournalContext(alluxio.master.journal.JournalContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvalidPathException(alluxio.exception.InvalidPathException) RpcContext(alluxio.master.file.RpcContext) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) AlluxioURI(alluxio.AlluxioURI) CallTracker(alluxio.master.file.contexts.CallTracker) Test(org.junit.Test)

Aggregations

JournalContext (alluxio.master.journal.JournalContext)26 Test (org.junit.Test)15 AlluxioURI (alluxio.AlluxioURI)9 NoopMaster (alluxio.master.NoopMaster)9 HashMap (java.util.HashMap)8 LockedInodePath (alluxio.master.file.meta.LockedInodePath)6 NoopJournalContext (alluxio.master.journal.NoopJournalContext)5 Journal (alluxio.proto.journal.Journal)5 CatchupFuture (alluxio.master.journal.CatchupFuture)4 LockResource (alluxio.resource.LockResource)4 MountInfo (alluxio.master.file.meta.options.MountInfo)3 ExpectedException (org.junit.rules.ExpectedException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 NotFoundException (alluxio.exception.status.NotFoundException)2 UnavailableException (alluxio.exception.status.UnavailableException)2 MountPOptions (alluxio.grpc.MountPOptions)2 HeartbeatThread (alluxio.heartbeat.HeartbeatThread)2 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)2 Inode (alluxio.master.file.meta.Inode)2