Search in sources :

Example 1 with FileIncompleteException

use of alluxio.exception.FileIncompleteException 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 FileIncompleteException

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

the class AlluxioJniFuseFileSystemTest method openWithDelay.

@Test
public void openWithDelay() throws Exception {
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    FileInfo fi = setUpOpenMock(expectedPath);
    fi.setCompleted(false);
    when(mFileSystem.openFile(expectedPath)).thenThrow(new FileIncompleteException(expectedPath));
    // Use another thread to open file so that
    // we could change the file status when opening it
    Thread t = new Thread(() -> mFuseFs.open("/foo/bar", mFileInfo));
    t.start();
    Thread.sleep(1000);
    // If the file exists but is not completed, we will wait for the file to complete
    verify(mFileSystem, atLeast(10)).getStatus(expectedPath);
    fi.setCompleted(true);
    t.join();
    verify(mFileSystem, times(2)).openFile(expectedPath);
}
Also used : FuseFileInfo(alluxio.jnifuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) FileIncompleteException(alluxio.exception.FileIncompleteException) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with FileIncompleteException

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

the class AlluxioFuseFileSystemTest method incompleteFileCannotOpen.

@Test
public void incompleteFileCannotOpen() throws Exception {
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    FileInfo fi = setUpOpenMock(expectedPath);
    fi.setCompleted(false);
    when(mFileSystem.openFile(expectedPath)).thenThrow(new FileIncompleteException(expectedPath));
    assertEquals(-ErrorCodes.EFAULT(), mFuseFs.open("/foo/bar", mFileInfo));
}
Also used : FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) FileIncompleteException(alluxio.exception.FileIncompleteException) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with FileIncompleteException

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

the class AlluxioFuseFileSystemTest method openWithDelay.

@Test
public void openWithDelay() throws Exception {
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    FileInfo fi = setUpOpenMock(expectedPath);
    fi.setCompleted(false);
    when(mFileSystem.openFile(expectedPath)).thenThrow(new FileIncompleteException(expectedPath));
    // Use another thread to open file so that
    // we could change the file status when opening it
    Thread t = new Thread(() -> mFuseFs.open("/foo/bar", mFileInfo));
    t.start();
    Thread.sleep(1000);
    // If the file exists but is not completed, we will wait for the file to complete
    verify(mFileSystem, atLeast(10)).getStatus(expectedPath);
    fi.setCompleted(true);
    t.join();
    verify(mFileSystem, times(2)).openFile(expectedPath);
}
Also used : FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) FileIncompleteException(alluxio.exception.FileIncompleteException) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with FileIncompleteException

use of alluxio.exception.FileIncompleteException 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)6 FileIncompleteException (alluxio.exception.FileIncompleteException)6 FileInfo (alluxio.wire.FileInfo)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 OpenDirectoryException (alluxio.exception.OpenDirectoryException)2 FuseFileInfo (alluxio.jnifuse.struct.FuseFileInfo)2 FuseFileInfo (ru.serce.jnrfuse.struct.FuseFileInfo)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