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());
}
}
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()));
}
}
}
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());
}
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());
}
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());
}
Aggregations