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);
}
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);
}
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));
}
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);
}
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;
}
Aggregations