use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class ReplicationChecker method checkMisreplicated.
private void checkMisreplicated(Set<Long> inodes, ReplicationHandler handler) throws InterruptedException {
for (long inodeId : inodes) {
if (mActiveJobToInodeID.size() >= mMaxActiveJobs) {
return;
}
if (mActiveJobToInodeID.containsValue(inodeId)) {
continue;
}
// Throw if interrupted.
if (Thread.interrupted()) {
throw new InterruptedException("ReplicationChecker interrupted.");
}
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(inodeId, LockPattern.READ)) {
InodeFile file = inodePath.getInodeFile();
for (long blockId : file.getBlockIds()) {
BlockInfo blockInfo = null;
try {
blockInfo = mBlockMaster.getBlockInfo(blockId);
} catch (BlockInfoException e) {
// Cannot find this block in Alluxio from BlockMaster, possibly persisted in UFS
} catch (UnavailableException e) {
// The block master is not available, wait for the next heartbeat
LOG.warn("The block master is not available: {}", e.toString());
return;
}
if (blockInfo == null) {
// no block info available, we simply log and return;
LOG.warn("Block info is null");
return;
}
for (Map.Entry<String, String> entry : findMisplacedBlock(file, blockInfo).entrySet()) {
try {
final long jobId = handler.migrate(inodePath.getUri(), blockId, entry.getKey(), entry.getValue());
mActiveJobToInodeID.put(jobId, inodeId);
} catch (Exception e) {
LOG.warn("Unexpected exception encountered when starting a migration job (uri={}," + " block ID={}, workerHost= {}) : {}", inodePath.getUri(), blockId, entry.getKey(), e.toString());
LOG.debug("Exception: ", e);
}
}
}
} catch (FileDoesNotExistException e) {
LOG.warn("Failed to check replication level for inode id {} : {}", inodeId, e.toString());
}
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class AccessTimeUpdaterTest method updateAccessTimePrecision.
@Test
public void updateAccessTimePrecision() throws Exception {
mAccessTimeUpdater = new AccessTimeUpdater(mFileSystemMaster, mInodeTree, mContext.getJournalSystem(), 0, Constants.HOUR_MS, 0);
mAccessTimeUpdater.start();
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 not updated
assertNotEquals(accessTime, mInodeStore.get(inodeId).get().getLastAccessTimeMs());
// verify journal entry is not logged yet
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());
// / 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(newAccessTime, captor.getValue().getUpdateInode().getLastAccessTimeMs());
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method checkAccess.
@Override
public void checkAccess(AlluxioURI path, CheckAccessContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
try (RpcContext rpcContext = createRpcContext(context);
FileSystemMasterAuditContext auditContext = createAuditContext("checkAccess", path, null, null)) {
Mode.Bits bits = Mode.Bits.fromProto(context.getOptions().getBits());
syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.NONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(bits, inodePath), false);
LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.READ);
try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
mPermissionChecker.checkPermission(bits, inodePath);
if (!inodePath.fullPathExists()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
}
auditContext.setSucceeded(true);
}
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getNewBlockIdForFile.
@Override
public long getNewBlockIdForFile(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnavailableException {
Metrics.GET_NEW_BLOCK_OPS.inc();
try (RpcContext rpcContext = createRpcContext();
LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.WRITE_INODE);
FileSystemMasterAuditContext auditContext = createAuditContext("getNewBlockIdForFile", path, null, inodePath.getInodeOrNull())) {
try {
mPermissionChecker.checkPermission(Mode.Bits.WRITE, inodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
Metrics.NEW_BLOCKS_GOT.inc();
long blockId = mInodeTree.newBlock(rpcContext, NewBlockEntry.newBuilder().setId(inodePath.getInode().getId()).build());
auditContext.setSucceeded(true);
return blockId;
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method free.
@Override
public void free(AlluxioURI path, FreeContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnexpectedAlluxioException, IOException {
Metrics.FREE_FILE_OPS.inc();
// No need to syncMetadata before free.
try (RpcContext rpcContext = createRpcContext(context);
LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.WRITE_INODE);
FileSystemMasterAuditContext auditContext = createAuditContext("free", path, null, inodePath.getInodeOrNull())) {
try {
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
freeInternal(rpcContext, inodePath, context);
auditContext.setSucceeded(true);
}
}
Aggregations