Search in sources :

Example 81 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class DefaultFileSystemMaster method setAclSingleInode.

private void setAclSingleInode(RpcContext rpcContext, SetAclAction action, LockedInodePath inodePath, List<AclEntry> entries, boolean replay, long opTimeMs) throws IOException, FileDoesNotExistException {
    Preconditions.checkState(inodePath.getLockPattern().isWrite());
    Inode inode = inodePath.getInode();
    // Check that we are not removing an extended mask.
    if (action == SetAclAction.REMOVE) {
        for (AclEntry entry : entries) {
            if ((entry.isDefault() && inode.getDefaultACL().hasExtended()) || (!entry.isDefault() && inode.getACL().hasExtended())) {
                if (entry.getType() == AclEntryType.MASK) {
                    throw new InvalidArgumentException("Deleting the mask for an extended ACL is not allowed. entry: " + entry);
                }
            }
        }
    }
    // Check that we are not setting default ACL to a file
    if (inode.isFile()) {
        for (AclEntry entry : entries) {
            if (entry.isDefault()) {
                throw new UnsupportedOperationException("Can not set default ACL for a file");
            }
        }
    }
    mInodeTree.setAcl(rpcContext, SetAclEntry.newBuilder().setId(inode.getId()).setOpTimeMs(opTimeMs).setAction(ProtoUtils.toProto(action)).addAllEntries(entries.stream().map(ProtoUtils::toProto).collect(Collectors.toList())).build());
    try {
        if (!replay && inode.isPersisted()) {
            setUfsAcl(inodePath);
        }
    } catch (InvalidPathException | AccessControlException e) {
        LOG.warn("Setting ufs ACL failed for path: {}", inodePath.getUri(), e);
    // TODO(david): revert the acl and default acl to the initial state if writing to ufs failed.
    }
}
Also used : Inode(alluxio.master.file.meta.Inode) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AclEntry(alluxio.security.authorization.AclEntry) SetAclEntry(alluxio.proto.journal.File.SetAclEntry) ProtoUtils(alluxio.util.proto.ProtoUtils) AccessControlException(alluxio.exception.AccessControlException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 82 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class DefaultAsyncPersistHandler method getWorkerStoringFile.

/**
 * Gets a worker where the given file is stored.
 *
 * @param path the path to the file
 * @return the id of the storing worker
 * @throws FileDoesNotExistException when the file does not exist on any worker
 * @throws AccessControlException if permission checking fails
 */
// TODO(calvin): Propagate the exceptions in certain cases
private long getWorkerStoringFile(AlluxioURI path) throws FileDoesNotExistException, AccessControlException, UnavailableException {
    long fileId = mFileSystemMasterView.getFileId(path);
    try {
        if (mFileSystemMasterView.getFileInfo(fileId).getLength() == 0) {
            // if file is empty, return any worker
            List<WorkerInfo> workerInfoList = mFileSystemMasterView.getWorkerInfoList();
            if (workerInfoList.isEmpty()) {
                LOG.error("No worker is available");
                return IdUtils.INVALID_WORKER_ID;
            }
            // randomly pick a worker
            int index = new Random().nextInt(workerInfoList.size());
            return workerInfoList.get(index).getId();
        }
    } catch (UnavailableException e) {
        return IdUtils.INVALID_WORKER_ID;
    }
    Map<Long, Integer> workerBlockCounts = new HashMap<>();
    List<FileBlockInfo> blockInfoList;
    try {
        blockInfoList = mFileSystemMasterView.getFileBlockInfoList(path);
        for (FileBlockInfo fileBlockInfo : blockInfoList) {
            for (BlockLocation blockLocation : fileBlockInfo.getBlockInfo().getLocations()) {
                if (workerBlockCounts.containsKey(blockLocation.getWorkerId())) {
                    workerBlockCounts.put(blockLocation.getWorkerId(), workerBlockCounts.get(blockLocation.getWorkerId()) + 1);
                } else {
                    workerBlockCounts.put(blockLocation.getWorkerId(), 1);
                }
                // all the blocks of a file must be stored on the same worker
                if (workerBlockCounts.get(blockLocation.getWorkerId()) == blockInfoList.size()) {
                    return blockLocation.getWorkerId();
                }
            }
        }
    } catch (FileDoesNotExistException e) {
        LOG.error("The file {} to persist does not exist", path);
        return IdUtils.INVALID_WORKER_ID;
    } catch (InvalidPathException e) {
        LOG.error("The file {} to persist is invalid", path);
        return IdUtils.INVALID_WORKER_ID;
    } catch (UnavailableException e) {
        return IdUtils.INVALID_WORKER_ID;
    }
    if (workerBlockCounts.size() == 0) {
        LOG.error("The file " + path + " does not exist on any worker");
        return IdUtils.INVALID_WORKER_ID;
    }
    LOG.error("Not all the blocks of file {} stored on the same worker", path);
    return IdUtils.INVALID_WORKER_ID;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) HashMap(java.util.HashMap) UnavailableException(alluxio.exception.status.UnavailableException) WorkerInfo(alluxio.wire.WorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) InvalidPathException(alluxio.exception.InvalidPathException) Random(java.util.Random)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)82 AlluxioURI (alluxio.AlluxioURI)51 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)44 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)25 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)19 AccessControlException (alluxio.exception.AccessControlException)17 AlluxioException (alluxio.exception.AlluxioException)17 LockedInodePath (alluxio.master.file.meta.LockedInodePath)17 MountTable (alluxio.master.file.meta.MountTable)14 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Inode (alluxio.master.file.meta.Inode)12 MountInfo (alluxio.master.file.meta.options.MountInfo)11 BlockInfoException (alluxio.exception.BlockInfoException)10 UnavailableException (alluxio.exception.status.UnavailableException)9 LockResource (alluxio.resource.LockResource)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeDirectory (alluxio.master.file.meta.InodeDirectory)8 Test (org.junit.Test)8 URIStatus (alluxio.client.file.URIStatus)7