use of alluxio.grpc.LoadDescendantPType in project alluxio by Alluxio.
the class InodeSyncStream method loadMetadata.
/**
* This method creates inodes containing the metadata from the UFS. The {@link UfsStatus} object
* must be set in the {@link LoadMetadataContext} in order to successfully create the inodes.
*/
private void loadMetadata(LockedInodePath inodePath, LoadMetadataContext context) throws AccessControlException, BlockInfoException, FileAlreadyCompletedException, FileDoesNotExistException, InvalidFileSizeException, InvalidPathException, IOException {
AlluxioURI path = inodePath.getUri();
MountTable.Resolution resolution = mMountTable.resolve(path);
int failedSync = 0;
try {
if (context.getUfsStatus() == null) {
// uri does not exist in ufs
Inode inode = inodePath.getInode();
if (inode.isFile()) {
throw new IllegalArgumentException(String.format("load metadata cannot be called on a file if no ufs " + "status is present in the context. %s", inodePath.getUri()));
}
mInodeTree.setDirectChildrenLoaded(mRpcContext, inode.asDirectory());
return;
}
if (context.getUfsStatus().isFile()) {
loadFileMetadataInternal(mRpcContext, inodePath, resolution, context, mFsMaster);
} else {
loadDirectoryMetadata(mRpcContext, inodePath, context, mMountTable, mFsMaster);
// now load all children if required
LoadDescendantPType type = context.getOptions().getLoadDescendantType();
if (type != LoadDescendantPType.NONE) {
Collection<UfsStatus> children = mStatusCache.fetchChildrenIfAbsent(mRpcContext, inodePath.getUri(), mMountTable);
if (children == null) {
LOG.debug("fetching children for {} returned null", inodePath.getUri());
return;
}
for (UfsStatus childStatus : children) {
if (PathUtils.isTemporaryFileName(childStatus.getName())) {
continue;
}
AlluxioURI childURI = new AlluxioURI(PathUtils.concatPath(inodePath.getUri(), childStatus.getName()));
if (mInodeTree.inodePathExists(childURI) && (childStatus.isFile() || context.getOptions().getLoadDescendantType() != LoadDescendantPType.ALL)) {
// loading all descendants.
continue;
}
LoadMetadataContext loadMetadataContext = LoadMetadataContext.mergeFrom(LoadMetadataPOptions.newBuilder().setLoadDescendantType(LoadDescendantPType.NONE).setCommonOptions(NO_TTL_OPTION).setCreateAncestors(false)).setUfsStatus(childStatus);
try (LockedInodePath descendant = inodePath.lockDescendant(inodePath.getUri().joinUnsafe(childStatus.getName()), LockPattern.READ)) {
loadMetadata(descendant, loadMetadataContext);
} catch (FileNotFoundException e) {
LOG.debug("Failed to loadMetadata because file is not in ufs:" + " inodePath={}, options={}.", childURI, loadMetadataContext, e);
} catch (BlockInfoException | FileAlreadyCompletedException | FileDoesNotExistException | InvalidFileSizeException | IOException e) {
LOG.debug("Failed to loadMetadata because the ufs file or directory" + " is {}, options={}.", childStatus, loadMetadataContext, e);
failedSync++;
}
}
mInodeTree.setDirectChildrenLoaded(mRpcContext, inodePath.getInode().asDirectory());
}
}
} catch (IOException | InterruptedException e) {
LOG.debug("Failed to loadMetadata: inodePath={}, context={}.", inodePath.getUri(), context, e);
throw new IOException(e);
}
if (failedSync > 0) {
throw new IOException(String.format("Failed to load metadata of %s files or directories " + "under %s", failedSync, path));
}
}
Aggregations