Search in sources :

Example 31 with InvalidPathException

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

the class ActiveSyncManager method stopSyncAndJournal.

/**
 * Stop active sync on a URI and journal the remove entry.
 *
 * @param rpcContext the master rpc or no-op context
 * @param syncPoint sync point to be stopped
 */
public void stopSyncAndJournal(RpcContext rpcContext, AlluxioURI syncPoint) throws InvalidPathException {
    if (!isSyncPoint(syncPoint)) {
        throw new InvalidPathException(String.format("%s is not a sync point", syncPoint));
    }
    try (LockResource r = new LockResource(mLock)) {
        MountTable.Resolution resolution = mMountTable.resolve(syncPoint);
        LOG.debug("stop syncPoint {}", syncPoint.getPath());
        final long mountId = resolution.getMountId();
        RemoveSyncPointEntry removeSyncPoint = File.RemoveSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).setMountId(mountId).build();
        applyAndJournal(rpcContext, removeSyncPoint);
        try {
            stopSyncInternal(syncPoint);
        } catch (Throwable e) {
            LOG.warn("Stop sync failed on {}", syncPoint, e);
            // revert state;
            AddSyncPointEntry addSyncPoint = File.AddSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).build();
            applyAndJournal(rpcContext, addSyncPoint);
            recoverFromStopSync(syncPoint);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) RemoveSyncPointEntry(alluxio.proto.journal.File.RemoveSyncPointEntry) MountTable(alluxio.master.file.meta.MountTable) InvalidPathException(alluxio.exception.InvalidPathException)

Example 32 with InvalidPathException

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

the class ActiveSyncManager method getSyncPathIterator.

private Iterator<Journal.JournalEntry> getSyncPathIterator() {
    final Iterator<AlluxioURI> it = mSyncPathList.iterator();
    return new Iterator<Journal.JournalEntry>() {

        private AlluxioURI mEntry = null;

        @Override
        public boolean hasNext() {
            if (mEntry != null) {
                return true;
            }
            if (it.hasNext()) {
                mEntry = it.next();
                return true;
            }
            return false;
        }

        @Override
        public Journal.JournalEntry next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            String syncPointPath = mEntry.getPath();
            long mountId = -1;
            while (mountId == -1) {
                try {
                    syncPointPath = mEntry.getPath();
                    String mountPoint = mMountTable.getMountPoint(mEntry);
                    MountInfo mountInfo = mMountTable.getMountTable().get(mountPoint);
                    mountId = mountInfo.getMountId();
                } catch (InvalidPathException e) {
                    LOG.info("Path resolution failed for {}, exception {}", syncPointPath, e);
                    mEntry = null;
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                }
            }
            mEntry = null;
            File.AddSyncPointEntry addSyncPointEntry = File.AddSyncPointEntry.newBuilder().setSyncpointPath(syncPointPath).setMountId(mountId).build();
            return Journal.JournalEntry.newBuilder().setAddSyncPoint(addSyncPointEntry).build();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("ActiveSyncManager#Iterator#remove is not supported.");
        }
    };
}
Also used : AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) CloseableIterator(alluxio.resource.CloseableIterator) Iterator(java.util.Iterator) Journal(alluxio.proto.journal.Journal) MountInfo(alluxio.master.file.meta.options.MountInfo) File(alluxio.proto.journal.File) NoSuchElementException(java.util.NoSuchElementException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 33 with InvalidPathException

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

the class ActiveSyncManager method startSyncAndJournal.

/**
 * Start active sync on a URI and journal the add entry.
 *
 * @param rpcContext the master rpc or no-op context
 * @param syncPoint sync point to be start
 */
public void startSyncAndJournal(RpcContext rpcContext, AlluxioURI syncPoint) throws InvalidPathException {
    try (LockResource r = new LockResource(mLock)) {
        MountTable.Resolution resolution = mMountTable.resolve(syncPoint);
        long mountId = resolution.getMountId();
        try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
            if (!ufsResource.get().supportsActiveSync()) {
                throw new UnsupportedOperationException("Active Syncing is not supported on this UFS type: " + ufsResource.get().getUnderFSType());
            }
        }
        if (isUnderSyncPoint(syncPoint)) {
            throw new InvalidPathException("URI " + syncPoint + " is already a sync point");
        }
        AddSyncPointEntry addSyncPoint = AddSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).setMountId(mountId).build();
        applyAndJournal(rpcContext, addSyncPoint);
        try {
            startSyncInternal(syncPoint, resolution);
        } catch (Throwable e) {
            LOG.warn("Start sync failed on {}", syncPoint, e);
            // revert state;
            RemoveSyncPointEntry removeSyncPoint = File.RemoveSyncPointEntry.newBuilder().setSyncpointPath(syncPoint.toString()).build();
            applyAndJournal(rpcContext, removeSyncPoint);
            recoverFromStartSync(syncPoint, resolution.getMountId());
            throw e;
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) AddSyncPointEntry(alluxio.proto.journal.File.AddSyncPointEntry) RemoveSyncPointEntry(alluxio.proto.journal.File.RemoveSyncPointEntry) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException)

