use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method activeSyncMetadata.
/**
* Actively sync metadata, based on a list of changed files.
*
* @param path the path to sync
* @param changedFiles collection of files that are changed under the path to sync, if this is
* null, force sync the entire directory
* @param executorService executor to execute the parallel incremental sync
*/
public void activeSyncMetadata(AlluxioURI path, Collection<AlluxioURI> changedFiles, ExecutorService executorService) throws IOException {
if (changedFiles == null) {
LOG.info("Start an active full sync of {}", path.toString());
} else {
LOG.info("Start an active incremental sync of {} files", changedFiles.size());
}
long start = System.currentTimeMillis();
if (changedFiles != null && changedFiles.isEmpty()) {
return;
}
try (RpcContext rpcContext = createRpcContext()) {
if (changedFiles == null) {
// full sync
// Set sync interval to 0 to force a sync.
FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
LockingScheme scheme = createSyncLockingScheme(path, options, false);
InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ALL, options, false, false, false, false);
if (sync.sync().equals(FAILED)) {
LOG.debug("Active full sync on {} didn't sync any paths.", path);
}
long end = System.currentTimeMillis();
LOG.info("Ended an active full sync of {} in {}ms", path.toString(), end - start);
return;
} else {
// incremental sync
Set<Callable<Void>> callables = new HashSet<>();
for (AlluxioURI changedFile : changedFiles) {
callables.add(() -> {
// Set sync interval to 0 to force a sync.
FileSystemMasterCommonPOptions options = FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build();
LockingScheme scheme = createSyncLockingScheme(changedFile, options, false);
InodeSyncStream sync = new InodeSyncStream(scheme, this, rpcContext, DescendantType.ONE, options, false, false, false, false);
if (sync.sync().equals(FAILED)) {
// Use debug because this can be a noisy log
LOG.debug("Incremental sync on {} didn't sync any paths.", path);
}
return null;
});
}
executorService.invokeAll(callables);
}
} catch (InterruptedException e) {
LOG.warn("InterruptedException during active sync: {}", e.toString());
Thread.currentThread().interrupt();
return;
} catch (InvalidPathException | AccessControlException e) {
LogUtils.warnWithException(LOG, "Failed to active sync on path {}", path, e);
}
if (changedFiles != null) {
long end = System.currentTimeMillis();
LOG.info("Ended an active incremental sync of {} files in {}ms", changedFiles.size(), end - start);
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method scheduleAsyncPersistenceInternal.
private void scheduleAsyncPersistenceInternal(LockedInodePath inodePath, ScheduleAsyncPersistenceContext context, RpcContext rpcContext) throws InvalidPathException, FileDoesNotExistException {
InodeFile inode = inodePath.getInodeFile();
if (!inode.isCompleted()) {
throw new InvalidPathException("Cannot persist an incomplete Alluxio file: " + inodePath.getUri());
}
if (shouldPersistPath(inodePath.toString())) {
mInodeTree.updateInode(rpcContext, UpdateInodeEntry.newBuilder().setId(inode.getId()).setPersistenceState(PersistenceState.TO_BE_PERSISTED.name()).build());
mPersistRequests.put(inode.getId(), new alluxio.time.ExponentialTimer(ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_INITIAL_INTERVAL_MS), ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_MAX_INTERVAL_MS), context.getPersistenceWaitTime(), ServerConfiguration.getMs(PropertyKey.MASTER_PERSISTENCE_MAX_TOTAL_WAIT_TIME_MS)));
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class DefaultFileSystemMaster method listStatusInternal.
/**
* Lists the status of the path in {@link LockedInodePath}, possibly recursively depending on the
* descendantType. The result is returned via a list specified by statusList, in postorder
* traversal order.
*
* @param context call context
* @param rpcContext the context for the RPC call
* @param currInodePath the inode path to find the status
* @param auditContext the audit context to return any access exceptions
* @param descendantType if the currInodePath is a directory, how many levels of its descendant
* should be returned
* @param resultStream the stream to receive individual results
* @param depth internal use field for tracking depth relative to root item
*/
private void listStatusInternal(ListStatusContext context, RpcContext rpcContext, LockedInodePath currInodePath, AuditContext auditContext, DescendantType descendantType, ResultStream<FileInfo> resultStream, int depth, Counter counter) throws FileDoesNotExistException, UnavailableException, AccessControlException, InvalidPathException {
rpcContext.throwIfCancelled();
Inode inode = currInodePath.getInode();
if (inode.isDirectory() && descendantType != DescendantType.NONE) {
try {
// TODO(david): Return the error message when we do not have permission
mPermissionChecker.checkPermission(Mode.Bits.EXECUTE, currInodePath);
} catch (AccessControlException e) {
auditContext.setAllowed(false);
if (descendantType == DescendantType.ALL) {
return;
} else {
throw e;
}
}
mAccessTimeUpdater.updateAccessTime(rpcContext.getJournalContext(), inode, CommonUtils.getCurrentMs());
DescendantType nextDescendantType = (descendantType == DescendantType.ALL) ? DescendantType.ALL : DescendantType.NONE;
// This is to generate a parsed child path components to be passed to lockChildPath
String[] childComponentsHint = null;
for (Inode child : mInodeStore.getChildren(inode.asDirectory())) {
if (childComponentsHint == null) {
String[] parentComponents = PathUtils.getPathComponents(currInodePath.getUri().getPath());
childComponentsHint = new String[parentComponents.length + 1];
System.arraycopy(parentComponents, 0, childComponentsHint, 0, parentComponents.length);
}
// TODO(david): Make extending InodePath more efficient
childComponentsHint[childComponentsHint.length - 1] = child.getName();
try (LockedInodePath childInodePath = currInodePath.lockChild(child, LockPattern.READ, childComponentsHint)) {
listStatusInternal(context, rpcContext, childInodePath, auditContext, nextDescendantType, resultStream, depth + 1, counter);
} catch (InvalidPathException | FileDoesNotExistException e) {
LOG.debug("Path \"{}\" is invalid, has been ignored.", PathUtils.concatPath("/", childComponentsHint));
}
}
}
// Listing a directory should not emit item for the directory itself.
if (depth != 0 || inode.isFile()) {
resultStream.submit(getFileInfoInternal(currInodePath, counter));
}
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class BaseFileSystem method createFile.
@Override
public FileOutStream createFile(AlluxioURI path, CreateFilePOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException {
checkUri(path);
return rpc(client -> {
CreateFilePOptions mergedOptions = FileSystemOptions.createFileDefaults(mFsContext.getPathConf(path)).toBuilder().mergeFrom(options).build();
URIStatus status = client.createFile(path, mergedOptions);
LOG.debug("Created file {}, options: {}", path.getPath(), mergedOptions);
OutStreamOptions outStreamOptions = new OutStreamOptions(mergedOptions, mFsContext.getClientContext(), mFsContext.getPathConf(path));
outStreamOptions.setUfsPath(status.getUfsPath());
outStreamOptions.setMountId(status.getMountId());
outStreamOptions.setAcl(status.getAcl());
try {
return new AlluxioFileOutStream(path, outStreamOptions, mFsContext);
} catch (Exception e) {
delete(path);
throw e;
}
});
}
use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.
the class InodeTree method lockInodePathById.
/**
* Locks existing inodes on the path to the inode specified by an id, in the specified
* {@link LockPattern}. The target inode must exist. This may require multiple traversals of the
* tree, so may be inefficient.
*
* @param id the inode id
* @param lockPattern the {@link LockPattern} to lock the inodes with
* @return the {@link LockedInodePath} representing the locked path of inodes
* @throws FileDoesNotExistException if the target inode does not exist
*/
private LockedInodePath lockInodePathById(long id, LockPattern lockPattern) throws FileDoesNotExistException {
int count = 0;
while (true) {
Optional<Inode> inode = mInodeStore.get(id);
if (!inode.isPresent()) {
throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST.getMessage(id));
}
// Compute the path given the target inode.
StringBuilder builder = new StringBuilder();
computePathForInode(inode.get(), builder);
AlluxioURI uri = new AlluxioURI(builder.toString());
boolean valid = false;
LockedInodePath inodePath = null;
try {
inodePath = lockInodePath(uri, lockPattern);
if (inodePath.getInode().getId() == id) {
// Set to true, so the path is not unlocked before returning.
valid = true;
return inodePath;
}
// The path does not end up at the target inode id. Repeat the traversal.
} catch (InvalidPathException e) {
// ignore and repeat the loop
LOG.debug("Inode lookup id {} computed path {} mismatch id. Repeating.", id, uri);
} finally {
if (!valid && inodePath != null) {
inodePath.close();
}
}
count++;
if (count > PATH_TRAVERSAL_RETRIES) {
throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST_RETRIES.getMessage(id));
}
}
}
Aggregations