Search in sources :

Example 1 with OpenDirectoryException

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

the class BaseFileSystem method openFile.

@Override
public FileInStream openFile(URIStatus status, OpenFilePOptions options) throws FileDoesNotExistException, OpenDirectoryException, FileIncompleteException, IOException, AlluxioException {
    AlluxioURI path = new AlluxioURI(status.getPath());
    if (status.isFolder()) {
        throw new OpenDirectoryException(path);
    }
    if (!status.isCompleted()) {
        throw new FileIncompleteException(path);
    }
    AlluxioConfiguration conf = mFsContext.getPathConf(path);
    OpenFilePOptions mergedOptions = FileSystemOptions.openFileDefaults(conf).toBuilder().mergeFrom(options).build();
    InStreamOptions inStreamOptions = new InStreamOptions(status, mergedOptions, conf);
    return new AlluxioFileInStream(status, inStreamOptions, mFsContext);
}
Also used : OpenDirectoryException(alluxio.exception.OpenDirectoryException) FileIncompleteException(alluxio.exception.FileIncompleteException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) AlluxioURI(alluxio.AlluxioURI) InStreamOptions(alluxio.client.file.options.InStreamOptions)

Example 2 with OpenDirectoryException

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

the class AlluxioFuseFileSystem method openInternal.

private int openInternal(String path, FuseFileInfo fi) {
    final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    // (see {@code man 2 open} for the structure of the flags bitfield)
    // File creation flags are the last two bits of flags
    final int flags = fi.flags.get();
    if (mOpenFiles.size() >= MAX_OPEN_FILES) {
        LOG.error("Cannot open {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
        return ErrorCodes.EMFILE();
    }
    FileInStream is;
    try {
        try {
            is = mFileSystem.openFile(uri);
        } catch (FileIncompleteException e) {
            if (AlluxioFuseUtils.waitForFileCompleted(mFileSystem, uri)) {
                is = mFileSystem.openFile(uri);
            } else {
                throw e;
            }
        }
    } catch (OpenDirectoryException e) {
        LOG.error("Cannot open folder {}", path);
        return -ErrorCodes.EISDIR();
    } catch (FileIncompleteException e) {
        LOG.error("Cannot open incomplete file {}", path);
        return -ErrorCodes.EFAULT();
    } catch (FileDoesNotExistException | InvalidPathException e) {
        LOG.error("Failed to open file {}, path does not exist or is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to open file {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    long fid = mNextOpenFileId.getAndIncrement();
    mOpenFiles.add(new OpenFileEntry<>(fid, path, is, null));
    fi.fh.set(fid);
    return 0;
}
Also used : OpenDirectoryException(alluxio.exception.OpenDirectoryException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInStream(alluxio.client.file.FileInStream) FileIncompleteException(alluxio.exception.FileIncompleteException) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AlluxioURI (alluxio.AlluxioURI)2 FileIncompleteException (alluxio.exception.FileIncompleteException)2 OpenDirectoryException (alluxio.exception.OpenDirectoryException)2 FileInStream (alluxio.client.file.FileInStream)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)1 InvalidPathException (java.nio.file.InvalidPathException)1