use of alluxio.master.file.options.LoadMetadataOptions in project alluxio by Alluxio.
the class FileSystemMaster method loadMetadataAndJournal.
/**
* Loads metadata for the object identified by the given path from UFS into Alluxio.
* <p>
* Writes to the journal.
*
* @param inodePath the path for which metadata should be loaded
* @param options the load metadata options
* @param journalContext the journal context
* @throws InvalidPathException if invalid path is encountered
* @throws FileDoesNotExistException if there is no UFS path
* @throws BlockInfoException if an invalid block size is encountered
* @throws FileAlreadyCompletedException if the file is already completed
* @throws InvalidFileSizeException if invalid file size is encountered
* @throws AccessControlException if permission checking fails
* @throws IOException if an I/O error occurs
*/
private void loadMetadataAndJournal(LockedInodePath inodePath, LoadMetadataOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, BlockInfoException, FileAlreadyCompletedException, InvalidFileSizeException, AccessControlException, IOException {
AlluxioURI path = inodePath.getUri();
MountTable.Resolution resolution = mMountTable.resolve(path);
AlluxioURI ufsUri = resolution.getUri();
UnderFileSystem ufs = resolution.getUfs();
try {
if (options.getUnderFileStatus() == null && !ufs.exists(ufsUri.toString())) {
// uri does not exist in ufs
InodeDirectory inode = (InodeDirectory) inodePath.getInode();
inode.setDirectChildrenLoaded(true);
}
boolean isFile;
if (options.getUnderFileStatus() != null) {
isFile = options.getUnderFileStatus().isFile();
} else {
isFile = ufs.isFile(ufsUri.toString());
}
if (isFile) {
loadFileMetadataAndJournal(inodePath, resolution, options, journalContext);
} else {
loadDirectoryMetadataAndJournal(inodePath, options, journalContext);
InodeDirectory inode = (InodeDirectory) inodePath.getInode();
if (options.isLoadDirectChildren()) {
UnderFileStatus[] files = ufs.listStatus(ufsUri.toString());
for (UnderFileStatus file : files) {
if (PathUtils.isTemporaryFileName(file.getName()) || inode.getChild(file.getName()) != null) {
continue;
}
TempInodePathForChild tempInodePath = new TempInodePathForChild(inodePath, file.getName());
LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setLoadDirectChildren(false).setCreateAncestors(false).setUnderFileStatus(file);
loadMetadataAndJournal(tempInodePath, loadMetadataOptions, journalContext);
}
inode.setDirectChildrenLoaded(true);
}
}
} catch (IOException e) {
LOG.error(ExceptionUtils.getStackTrace(e));
throw e;
}
}
use of alluxio.master.file.options.LoadMetadataOptions 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;
}
}
Aggregations