use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method checkConsistencyRecursive.
private void checkConsistencyRecursive(LockedInodePath inodePath, List<AlluxioURI> inconsistentUris, boolean assertInconsistent, boolean metadataSynced) throws IOException, FileDoesNotExistException {
Inode inode = inodePath.getInode();
try {
if (assertInconsistent || !checkConsistencyInternal(inodePath)) {
inconsistentUris.add(inodePath.getUri());
// If a dir in Alluxio is inconsistent with underlying storage,
// we can assert the children is inconsistent.
// If a file is inconsistent, please ignore this parameter cause it has no child node.
assertInconsistent = true;
}
if (inode.isDirectory()) {
InodeDirectory inodeDir = inode.asDirectory();
Iterable<? extends Inode> children = mInodeStore.getChildren(inodeDir);
for (Inode child : children) {
try (LockedInodePath childPath = inodePath.lockChild(child, LockPattern.READ)) {
checkConsistencyRecursive(childPath, inconsistentUris, assertInconsistent, metadataSynced);
}
}
// if the metadata has already been synced, then we could skip it.
if (metadataSynced) {
return;
}
MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
UfsStatus[] statuses;
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
String ufsPath = resolution.getUri().getPath();
statuses = ufs.listStatus(ufsPath);
}
if (statuses != null) {
HashSet<String> alluxioFileNames = Streams.stream(children).map(Inode::getName).collect(Collectors.toCollection(HashSet::new));
Arrays.stream(statuses).forEach(status -> {
if (!alluxioFileNames.contains(status.getName())) {
inconsistentUris.add(inodePath.getUri().join(status.getName()));
}
});
}
}
} catch (InvalidPathException e) {
LOG.debug("Path \"{}\" is invalid, has been ignored.", PathUtils.concatPath(inodePath.getUri().getPath()));
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method setAttributeInternal.
/**
* Sets the file attribute.
*
* @param rpcContext the rpc context
* @param inodePath the {@link LockedInodePath} to set attribute for
* @param context attributes to be set, see {@link SetAttributePOptions}
*/
private void setAttributeInternal(RpcContext rpcContext, LockedInodePath inodePath, SetAttributeContext context) throws InvalidPathException, FileDoesNotExistException, AccessControlException, IOException {
Inode targetInode = inodePath.getInode();
long opTimeMs = System.currentTimeMillis();
if (context.getOptions().getRecursive() && targetInode.isDirectory()) {
try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
for (LockedInodePath childPath : descendants) {
rpcContext.throwIfCancelled();
setAttributeSingleFile(rpcContext, childPath, true, opTimeMs, context);
}
}
}
setAttributeSingleFile(rpcContext, inodePath, true, opTimeMs, context);
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getInAlluxioFiles.
@Override
public List<AlluxioURI> getInAlluxioFiles() throws UnavailableException {
List<AlluxioURI> files = new ArrayList<>();
LockedInodePath rootPath;
try {
rootPath = mInodeTree.lockFullInodePath(new AlluxioURI(AlluxioURI.SEPARATOR), LockPattern.READ);
} catch (FileDoesNotExistException | InvalidPathException e) {
// Root should always exist.
throw new RuntimeException(e);
}
try (LockedInodePath inodePath = rootPath) {
getInAlluxioFilesInternal(inodePath, files);
}
return files;
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getFileInfo.
@Override
public FileInfo getFileInfo(AlluxioURI path, GetStatusContext context) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
Metrics.GET_FILE_INFO_OPS.inc();
boolean ufsAccessed = false;
long opTimeMs = System.currentTimeMillis();
try (RpcContext rpcContext = createRpcContext(context);
FileSystemMasterAuditContext auditContext = createAuditContext("getFileInfo", path, null, null)) {
if (!syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), DescendantType.ONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkPermission(Mode.Bits.READ, inodePath), true).equals(NOT_NEEDED)) {
// If synced, do not load metadata.
context.getOptions().setLoadMetadataType(LoadMetadataPType.NEVER);
ufsAccessed = true;
}
LoadMetadataContext lmCtx = LoadMetadataContext.mergeFrom(LoadMetadataPOptions.newBuilder().setCreateAncestors(true).setLoadType(context.getOptions().getLoadMetadataType()).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction())));
/*
See the comments in #getFileIdInternal for an explanation on why the loop here is required.
*/
boolean run = true;
boolean loadMetadata = false;
FileInfo ret = null;
while (run) {
run = false;
if (loadMetadata) {
checkLoadMetadataOptions(context.getOptions().getLoadMetadataType(), path);
loadMetadataIfNotExist(rpcContext, path, lmCtx, true);
ufsAccessed = true;
}
LockingScheme lockingScheme = new LockingScheme(path, LockPattern.READ, false);
try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
auditContext.setSrcInode(inodePath.getInodeOrNull());
try {
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
if (!loadMetadata && shouldLoadMetadataIfNotExists(inodePath, lmCtx)) {
loadMetadata = true;
run = true;
continue;
}
ensureFullPathAndUpdateCache(inodePath);
FileInfo fileInfo = getFileInfoInternal(inodePath);
if (!fileInfo.isFolder() && (!fileInfo.isCompleted())) {
LOG.debug("File {} is not yet completed. getStatus will see incomplete metadata.", fileInfo.getPath());
}
if (ufsAccessed) {
MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
Metrics.getUfsOpsSavedCounter(resolution.getUfsMountPointUri(), Metrics.UFSOps.GET_FILE_INFO).dec();
}
Mode.Bits accessMode = Mode.Bits.fromProto(context.getOptions().getAccessMode());
if (context.getOptions().getUpdateTimestamps() && context.getOptions().hasAccessMode() && (accessMode.imply(Mode.Bits.READ) || accessMode.imply(Mode.Bits.WRITE))) {
mAccessTimeUpdater.updateAccessTime(rpcContext.getJournalContext(), inodePath.getInode(), opTimeMs);
}
auditContext.setSrcInode(inodePath.getInode()).setSucceeded(true);
ret = fileInfo;
}
}
return ret;
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method getFileBlockInfoList.
@Override
public List<FileBlockInfo> getFileBlockInfoList(AlluxioURI path) throws FileDoesNotExistException, InvalidPathException, AccessControlException, UnavailableException {
Metrics.GET_FILE_BLOCK_INFO_OPS.inc();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.READ);
FileSystemMasterAuditContext auditContext = createAuditContext("getFileBlockInfoList", path, null, inodePath.getInodeOrNull())) {
try {
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
List<FileBlockInfo> ret = getFileBlockInfoListInternal(inodePath);
Metrics.FILE_BLOCK_INFOS_GOT.inc();
auditContext.setSucceeded(true);
return ret;
}
}
Aggregations