use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method unmount.
/**
* Unmounts a UFS path previously mounted onto an Alluxio path.
* <p>
* This operation requires users to have {@link Mode.Bits#WRITE} permission on the parent
* of the Alluxio path.
*
* @param alluxioPath the Alluxio path to unmount, must be a mount point
* @throws FileDoesNotExistException if the path to be mounted does not exist
* @throws InvalidPathException if an invalid path is encountered
* @throws IOException if an I/O error occurs
* @throws AccessControlException if the permission check fails
*/
public void unmount(AlluxioURI alluxioPath) throws FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
Metrics.UNMOUNT_OPS.inc();
// Unmount should lock the parent to remove the child inode.
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockFullInodePath(alluxioPath, InodeTree.LockMode.WRITE_PARENT)) {
mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
unmountAndJournal(inodePath, journalContext);
Metrics.PATHS_UNMOUNTED.inc();
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMaster method listStatus.
/**
* Returns a list of {@link FileInfo} for a given path. If the given path is a file, the list only
* contains a single object. If it is a directory, the resulting list contains all direct children
* of the directory.
* <p>
* This operation requires users to have
* {@link Mode.Bits#READ} permission on the path, and also
* {@link Mode.Bits#EXECUTE} permission on the path if it is a directory.
*
* @param path the path to get the {@link FileInfo} list for
* @param listStatusOptions the {@link alluxio.master.file.options.ListStatusOptions}
* @return the list of {@link FileInfo}s
* @throws AccessControlException if permission checking fails
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the path is invalid
*/
public List<FileInfo> listStatus(AlluxioURI path, ListStatusOptions listStatusOptions) throws AccessControlException, FileDoesNotExistException, InvalidPathException {
Metrics.GET_FILE_INFO_OPS.inc();
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
// This is WRITE locked, since loading metadata is possible.
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(listStatusOptions.getLoadMetadataType() != LoadMetadataType.Never);
Inode<?> inode;
if (inodePath.fullPathExists()) {
inode = inodePath.getInode();
if (inode.isDirectory() && listStatusOptions.getLoadMetadataType() != LoadMetadataType.Always && ((InodeDirectory) inode).isDirectChildrenLoaded()) {
loadMetadataOptions.setLoadDirectChildren(false);
}
}
loadMetadataIfNotExistAndJournal(inodePath, loadMetadataOptions, journalContext);
mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
inode = inodePath.getInode();
List<FileInfo> ret = new ArrayList<>();
if (inode.isDirectory()) {
TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
mPermissionChecker.checkPermission(Mode.Bits.EXECUTE, inodePath);
for (Inode<?> child : ((InodeDirectory) inode).getChildren()) {
child.lockReadAndCheckParent(inode);
try {
// the path to child for getPath should already be locked.
tempInodePath.setDescendant(child, mInodeTree.getPath(child));
ret.add(getFileInfoInternal(tempInodePath));
} finally {
child.unlockRead();
}
}
} else {
ret.add(getFileInfoInternal(inodePath));
}
Metrics.FILE_INFOS_GOT.inc();
return ret;
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method lastModificationTimeCreateFile.
@Test
public void lastModificationTimeCreateFile() throws Exception {
mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults());
long opTimeMs = TEST_TIME_MS;
CreateFileOptions options = CreateFileOptions.defaults().setOperationTimeMs(opTimeMs);
try (LockedInodePath inodePath = mInodeTree.lockInodePath(new AlluxioURI("/testFolder/testFile"), InodeTree.LockMode.WRITE)) {
mFsMaster.createFileInternal(inodePath, options);
}
FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder")));
Assert.assertEquals(opTimeMs, folderInfo.getLastModificationTimeMs());
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class PermissionCheckerTest method createAndSetPermission.
/**
* Helper function to create a path and set the permission to what specified in option.
*
* @param path path to construct the {@link AlluxioURI} from
* @param context method context for creating a file
*/
private static void createAndSetPermission(String path, CreateFileContext context) throws Exception {
try (LockedInodePath inodePath = sTree.lockInodePath(new AlluxioURI(path), LockPattern.WRITE_EDGE)) {
List<Inode> result = sTree.createPath(RpcContext.NOOP, inodePath, context);
MutableInode<?> inode = sInodeStore.getMutable(result.get(result.size() - 1).getId()).get();
inode.setOwner(context.getOwner()).setGroup(context.getGroup()).setMode(context.getMode().toShort());
sInodeStore.writeInode(inode);
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class ReplicationChecker method check.
private Set<Long> check(Set<Long> inodes, ReplicationHandler handler, Mode mode) throws InterruptedException {
Set<Long> processedFileIds = new HashSet<>();
for (long inodeId : inodes) {
if (mActiveJobToInodeID.size() >= mMaxActiveJobs) {
return processedFileIds;
}
if (mActiveJobToInodeID.containsValue(inodeId)) {
continue;
}
Set<Triple<AlluxioURI, Long, Integer>> requests = new HashSet<>();
// Throw if interrupted.
if (Thread.interrupted()) {
throw new InterruptedException("ReplicationChecker interrupted.");
}
// locking the entire path but just the inode file since this access is read-only.
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 processedFileIds;
}
int currentReplicas = (blockInfo == null) ? 0 : blockInfo.getLocations().size();
switch(mode) {
case EVICT:
int maxReplicas = file.getReplicationMax();
if (file.getPersistenceState() == PersistenceState.TO_BE_PERSISTED && file.getReplicationDurable() > maxReplicas) {
maxReplicas = file.getReplicationDurable();
}
if (currentReplicas > maxReplicas) {
requests.add(new ImmutableTriple<>(inodePath.getUri(), blockId, currentReplicas - maxReplicas));
}
break;
case REPLICATE:
int minReplicas = file.getReplicationMin();
if (file.getPersistenceState() == PersistenceState.TO_BE_PERSISTED && file.getReplicationDurable() > minReplicas) {
minReplicas = file.getReplicationDurable();
}
if (currentReplicas < minReplicas) {
// if this file is not persisted and block master thinks it is lost, no effort made
if (!file.isPersisted() && mBlockMaster.isBlockLost(blockId)) {
continue;
}
requests.add(new ImmutableTriple<>(inodePath.getUri(), blockId, minReplicas - currentReplicas));
}
break;
default:
LOG.warn("Unexpected replication mode {}.", mode);
}
}
} catch (FileDoesNotExistException e) {
LOG.warn("Failed to check replication level for inode id {} : {}", inodeId, e.toString());
}
for (Triple<AlluxioURI, Long, Integer> entry : requests) {
AlluxioURI uri = entry.getLeft();
long blockId = entry.getMiddle();
int numReplicas = entry.getRight();
try {
long jobId;
switch(mode) {
case EVICT:
jobId = handler.evict(uri, blockId, numReplicas);
break;
case REPLICATE:
jobId = handler.replicate(uri, blockId, numReplicas);
break;
default:
throw new RuntimeException(String.format("Unexpected replication mode {}.", mode));
}
processedFileIds.add(inodeId);
mActiveJobToInodeID.put(jobId, inodeId);
} catch (JobDoesNotExistException | ResourceExhaustedException e) {
LOG.warn("The job service is busy, will retry later. {}", e.toString());
return processedFileIds;
} catch (UnavailableException e) {
LOG.warn("Unable to complete the replication check: {}, will retry later.", e.toString());
return processedFileIds;
} catch (Exception e) {
SAMPLING_LOG.warn("Unexpected exception encountered when starting a {} job (uri={}," + " block ID={}, num replicas={}) : {}", mode, uri, blockId, numReplicas, e.toString());
LOG.debug("Job service unexpected exception: ", e);
}
}
}
return processedFileIds;
}
Aggregations