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