use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileSystemIntegrationTest method createFileWithFileAlreadyExistsException.
@Test
public void createFileWithFileAlreadyExistsException() throws Exception {
AlluxioURI uri = new AlluxioURI(PathUtils.uniqPath());
mFileSystem.createFile(uri, mWriteBoth).close();
Assert.assertNotNull(mFileSystem.getStatus(uri));
try {
mFileSystem.createFile(uri, mWriteBoth).close();
} catch (AlluxioException e) {
Assert.assertTrue(e instanceof FileAlreadyExistsException);
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileSystemMaster method processJournalEntry.
@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
if (entry.hasInodeFile()) {
mInodeTree.addInodeFileFromJournal(entry.getInodeFile());
// Add the file to TTL buckets, the insert automatically rejects files w/ Constants.NO_TTL
InodeFileEntry inodeFileEntry = entry.getInodeFile();
if (inodeFileEntry.hasTtl()) {
mTtlBuckets.insert(InodeFile.fromJournalEntry(inodeFileEntry));
}
} else if (entry.hasInodeDirectory()) {
try {
// Add the directory to TTL buckets, the insert automatically rejects directory
// w/ Constants.NO_TTL
InodeDirectoryEntry inodeDirectoryEntry = entry.getInodeDirectory();
if (inodeDirectoryEntry.hasTtl()) {
mTtlBuckets.insert(InodeDirectory.fromJournalEntry(inodeDirectoryEntry));
}
mInodeTree.addInodeDirectoryFromJournal(entry.getInodeDirectory());
} catch (AccessControlException e) {
throw new RuntimeException(e);
}
} else if (entry.hasInodeLastModificationTime()) {
InodeLastModificationTimeEntry modTimeEntry = entry.getInodeLastModificationTime();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(modTimeEntry.getId(), InodeTree.LockMode.WRITE)) {
inodePath.getInode().setLastModificationTimeMs(modTimeEntry.getLastModificationTimeMs(), true);
} catch (FileDoesNotExistException e) {
throw new RuntimeException(e);
}
} else if (entry.hasPersistDirectory()) {
PersistDirectoryEntry typedEntry = entry.getPersistDirectory();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(typedEntry.getId(), InodeTree.LockMode.WRITE)) {
inodePath.getInode().setPersistenceState(PersistenceState.PERSISTED);
} catch (FileDoesNotExistException e) {
throw new RuntimeException(e);
}
} else if (entry.hasCompleteFile()) {
try {
completeFileFromEntry(entry.getCompleteFile());
} catch (InvalidPathException | InvalidFileSizeException | FileAlreadyCompletedException e) {
throw new RuntimeException(e);
}
} else if (entry.hasSetAttribute()) {
try {
setAttributeFromEntry(entry.getSetAttribute());
} catch (AccessControlException | FileDoesNotExistException | InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasDeleteFile()) {
deleteFromEntry(entry.getDeleteFile());
} else if (entry.hasRename()) {
renameFromEntry(entry.getRename());
} else if (entry.hasInodeDirectoryIdGenerator()) {
mDirectoryIdGenerator.initFromJournalEntry(entry.getInodeDirectoryIdGenerator());
} else if (entry.hasReinitializeFile()) {
resetBlockFileFromEntry(entry.getReinitializeFile());
} else if (entry.hasAddMountPoint()) {
try {
mountFromEntry(entry.getAddMountPoint());
} catch (FileAlreadyExistsException | InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasDeleteMountPoint()) {
try {
unmountFromEntry(entry.getDeleteMountPoint());
} catch (InvalidPathException e) {
throw new RuntimeException(e);
}
} else if (entry.hasAsyncPersistRequest()) {
try {
long fileId = (entry.getAsyncPersistRequest()).getFileId();
try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) {
scheduleAsyncPersistenceInternal(inodePath);
}
// NOTE: persistence is asynchronous so there is no guarantee the path will still exist
mAsyncPersistHandler.scheduleAsyncPersistence(getPath(fileId));
} catch (AlluxioException e) {
// It's possible that rescheduling the async persist calls fails, because the blocks may no
// longer be in the memory
LOG.error(e.getMessage());
}
} else {
throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileInStream method updateCacheStream.
/**
* Updates {@link #mCurrentCacheStream}. When {@code mShouldCache} is true, {@code FileInStream}
* will create an {@code BlockOutStream} to cache the data read only if
* <ol>
* <li>the file is read from under storage, or</li>
* <li>the file is read from a remote worker and we have an available local worker.</li>
* </ol>
* The following preconditions are checked inside:
* <ol>
* <li>{@link #mCurrentCacheStream} is either done or null.</li>
* <li>EOF is reached or {@link #mCurrentBlockInStream} must be valid.</li>
* </ol>
* After this call, {@link #mCurrentCacheStream} is either null or freshly created.
* {@link #mCurrentCacheStream} is created only if the block is not cached in a chosen machine
* and mPos is at the beginning of a block.
* This function is only called by {@link #updateStreams()}.
*
* @param blockId cached result of {@link #getCurrentBlockId()}
* @throws IOException if the next cache stream cannot be created
*/
private void updateCacheStream(long blockId) throws IOException {
// We should really only close a cache stream here. This check is to verify this.
Preconditions.checkState(mCurrentCacheStream == null || cacheStreamRemaining() == 0);
closeOrCancelCacheStream();
Preconditions.checkState(mCurrentCacheStream == null);
if (blockId < 0) {
// End of file.
return;
}
Preconditions.checkNotNull(mCurrentBlockInStream);
if (!mShouldCache || isReadingFromLocalBlockWorker()) {
return;
}
// If this block is read from a remote worker but we don't have a local worker, don't cache
if (isReadingFromRemoteBlockWorker() && !mContext.hasLocalWorker()) {
return;
}
// middle of a block.
if (mPos % mBlockSize != 0) {
return;
}
try {
WorkerNetAddress address = mCacheLocationPolicy.getWorkerForNextBlock(mBlockStore.getWorkerInfoList(), getBlockSizeAllocation(mPos));
// If we reach here, we need to cache.
mCurrentCacheStream = mBlockStore.getOutStream(blockId, getBlockSize(mPos), address, mOutStreamOptions);
} catch (IOException e) {
handleCacheStreamIOException(e);
} catch (AlluxioException e) {
LOG.warn("The block with ID {} could not be cached into Alluxio storage.", blockId, e);
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileOutStream method close.
@Override
public void close() throws IOException {
if (mClosed) {
return;
}
try {
if (mCurrentBlockOutStream != null) {
mPreviousBlockOutStreams.add(mCurrentBlockOutStream);
}
CompleteFileOptions options = CompleteFileOptions.defaults();
if (mUnderStorageType.isSyncPersist()) {
if (mUfsDelegation) {
mUnderStorageOutputStream.close();
if (mCanceled) {
mFileSystemWorkerClient.cancelUfsFile(mUfsFileId, CancelUfsFileOptions.defaults());
} else {
long len = mFileSystemWorkerClient.completeUfsFile(mUfsFileId, CompleteUfsFileOptions.defaults());
options.setUfsLength(len);
}
} else {
UnderFileSystem ufs = UnderFileSystem.Factory.get(mUfsPath);
if (mCanceled) {
// TODO(yupeng): Handle this special case in under storage integrations.
mUnderStorageOutputStream.close();
ufs.deleteFile(mUfsPath);
} else {
mUnderStorageOutputStream.flush();
mUnderStorageOutputStream.close();
options.setUfsLength(ufs.getFileSize(mUfsPath));
}
}
}
if (mAlluxioStorageType.isStore()) {
if (mCanceled) {
for (OutputStream bos : mPreviousBlockOutStreams) {
outStreamCancel(bos);
}
} else {
for (OutputStream bos : mPreviousBlockOutStreams) {
bos.close();
}
}
}
// Complete the file if it's ready to be completed.
if (!mCanceled && (mUnderStorageType.isSyncPersist() || mAlluxioStorageType.isStore())) {
try (CloseableResource<FileSystemMasterClient> masterClient = mContext.acquireMasterClientResource()) {
masterClient.get().completeFile(mUri, options);
}
}
if (mUnderStorageType.isAsyncPersist()) {
scheduleAsyncPersist();
}
} catch (AlluxioException e) {
throw mCloser.rethrow(new IOException(e));
} catch (Throwable e) {
// IOException will be thrown as-is
throw mCloser.rethrow(e);
} finally {
mClosed = true;
mCloser.close();
}
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class FileSystemContext method getWorkerAddresses.
/**
* @return if there are any local workers, the returned list will ONLY contain the local workers,
* otherwise a list of all remote workers will be returned
* @throws IOException if an error occurs communicating with the master
*/
private List<WorkerNetAddress> getWorkerAddresses() throws IOException {
List<WorkerInfo> infos;
BlockMasterClient blockMasterClient = mBlockMasterClientPool.acquire();
try {
infos = blockMasterClient.getWorkerInfoList();
} catch (AlluxioException e) {
throw new IOException(e);
} finally {
mBlockMasterClientPool.release(blockMasterClient);
}
if (infos.isEmpty()) {
throw new IOException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
}
// Convert the worker infos into net addresses, if there are local addresses, only keep those
List<WorkerNetAddress> workerNetAddresses = new ArrayList<>();
List<WorkerNetAddress> localWorkerNetAddresses = new ArrayList<>();
String localHostname = NetworkAddressUtils.getClientHostName();
for (WorkerInfo info : infos) {
WorkerNetAddress netAddress = info.getAddress();
if (netAddress.getHost().equals(localHostname)) {
localWorkerNetAddresses.add(netAddress);
}
workerNetAddresses.add(netAddress);
}
return localWorkerNetAddresses.isEmpty() ? workerNetAddresses : localWorkerNetAddresses;
}
Aggregations