Search in sources :

Example 1 with Journal

use of alluxio.proto.journal.Journal in project alluxio by Alluxio.

the class MountTable method add.

/**
 * Mounts the given UFS path at the given Alluxio path. The Alluxio path should not be nested
 * under an existing mount point.
 *
 * @param journalContext the journal context
 * @param alluxioUri an Alluxio path URI
 * @param ufsUri a UFS path URI
 * @param mountId the mount id
 * @param options the mount options
 * @throws FileAlreadyExistsException if the mount point already exists
 * @throws InvalidPathException if an invalid path is encountered
 */
public void add(Supplier<JournalContext> journalContext, AlluxioURI alluxioUri, AlluxioURI ufsUri, long mountId, MountPOptions options) throws FileAlreadyExistsException, InvalidPathException {
    String alluxioPath = alluxioUri.getPath().isEmpty() ? "/" : alluxioUri.getPath();
    LOG.info("Mounting {} at {}", ufsUri, alluxioPath);
    try (LockResource r = new LockResource(mWriteLock)) {
        if (mState.getMountTable().containsKey(alluxioPath)) {
            throw new FileAlreadyExistsException(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath));
        }
        // or suffix of any existing mount path.
        for (Map.Entry<String, MountInfo> entry : mState.getMountTable().entrySet()) {
            AlluxioURI mountedUfsUri = entry.getValue().getUfsUri();
            if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority().toString().equals(mountedUfsUri.getAuthority().toString()))) {
                String ufsPath = ufsUri.getPath().isEmpty() ? "/" : ufsUri.getPath();
                String mountedUfsPath = mountedUfsUri.getPath().isEmpty() ? "/" : mountedUfsUri.getPath();
                if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedUfsUri.toString(), ufsUri.toString()));
                }
                if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(ufsUri.toString(), mountedUfsUri.toString()));
                }
            }
        }
        Map<String, String> properties = options.getPropertiesMap();
        mState.applyAndJournal(journalContext, AddMountPointEntry.newBuilder().addAllProperties(properties.entrySet().stream().map(entry -> StringPairEntry.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build()).collect(Collectors.toList())).setAlluxioPath(alluxioPath).setMountId(mountId).setReadOnly(options.getReadOnly()).setShared(options.getShared()).setUfsPath(ufsUri.toString()).build());
    }
}
Also used : CloseableIterator(alluxio.resource.CloseableIterator) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) DeleteMountPointEntry(alluxio.proto.journal.File.DeleteMountPointEntry) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) PathUtils(alluxio.util.io.PathUtils) InvalidPathException(alluxio.exception.InvalidPathException) CloseableResource(alluxio.resource.CloseableResource) GrpcUtils(alluxio.grpc.GrpcUtils) AddMountPointEntry(alluxio.proto.journal.File.AddMountPointEntry) MountInfo(alluxio.master.file.meta.options.MountInfo) AlluxioURI(alluxio.AlluxioURI) Map(java.util.Map) DelegatingJournaled(alluxio.master.journal.DelegatingJournaled) MountPOptions(alluxio.grpc.MountPOptions) NoSuchElementException(java.util.NoSuchElementException) Nullable(javax.annotation.Nullable) Journaled(alluxio.master.journal.Journaled) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) IdUtils(alluxio.util.IdUtils) ExceptionMessage(alluxio.exception.ExceptionMessage) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Throwables(com.google.common.base.Throwables) ThreadSafe(javax.annotation.concurrent.ThreadSafe) CheckpointName(alluxio.master.journal.checkpoint.CheckpointName) GuardedBy(javax.annotation.concurrent.GuardedBy) NotFoundException(alluxio.exception.status.NotFoundException) LockResource(alluxio.resource.LockResource) Collectors(java.util.stream.Collectors) AccessControlException(alluxio.exception.AccessControlException) File(alluxio.proto.journal.File) StringPairEntry(alluxio.proto.journal.File.StringPairEntry) List(java.util.List) Lock(java.util.concurrent.locks.Lock) UnderFileSystem(alluxio.underfs.UnderFileSystem) Journal(alluxio.proto.journal.Journal) UfsManager(alluxio.underfs.UfsManager) Collections(java.util.Collections) JournalContext(alluxio.master.journal.JournalContext) UnavailableException(alluxio.exception.status.UnavailableException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 2 with Journal

use of alluxio.proto.journal.Journal in project alluxio by Alluxio.

the class UfsJournalReader method advanceEntry.

private void advanceEntry() throws IOException {
    while (true) {
        Journal.JournalEntry entry;
        try {
            entry = readInternal();
        } catch (IOException e) {
            throw new IOException(String.format("Failed to read from journal: %s error: %s", mJournal.getLocation(), e.getMessage()), e);
        }
        if (entry == null) {
            return;
        }
        if (entry.getSequenceNumber() == mNextSequenceNumber) {
            mNextSequenceNumber++;
            mNextEntry = entry;
            return;
        } else if (entry.getSequenceNumber() < mNextSequenceNumber) {
            // This can happen in the following two scenarios:
            // 1. The primary master failed when renaming the current log to completed log which might
            // result in duplicate logs.
            // 2. The first completed log after the checkpoint's last sequence number might contains
            // some duplicate entries with the checkpoint.
            LOG.debug("Skipping duplicate log entry {} (next sequence number: {}).", entry, mNextSequenceNumber);
        } else {
            throw new IllegalStateException(ExceptionMessage.JOURNAL_ENTRY_MISSING.getMessage(mNextSequenceNumber, entry.getSequenceNumber()));
        }
    }
}
Also used : Journal(alluxio.proto.journal.Journal) IOException(java.io.IOException) JournalEntry(alluxio.proto.journal.Journal.JournalEntry)

Example 3 with Journal

use of alluxio.proto.journal.Journal 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 4 with Journal

use of alluxio.proto.journal.Journal 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 5 with Journal

use of alluxio.proto.journal.Journal 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)

Aggregations

Journal (alluxio.proto.journal.Journal)15 AlluxioURI (alluxio.AlluxioURI)7 JournalContext (alluxio.master.journal.JournalContext)7 Test (org.junit.Test)7 NoopJournalContext (alluxio.master.journal.NoopJournalContext)6 LockedInodePath (alluxio.master.file.meta.LockedInodePath)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 NoopMaster (alluxio.master.NoopMaster)3 MountInfo (alluxio.master.file.meta.options.MountInfo)3 HashMap (java.util.HashMap)3 PropertyKey (alluxio.conf.PropertyKey)2 ServerConfiguration (alluxio.conf.ServerConfiguration)2 ExceptionMessage (alluxio.exception.ExceptionMessage)2 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 NotFoundException (alluxio.exception.status.NotFoundException)2 JournalReader (alluxio.master.journal.JournalReader)2 File (alluxio.proto.journal.File)2 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)2