Example 34 with InvalidPathException

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

the class AsyncUfsAbsentPathCache method processSinglePath.

/**
 * Processes and checks the existence of the corresponding ufs path for the given Alluxio path.
 *
 * @param alluxioUri the Alluxio path to process
 * @param mountInfo the associated {@link MountInfo} for the Alluxio path
 * @return if true, further traversal of the descendant paths should continue
 */
private boolean processSinglePath(AlluxioURI alluxioUri, MountInfo mountInfo) {
    PathLock pathLock = new PathLock();
    Lock writeLock = pathLock.writeLock();
    Lock readLock = null;
    try {
        // Write lock this path, to only enable a single task per path
        writeLock.lock();
        PathLock existingLock = mCurrentPaths.putIfAbsent(alluxioUri.getPath(), pathLock);
        if (existingLock != null) {
            // Another thread already locked this path and is processing it. Wait for the other
            // thread to finish, by locking the existing read lock.
            writeLock.unlock();
            writeLock = null;
            readLock = existingLock.readLock();
            readLock.lock();
            if (mCache.getIfPresent(alluxioUri.getPath()) != null) {
                // This path is already in the cache (is absent). Further traversal is unnecessary.
                return false;
            }
        } else {
            // This thread has the exclusive lock for this path.
            // Resolve this Alluxio uri. It should match the original mount id.
            MountTable.Resolution resolution = mMountTable.resolve(alluxioUri);
            if (resolution.getMountId() != mountInfo.getMountId()) {
                // This mount point has changed. Further traversal is unnecessary.
                return false;
            }
            boolean existsInUfs;
            try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
                UnderFileSystem ufs = ufsResource.get();
                existsInUfs = ufs.exists(resolution.getUri().toString());
            }
            if (existsInUfs) {
                // This ufs path exists. Remove the cache entry.
                removeCacheEntry(alluxioUri.getPath());
            } else {
                // This is the first ufs path which does not exist. Add it to the cache.
                addCacheEntry(alluxioUri.getPath(), mountInfo);
                if (pathLock.isInvalidate()) {
                    // This path was marked to be invalidated, meaning this UFS path was just created,
                    // and now exists. Invalidate the entry.
                    // This check is necessary to avoid the race with the invalidating thread.
                    removeCacheEntry(alluxioUri.getPath());
                } else {
                    // Further traversal is unnecessary.
                    return false;
                }
            }
        }
    } catch (InvalidPathException | IOException e) {
        LOG.warn("Processing path failed: " + alluxioUri, e);
        return false;
    } finally {
        // Unlock the path
        if (readLock != null) {
            readLock.unlock();
        }
        if (writeLock != null) {
            mCurrentPaths.remove(alluxioUri.getPath(), pathLock);
            writeLock.unlock();
        }
    }
    return true;
}
Also used : IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 35 with InvalidPathException

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

the class AbstractFileSystem method delete.

/**
 * Attempts to delete the file or directory with the specified path.
 *
 * @param path path to delete
 * @param recursive if true, will attempt to delete all children of the path
 * @return true if one or more files/directories were deleted; false otherwise
 */
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
    LOG.debug("delete({}, {})", path, recursive);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = getAlluxioPath(path);
    DeletePOptions options = DeletePOptions.newBuilder().setRecursive(recursive).build();
    try {
        mFileSystem.delete(uri, options);
        return true;
    } catch (InvalidPathException | FileDoesNotExistException e) {
        LOG.debug("delete failed: {}", e.toString());
        return false;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeletePOptions(alluxio.grpc.DeletePOptions) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

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