use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method listStatusInternal.
/**
* Lists the status of the path in {@link LockedInodePath}, possibly recursively depending on the
* descendantType. The result is returned via a list specified by statusList, in postorder
* traversal order.
*
* @param context call context
* @param rpcContext the context for the RPC call
* @param currInodePath the inode path to find the status
* @param auditContext the audit context to return any access exceptions
* @param descendantType if the currInodePath is a directory, how many levels of its descendant
* should be returned
* @param resultStream the stream to receive individual results
* @param depth internal use field for tracking depth relative to root item
*/
private void listStatusInternal(ListStatusContext context, RpcContext rpcContext, LockedInodePath currInodePath, AuditContext auditContext, DescendantType descendantType, ResultStream<FileInfo> resultStream, int depth, Counter counter) throws FileDoesNotExistException, UnavailableException, AccessControlException, InvalidPathException {
rpcContext.throwIfCancelled();
Inode inode = currInodePath.getInode();
if (inode.isDirectory() && descendantType != DescendantType.NONE) {
try {
// TODO(david): Return the error message when we do not have permission
mPermissionChecker.checkPermission(Mode.Bits.EXECUTE, currInodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
if (descendantType == DescendantType.ALL) {
return;
} else {
throw e;
}
}
mAccessTimeUpdater.updateAccessTime(rpcContext.getJournalContext(), inode, CommonUtils.getCurrentMs());
DescendantType nextDescendantType = (descendantType == DescendantType.ALL) ? DescendantType.ALL : DescendantType.NONE;
// This is to generate a parsed child path components to be passed to lockChildPath
String[] childComponentsHint = null;
for (Inode child : mInodeStore.getChildren(inode.asDirectory())) {
if (childComponentsHint == null) {
String[] parentComponents = PathUtils.getPathComponents(currInodePath.getUri().getPath());
childComponentsHint = new String[parentComponents.length + 1];
System.arraycopy(parentComponents, 0, childComponentsHint, 0, parentComponents.length);
}
// TODO(david): Make extending InodePath more efficient
childComponentsHint[childComponentsHint.length - 1] = child.getName();
try (LockedInodePath childInodePath = currInodePath.lockChild(child, LockPattern.READ, childComponentsHint)) {
listStatusInternal(context, rpcContext, childInodePath, auditContext, nextDescendantType, resultStream, depth + 1, counter);
} catch (InvalidPathException | FileDoesNotExistException e) {
LOG.debug("Path \"{}\" is invalid, has been ignored.", PathUtils.concatPath("/", childComponentsHint));
}
}
}
// Listing a directory should not emit item for the directory itself.
if (depth != 0 || inode.isFile()) {
resultStream.submit(getFileInfoInternal(currInodePath, counter));
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method setAclRecursive.
private void setAclRecursive(RpcContext rpcContext, SetAclAction action, LockedInodePath inodePath, List<AclEntry> entries, boolean replay, long opTimeMs, SetAclContext context) throws IOException, FileDoesNotExistException {
Preconditions.checkState(inodePath.getLockPattern().isWrite());
setAclSingleInode(rpcContext, action, inodePath, entries, replay, opTimeMs);
if (context.getOptions().getRecursive()) {
try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
for (LockedInodePath childPath : descendants) {
rpcContext.throwIfCancelled();
setAclSingleInode(rpcContext, action, childPath, entries, replay, opTimeMs);
}
}
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method completeFile.
@Override
public void completeFile(AlluxioURI path, CompleteFileContext context) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, InvalidFileSizeException, FileAlreadyCompletedException, AccessControlException, UnavailableException {
if (isOperationComplete(context)) {
Metrics.COMPLETED_OPERATION_RETRIED_COUNT.inc();
LOG.warn("A completed \"completeFile\" operation has been retried. {}", context);
return;
}
Metrics.COMPLETE_FILE_OPS.inc();
// No need to syncMetadata before complete.
try (RpcContext rpcContext = createRpcContext(context);
LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, LockPattern.WRITE_INODE);
FileSystemMasterAuditContext auditContext = createAuditContext("completeFile", path, null, inodePath.getInodeOrNull())) {
try {
mPermissionChecker.checkPermission(Mode.Bits.WRITE, inodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
// Even readonly mount points should be able to complete a file, for UFS reads in CACHE mode.
completeFileInternal(rpcContext, inodePath, context);
// Schedule async persistence if requested.
if (context.getOptions().hasAsyncPersistOptions()) {
scheduleAsyncPersistenceInternal(inodePath, ScheduleAsyncPersistenceContext.create(context.getOptions().getAsyncPersistOptionsBuilder()), rpcContext);
}
auditContext.setSucceeded(true);
cacheOperation(context);
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class DefaultFileSystemMaster method setAcl.
@Override
public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclContext context) throws FileDoesNotExistException, AccessControlException, InvalidPathException, IOException {
Metrics.SET_ACL_OPS.inc();
try (RpcContext rpcContext = createRpcContext(context);
FileSystemMasterAuditContext auditContext = createAuditContext("setAcl", path, null, null)) {
syncMetadata(rpcContext, path, context.getOptions().getCommonOptions(), context.getOptions().getRecursive() ? DescendantType.ALL : DescendantType.NONE, auditContext, LockedInodePath::getInodeOrNull, (inodePath, permChecker) -> permChecker.checkSetAttributePermission(inodePath, false, true, false), false);
LockingScheme lockingScheme = createLockingScheme(path, context.getOptions().getCommonOptions(), LockPattern.WRITE_INODE);
try (LockedInodePath inodePath = mInodeTree.lockInodePath(lockingScheme)) {
mPermissionChecker.checkSetAttributePermission(inodePath, false, true, false);
if (context.getOptions().getRecursive()) {
try (LockedInodePathList descendants = mInodeTree.getDescendants(inodePath)) {
for (LockedInodePath child : descendants) {
mPermissionChecker.checkSetAttributePermission(child, false, true, false);
}
} catch (AccessControlException e) {
auditContext.setAllowed(false);
throw e;
}
}
if (!inodePath.fullPathExists()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
}
setAclInternal(rpcContext, action, inodePath, entries, context);
auditContext.setSucceeded(true);
}
}
}
use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.
the class InodeSyncStream method loadDirectoryMetadata.
/**
* Loads metadata for the directory identified by the given path from UFS into Alluxio. This does
* not actually require looking at the UFS path.
* It is a no-op if the directory exists.
*
* This method doesn't require any specific type of locking on inodePath. If the path needs to be
* loaded, we will acquire a write-edge lock if necessary.
*
* @param rpcContext the rpc context
* @param inodePath the path for which metadata should be loaded
* @param context the load metadata context
*/
static void loadDirectoryMetadata(RpcContext rpcContext, LockedInodePath inodePath, LoadMetadataContext context, MountTable mountTable, DefaultFileSystemMaster fsMaster) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
if (inodePath.fullPathExists()) {
return;
}
CreateDirectoryContext createDirectoryContext = CreateDirectoryContext.defaults();
createDirectoryContext.getOptions().setRecursive(context.getOptions().getCreateAncestors()).setAllowExists(false).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction()));
createDirectoryContext.setMountPoint(mountTable.isMountPoint(inodePath.getUri()));
createDirectoryContext.setMetadataLoad(true);
createDirectoryContext.setWriteType(WriteType.THROUGH);
MountTable.Resolution resolution = mountTable.resolve(inodePath.getUri());
AlluxioURI ufsUri = resolution.getUri();
AccessControlList acl = null;
DefaultAccessControlList defaultAcl = null;
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
if (context.getUfsStatus() == null) {
context.setUfsStatus(ufs.getExistingDirectoryStatus(ufsUri.toString()));
}
Pair<AccessControlList, DefaultAccessControlList> aclPair = ufs.getAclPair(ufsUri.toString());
if (aclPair != null) {
acl = aclPair.getFirst();
defaultAcl = aclPair.getSecond();
}
}
String ufsOwner = context.getUfsStatus().getOwner();
String ufsGroup = context.getUfsStatus().getGroup();
short ufsMode = context.getUfsStatus().getMode();
Long lastModifiedTime = context.getUfsStatus().getLastModifiedTime();
Mode mode = new Mode(ufsMode);
if (resolution.getShared()) {
mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
}
createDirectoryContext.getOptions().setMode(mode.toProto());
createDirectoryContext.setOwner(ufsOwner).setGroup(ufsGroup).setUfsStatus(context.getUfsStatus());
createDirectoryContext.setXAttr(context.getUfsStatus().getXAttr());
if (acl != null) {
createDirectoryContext.setAcl(acl.getEntries());
}
if (defaultAcl != null) {
createDirectoryContext.setDefaultAcl(defaultAcl.getEntries());
}
if (lastModifiedTime != null) {
createDirectoryContext.setOperationTimeMs(lastModifiedTime);
}
try (LockedInodePath writeLockedPath = inodePath.lockFinalEdgeWrite()) {
fsMaster.createDirectoryInternal(rpcContext, writeLockedPath, createDirectoryContext);
} catch (FileAlreadyExistsException e) {
// This may occur if a thread created or loaded the directory before we got the write lock.
// The directory already exists, so nothing needs to be loaded.
}
// Re-traverse the path to pick up any newly created inodes.
inodePath.traverse();
}
Aggregations