use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class MountTable method add.
/**
* Mounts the given UFS path at the given Alluxio path. The Alluxio path should not be nested
* under an existing mount point.
*
* @param alluxioUri an Alluxio path URI
* @param ufsUri a UFS path URI
* @param options the mount options
* @throws FileAlreadyExistsException if the mount point already exists
* @throws InvalidPathException if an invalid path is encountered
*/
public void add(AlluxioURI alluxioUri, AlluxioURI ufsUri, MountOptions options) throws FileAlreadyExistsException, InvalidPathException {
String alluxioPath = alluxioUri.getPath();
LOG.info("Mounting {} at {}", ufsUri, alluxioPath);
try (LockResource r = new LockResource(mWriteLock)) {
if (mMountTable.containsKey(alluxioPath)) {
throw new FileAlreadyExistsException(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath));
}
// or suffix of any existing mount path.
for (Map.Entry<String, MountInfo> entry : mMountTable.entrySet()) {
String mountedAlluxioPath = entry.getKey();
AlluxioURI mountedUfsUri = entry.getValue().getUfsUri();
if (!mountedAlluxioPath.equals(ROOT) && PathUtils.hasPrefix(alluxioPath, mountedAlluxioPath)) {
throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedAlluxioPath, alluxioPath));
}
if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority() == null || ufsUri.getAuthority().equals(mountedUfsUri.getAuthority()))) {
String ufsPath = ufsUri.getPath();
String mountedUfsPath = mountedUfsUri.getPath();
if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) {
throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedUfsUri.toString(), ufsUri.toString()));
}
if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) {
throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(ufsUri.toString(), mountedUfsUri.toString()));
}
}
}
mMountTable.put(alluxioPath, new MountInfo(ufsUri, options));
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class ConcurrentFileSystemMasterTest method consistentGetFileInfo.
/**
* Tests that getFileInfo (read operation) either returns the correct file info or fails if it
* has been renamed while the operation was waiting for the file lock.
*/
@Test
public void consistentGetFileInfo() throws Exception {
final int iterations = CONCURRENCY_FACTOR;
final AlluxioURI file = new AlluxioURI("/file");
final AlluxioURI dst = new AlluxioURI("/dst");
final CyclicBarrier barrier = new CyclicBarrier(2);
// If there are exceptions, we will store them here.
final ConcurrentHashSet<Throwable> errors = new ConcurrentHashSet<>();
Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread th, Throwable ex) {
errors.add(ex);
}
};
for (int i = 0; i < iterations; i++) {
// Don't want sleeping ufs behavior, so do not write to ufs
mFileSystem.createFile(file, CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE)).close();
Thread renamer = new Thread(new Runnable() {
@Override
public void run() {
try {
AuthenticatedClientUser.set(TEST_USER);
barrier.await();
mFileSystem.rename(file, dst);
mFileSystem.delete(dst);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
});
renamer.setUncaughtExceptionHandler(exceptionHandler);
Thread reader = new Thread(new Runnable() {
@Override
public void run() {
try {
AuthenticatedClientUser.set(TEST_USER);
barrier.await();
URIStatus status = mFileSystem.getStatus(file);
// If the uri status is successfully obtained, then the path should match
Assert.assertEquals(file.getName(), status.getName());
} catch (InvalidPathException | FileDoesNotExistException e) {
// InvalidPathException - if the file is renamed while the thread waits for the lock.
// FileDoesNotExistException - if the file is fully renamed before the getFileInfo call.
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
});
reader.setUncaughtExceptionHandler(exceptionHandler);
renamer.start();
reader.start();
renamer.join();
reader.join();
Assert.assertTrue("Errors detected: " + errors, errors.isEmpty());
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method mkdir.
/**
* Creates a new dir.
*
* @param path the path on the FS of the new dir
* @param mode Dir creation flags (IGNORED)
* @return 0 on success, a negative value on error
*/
@Override
public int mkdir(String path, @mode_t long mode) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("mkdir({}) [Alluxio: {}]", path, turi);
try {
mFileSystem.createDirectory(turi);
} catch (FileAlreadyExistsException e) {
LOG.debug("Cannot make dir. {} already exists", path, e);
return -ErrorCodes.EEXIST();
} catch (InvalidPathException e) {
LOG.debug("Cannot make dir. Invalid path: {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("Cannot make dir. IOException: {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("Cannot make dir. {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class PersistenceTest method waitUntilPersisted.
private void waitUntilPersisted(final AlluxioURI testFile) throws Exception {
// Persistence completion is asynchronous, so waiting is necessary.
CommonUtils.waitFor("async persistence is completed for file", () -> {
try {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(testFile, GET_STATUS_CONTEXT);
return fileInfo.getPersistenceState().equals(PersistenceState.PERSISTED.toString());
} catch (FileDoesNotExistException | InvalidPathException | AccessControlException | IOException e) {
return false;
}
}, WaitForOptions.defaults().setTimeoutMs(30000));
FileInfo fileInfo = mFileSystemMaster.getFileInfo(testFile, GET_STATUS_CONTEXT);
Map<Long, PersistJob> persistJobs = getPersistJobs();
Assert.assertEquals(0, getPersistRequests().size());
// We update the file info before removing the persist job, so we must wait here.
CommonUtils.waitFor("persist jobs list to be empty", () -> persistJobs.isEmpty(), WaitForOptions.defaults().setTimeoutMs(5 * Constants.SECOND_MS));
Assert.assertEquals(PersistenceState.PERSISTED.toString(), fileInfo.getPersistenceState());
Assert.assertNotEquals(Constants.INVALID_UFS_FINGERPRINT, fileInfo.getUfsFingerprint());
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class UfsStatusCacheTest method testFetchCancel.
@Test
public void testFetchCancel() throws Exception {
spyUfs();
doAnswer((Answer<UfsStatus[]>) invocation -> {
Thread.sleep(30 * Constants.HOUR_MS);
return new UfsStatus[] { Mockito.mock(UfsStatus.class) };
}).when(mUfs).listStatus(any(String.class));
mCache.prefetchChildren(new AlluxioURI("/"), mMountTable);
final BlockDeletionContext bdc = mock(BlockDeletionContext.class);
final JournalContext jc = mock(JournalContext.class);
final OperationContext oc = mock(OperationContext.class);
when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList());
final RpcContext rpcContext = new RpcContext(bdc, jc, oc);
AtomicReference<RuntimeException> ref = new AtomicReference<>(null);
Thread t = new Thread(() -> {
try {
mCache.fetchChildrenIfAbsent(rpcContext, new AlluxioURI("/"), mMountTable);
fail("Should not have been able to fetch children");
} catch (RuntimeException e) {
ref.set(e);
} catch (InterruptedException | InvalidPathException e) {
// do nothing
}
});
t.start();
when(oc.getCancelledTrackers()).thenReturn(Lists.newArrayList(new CallTracker() {
@Override
public boolean isCancelled() {
return true;
}
@Override
public Type getType() {
return Type.GRPC_CLIENT_TRACKER;
}
}));
t.join();
final RuntimeException runtimeException = ref.get();
assertNotNull(runtimeException);
MatcherAssert.assertThat(runtimeException.getMessage(), Matchers.stringContainsInOrder("Call cancelled"));
}
Aggregations