Search in sources :

Example 21 with InvalidPathException

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

the class DefaultFileSystemMaster method activeSyncMetadata.

/**
 * Actively sync metadata, based on a list of changed files.
 *
 * @param path the path to sync
 * @param changedFiles collection of files that are changed under the path to sync, if this is
 *        null, force sync the entire directory
 * @param executorService executor to execute the parallel incremental sync
 */
public void activeSyncMetadata(AlluxioURI path, Collection<AlluxioURI> changedFiles, ExecutorService executorService) throws IOException {
    if (changedFiles == null) {
        LOG.info("Start an active full sync of {}", path.toString());
    } else {
        LOG.info("Start an active incremental sync of {} files", changedFiles.size());
    }
    long start = System.currentTimeMillis();
    if (changedFiles != null && changedFiles.isEmpty()) {
        return;
    }
    try (RpcContext rpcContext = createRpcContext()) {
        if (changedFiles == null) {
            // full sync
            // Set sync interval to 0 to force a sync.
            FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
            LockingScheme scheme = createSyncLockingScheme(path, options, false);
            InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ALL, options, false, false, false, false);
            if (sync.sync().equals(FAILED)) {
                LOG.debug("Active full sync on {} didn't sync any paths.", path);
            }
            long end = System.currentTimeMillis();
            LOG.info("Ended an active full sync of {} in {}ms", path.toString(), end - start);
            return;
        } else {
            // incremental sync
            Set<Callable<Void>> callables = new HashSet<>();
            for (AlluxioURI changedFile : changedFiles) {
                callables.add(() -> {
                    // Set sync interval to 0 to force a sync.
                    FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
                    LockingScheme scheme = createSyncLockingScheme(changedFile, options, false);
                    InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ONE, options, false, false, false, false);
                    if (sync.sync().equals(FAILED)) {
                        // Use debug because this can be a noisy log
                        LOG.debug("Incremental sync on {} didn't sync any paths.", path);
                    }
                    return null;
                });
            }
            executorService.invokeAll(callables);
        }
    } catch (InterruptedException e) {
        LOG.warn("InterruptedException during active sync: {}", e.toString());
        Thread.currentThread().interrupt();
        return;
    } catch (InvalidPathException | AccessControlException e) {
        LogUtils.warnWithException(LOG, "Failed to active sync on path {}", path, e);
    }
    if (changedFiles != null) {
        long end = System.currentTimeMillis();
        LOG.info("Ended an active incremental sync of {} files in {}ms", changedFiles.size(), end - start);
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) Callable(java.util.concurrent.Callable) InvalidPathException(alluxio.exception.InvalidPathException) LockingScheme(alluxio.master.file.meta.LockingScheme) FileSystemMasterCommonPOptions(alluxio.grpc.FileSystemMasterCommonPOptions) HashSet(java.util.HashSet) AlluxioURI(alluxio.AlluxioURI)

Example 22 with InvalidPathException

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

the class DefaultFileSystemMaster method scheduleAsyncPersistenceInternal.

private void scheduleAsyncPersistenceInternal(LockedInodePath inodePath, ScheduleAsyncPersistenceContext context, RpcContext rpcContext) throws InvalidPathException, FileDoesNotExistException {
    InodeFile inode = inodePath.getInodeFile();
    if (!inode.isCompleted()) {
        throw new InvalidPathException("Cannot persist an incomplete Alluxio file: " + inodePath.getUri());
    }
    if (shouldPersistPath(inodePath.toString())) {
        mInodeTree.updateInode(rpcContext, UpdateInodeEntry.newBuilder().setId(inode.getId()).setPersistenceState(PersistenceState.TO_BE_PERSISTED.name()).build());
        mPersistRequests.put(inode.getId(), new alluxio.time.ExponentialTimer(ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_INITIAL_INTERVAL_MS), ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_MAX_INTERVAL_MS), context.getPersistenceWaitTime(), ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_MAX_TOTAL_WAIT_TIME_MS)));
    }
}
Also used : InodeFile(alluxio.master.file.meta.InodeFile) InvalidPathException(alluxio.exception.InvalidPathException)

Example 23 with InvalidPathException

use of alluxio.exception.InvalidPathException 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));
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) Inode(alluxio.master.file.meta.Inode) AccessControlException(alluxio.exception.AccessControlException) DescendantType(alluxio.file.options.DescendantType) InvalidPathException(alluxio.exception.InvalidPathException)

Example 24 with InvalidPathException

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

the class BaseFileSystem method createFile.

@Override
public FileOutStream createFile(AlluxioURI path, CreateFilePOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException {
    checkUri(path);
    return rpc(client -> {
        CreateFilePOptions mergedOptions = FileSystemOptions.createFileDefaults(mFsContext.getPathConf(path)).toBuilder().mergeFrom(options).build();
        URIStatus status = client.createFile(path, mergedOptions);
        LOG.debug("Created file {}, options: {}", path.getPath(), mergedOptions);
        OutStreamOptions outStreamOptions = new OutStreamOptions(mergedOptions, mFsContext.getClientContext(), mFsContext.getPathConf(path));
        outStreamOptions.setUfsPath(status.getUfsPath());
        outStreamOptions.setMountId(status.getMountId());
        outStreamOptions.setAcl(status.getAcl());
        try {
            return new AlluxioFileOutStream(path, outStreamOptions, mFsContext);
        } catch (Exception e) {
            delete(path);
            throw e;
        }
    });
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) InvalidPathException(alluxio.exception.InvalidPathException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) AlreadyExistsException(alluxio.exception.status.AlreadyExistsException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) FileIncompleteException(alluxio.exception.FileIncompleteException) OpenDirectoryException(alluxio.exception.OpenDirectoryException)

Example 25 with InvalidPathException

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

the class InodeTree method lockInodePathById.

/**
 * Locks existing inodes on the path to the inode specified by an id, in the specified
 * {@link LockPattern}. The target inode must exist. This may require multiple traversals of the
 * tree, so may be inefficient.
 *
 * @param id the inode id
 * @param lockPattern the {@link LockPattern} to lock the inodes with
 * @return the {@link LockedInodePath} representing the locked path of inodes
 * @throws FileDoesNotExistException if the target inode does not exist
 */
private LockedInodePath lockInodePathById(long id, LockPattern lockPattern) throws FileDoesNotExistException {
    int count = 0;
    while (true) {
        Optional<Inode> inode = mInodeStore.get(id);
        if (!inode.isPresent()) {
            throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST.getMessage(id));
        }
        // Compute the path given the target inode.
        StringBuilder builder = new StringBuilder();
        computePathForInode(inode.get(), builder);
        AlluxioURI uri = new AlluxioURI(builder.toString());
        boolean valid = false;
        LockedInodePath inodePath = null;
        try {
            inodePath = lockInodePath(uri, lockPattern);
            if (inodePath.getInode().getId() == id) {
                // Set to true, so the path is not unlocked before returning.
                valid = true;
                return inodePath;
            }
        // The path does not end up at the target inode id. Repeat the traversal.
        } catch (InvalidPathException e) {
            // ignore and repeat the loop
            LOG.debug("Inode lookup id {} computed path {} mismatch id. Repeating.", id, uri);
        } finally {
            if (!valid && inodePath != null) {
                inodePath.close();
            }
        }
        count++;
        if (count > PATH_TRAVERSAL_RETRIES) {
            throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST_RETRIES.getMessage(id));
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

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