use of alluxio.master.file.meta.Inode in project alluxio by Alluxio.
the class FileSystemMaster method setAttributeAndJournal.
/**
* Sets the file attribute.
* <p>
* Writes to the journal.
*
* @param inodePath the {@link LockedInodePath} to set attribute for
* @param rootRequired indicates whether it requires to be the superuser
* @param ownerRequired indicates whether it requires to be the owner of this path
* @param options attributes to be set, see {@link SetAttributeOptions}
* @param journalContext the journal context
* @throws InvalidPathException if the given path is invalid
* @throws FileDoesNotExistException if the file does not exist
* @throws AccessControlException if permission checking fails
*/
private void setAttributeAndJournal(LockedInodePath inodePath, boolean rootRequired, boolean ownerRequired, SetAttributeOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, AccessControlException {
Inode<?> targetInode = inodePath.getInode();
long opTimeMs = System.currentTimeMillis();
if (options.isRecursive() && targetInode.isDirectory()) {
try (InodeLockList lockList = mInodeTree.lockDescendants(inodePath, InodeTree.LockMode.WRITE)) {
List<Inode<?>> inodeChildren = lockList.getInodes();
for (Inode<?> inode : inodeChildren) {
// the path to inode for getPath should already be locked.
try (LockedInodePath childPath = mInodeTree.lockFullInodePath(mInodeTree.getPath(inode), InodeTree.LockMode.READ)) {
// TODO(gpang): a better way to check permissions
mPermissionChecker.checkSetAttributePermission(childPath, rootRequired, ownerRequired);
}
}
TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
for (Inode<?> inode : inodeChildren) {
// the path to inode for getPath should already be locked.
tempInodePath.setDescendant(inode, mInodeTree.getPath(inode));
List<Inode<?>> persistedInodes = setAttributeInternal(tempInodePath, false, opTimeMs, options);
journalPersistedInodes(persistedInodes, journalContext);
journalSetAttribute(tempInodePath, opTimeMs, options, journalContext);
}
}
}
List<Inode<?>> persistedInodes = setAttributeInternal(inodePath, false, opTimeMs, options);
journalPersistedInodes(persistedInodes, journalContext);
journalSetAttribute(inodePath, opTimeMs, options, journalContext);
}
use of alluxio.master.file.meta.Inode in project alluxio by Alluxio.
the class FileSystemMaster method createFileInternal.
/**
* @param inodePath the path to be created
* @param options method options
* @return {@link InodeTree.CreatePathResult} with the path creation result
* @throws InvalidPathException if an invalid path is encountered
* @throws FileAlreadyExistsException if the file already exists
* @throws BlockInfoException if invalid block information is encountered
* @throws IOException if an I/O error occurs
* @throws FileDoesNotExistException if the parent of the path does not exist and the recursive
* option is false
*/
InodeTree.CreatePathResult createFileInternal(LockedInodePath inodePath, CreateFileOptions options) throws InvalidPathException, FileAlreadyExistsException, BlockInfoException, IOException, FileDoesNotExistException {
InodeTree.CreatePathResult createResult = mInodeTree.createPath(inodePath, options);
// If the create succeeded, the list of created inodes will not be empty.
List<Inode<?>> created = createResult.getCreated();
InodeFile inode = (InodeFile) created.get(created.size() - 1);
if (mWhitelist.inList(inodePath.getUri().toString())) {
inode.setCacheable(true);
}
mTtlBuckets.insert(inode);
Metrics.FILES_CREATED.inc();
Metrics.DIRECTORIES_CREATED.inc();
return createResult;
}
use of alluxio.master.file.meta.Inode in project alluxio by Alluxio.
the class FileSystemMaster method setAttributeInternal.
/**
* @param inodePath the {@link LockedInodePath} to use
* @param replayed whether the operation is a result of replaying the journal
* @param opTimeMs the operation time (in milliseconds)
* @param options the method options
* @return list of inodes which were marked as persisted
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the file path corresponding to the file id is invalid
* @throws AccessControlException if failed to set permission
*/
private List<Inode<?>> setAttributeInternal(LockedInodePath inodePath, boolean replayed, long opTimeMs, SetAttributeOptions options) throws FileDoesNotExistException, InvalidPathException, AccessControlException {
List<Inode<?>> persistedInodes = Collections.emptyList();
Inode<?> inode = inodePath.getInode();
if (options.getPinned() != null) {
mInodeTree.setPinned(inodePath, options.getPinned(), opTimeMs);
inode.setLastModificationTimeMs(opTimeMs);
}
if (options.getTtl() != null) {
long ttl = options.getTtl();
if (inode.getTtl() != ttl) {
mTtlBuckets.remove(inode);
inode.setTtl(ttl);
mTtlBuckets.insert(inode);
inode.setLastModificationTimeMs(opTimeMs);
inode.setTtlAction(options.getTtlAction());
}
}
if (options.getPersisted() != null) {
Preconditions.checkArgument(inode.isFile(), PreconditionMessage.PERSIST_ONLY_FOR_FILE);
Preconditions.checkArgument(((InodeFile) inode).isCompleted(), PreconditionMessage.FILE_TO_PERSIST_MUST_BE_COMPLETE);
InodeFile file = (InodeFile) inode;
// TODO(manugoyal) figure out valid behavior in the un-persist case
Preconditions.checkArgument(options.getPersisted(), PreconditionMessage.ERR_SET_STATE_UNPERSIST);
if (!file.isPersisted()) {
file.setPersistenceState(PersistenceState.PERSISTED);
persistedInodes = propagatePersistedInternal(inodePath, false);
file.setLastModificationTimeMs(opTimeMs);
Metrics.FILES_PERSISTED.inc();
}
}
boolean ownerGroupChanged = (options.getOwner() != null) || (options.getGroup() != null);
boolean modeChanged = (options.getMode() != Constants.INVALID_MODE);
// If the file is persisted in UFS, also update corresponding owner/group/permission.
if ((ownerGroupChanged || modeChanged) && !replayed && inode.isPersisted()) {
if ((inode instanceof InodeFile) && !((InodeFile) inode).isCompleted()) {
LOG.debug("Alluxio does not propagate chown/chgrp/chmod to UFS for incomplete files.");
} else {
MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
String ufsUri = resolution.getUri().toString();
if (UnderFileSystemUtils.isObjectStorage(ufsUri)) {
LOG.warn("setOwner/setMode is not supported to object storage UFS via Alluxio. " + "UFS: " + ufsUri + ". This has no effect on the underlying object.");
} else {
UnderFileSystem ufs = resolution.getUfs();
if (ownerGroupChanged) {
try {
String owner = options.getOwner() != null ? options.getOwner() : inode.getOwner();
String group = options.getGroup() != null ? options.getGroup() : inode.getGroup();
ufs.setOwner(ufsUri, owner, group);
} catch (IOException e) {
throw new AccessControlException("Could not setOwner for UFS file " + ufsUri + " . Aborting the setAttribute operation in Alluxio.", e);
}
}
if (modeChanged) {
try {
ufs.setMode(ufsUri, options.getMode());
} catch (IOException e) {
throw new AccessControlException("Could not setMode for UFS file " + ufsUri + " . Aborting the setAttribute operation in Alluxio.", e);
}
}
}
}
}
// Only commit the set permission to inode after the propagation to UFS succeeded.
if (options.getOwner() != null) {
inode.setOwner(options.getOwner());
}
if (options.getGroup() != null) {
inode.setGroup(options.getGroup());
}
if (modeChanged) {
inode.setMode(options.getMode());
}
return persistedInodes;
}
use of alluxio.master.file.meta.Inode in project alluxio by Alluxio.
the class PermissionChecker method checkInodeList.
/**
* This method provides basic permission checking logic on a list of inodes. The input includes
* user and its group, requested action and inode list (by traversing the path). Then user,
* group, and the requested action will be evaluated on each of the inodes. It will return if
* check passed, and throw exception if check failed.
*
* @param user who requests access permission
* @param groups in which user belongs to
* @param bits bits that capture the action {@link Mode.Bits} by user
* @param path the path to check permission on
* @param inodeList file info list of all the inodes retrieved by traversing the path
* @param checkIsOwner indicates whether to check the user is the owner of the path
* @throws AccessControlException if permission checking fails
*/
private void checkInodeList(String user, List<String> groups, Mode.Bits bits, String path, List<Inode<?>> inodeList, boolean checkIsOwner) throws AccessControlException {
int size = inodeList.size();
Preconditions.checkArgument(size > 0, PreconditionMessage.EMPTY_FILE_INFO_LIST_FOR_PERMISSION_CHECK);
// bypass checking permission for super user or super group of Alluxio file system.
if (isPrivilegedUser(user, groups)) {
return;
}
// traverses from root to the parent dir to all inodes included by this path are executable
for (int i = 0; i < size - 1; i++) {
checkInode(user, groups, inodeList.get(i), Mode.Bits.EXECUTE, path);
}
Inode inode = inodeList.get(inodeList.size() - 1);
if (checkIsOwner) {
if (inode == null || user.equals(inode.getOwner())) {
return;
}
throw new AccessControlException(ExceptionMessage.PERMISSION_DENIED.getMessage("user=" + user + " is not the owner of path=" + path));
}
checkInode(user, groups, inode, bits, path);
}
use of alluxio.master.file.meta.Inode in project alluxio by Alluxio.
the class FileSystemMaster method getInMemoryFiles.
/**
* @return absolute paths of all in memory files
*/
public List<AlluxioURI> getInMemoryFiles() {
List<AlluxioURI> files = new ArrayList<>();
Inode root = mInodeTree.getRoot();
// Root has no parent, lock directly.
root.lockRead();
try {
getInMemoryFilesInternal(mInodeTree.getRoot(), new AlluxioURI(AlluxioURI.SEPARATOR), files);
} finally {
root.unlockRead();
}
return files;
}
Aggregations