Search in sources :

Example 61 with InvalidPathException

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));
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 62 with InvalidPathException

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());
    }
}
Also used : URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) CyclicBarrier(java.util.concurrent.CyclicBarrier) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 63 with InvalidPathException

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;
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 64 with InvalidPathException

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());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 65 with InvalidPathException

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"));
}
Also used : Mockito.doThrow(org.mockito.Mockito.doThrow) Future(java.util.concurrent.Future) InvalidPathException(alluxio.exception.InvalidPathException) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Assert.fail(org.junit.Assert.fail) LocalUnderFileSystem(alluxio.underfs.local.LocalUnderFileSystem) ServerConfiguration(alluxio.conf.ServerConfiguration) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) NoopUfsAbsentPathCache(alluxio.master.file.meta.NoopUfsAbsentPathCache) MatcherAssert(org.hamcrest.MatcherAssert) Assert.assertFalse(org.junit.Assert.assertFalse) RpcContext(alluxio.master.file.RpcContext) JournalContext(alluxio.master.journal.JournalContext) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OperationContext(alluxio.master.file.contexts.OperationContext) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) PathUtils(alluxio.util.io.PathUtils) Answer(org.mockito.stubbing.Answer) Lists(com.google.common.collect.Lists) Constants(alluxio.Constants) MountInfo(alluxio.master.file.meta.options.MountInfo) AlluxioURI(alluxio.AlluxioURI) MountPOptions(alluxio.grpc.MountPOptions) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ReentrantLock(java.util.concurrent.locks.ReentrantLock) IdUtils(alluxio.util.IdUtils) Assert.assertNotNull(org.junit.Assert.assertNotNull) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) UfsAbsentPathCache(alluxio.master.file.meta.UfsAbsentPathCache) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Lock(java.util.concurrent.locks.Lock) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) CallTracker(alluxio.master.file.contexts.CallTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) MountTable(alluxio.master.file.meta.MountTable) TemporaryFolder(org.junit.rules.TemporaryFolder) OperationContext(alluxio.master.file.contexts.OperationContext) JournalContext(alluxio.master.journal.JournalContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvalidPathException(alluxio.exception.InvalidPathException) RpcContext(alluxio.master.file.RpcContext) BlockDeletionContext(alluxio.master.file.BlockDeletionContext) AlluxioURI(alluxio.AlluxioURI) CallTracker(alluxio.master.file.contexts.CallTracker) Test(org.junit.Test)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)82 AlluxioURI (alluxio.AlluxioURI)51 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)44 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)25 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)19 AccessControlException (alluxio.exception.AccessControlException)17 AlluxioException (alluxio.exception.AlluxioException)17 LockedInodePath (alluxio.master.file.meta.LockedInodePath)17 MountTable (alluxio.master.file.meta.MountTable)14 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Inode (alluxio.master.file.meta.Inode)12 MountInfo (alluxio.master.file.meta.options.MountInfo)11 BlockInfoException (alluxio.exception.BlockInfoException)10 UnavailableException (alluxio.exception.status.UnavailableException)9 LockResource (alluxio.resource.LockResource)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeDirectory (alluxio.master.file.meta.InodeDirectory)8 Test (org.junit.Test)8 URIStatus (alluxio.client.file.URIStatus)7