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