/** * Checks the consistency of Alluxio metadata against the under storage for all files and * directories in a given subtree. * * @param fsContext the {@link FileSystemContext} linked to the {@link FileSystem} client * @param path the root of the subtree to check * @param options method options * @return a list of inconsistent files and directories */ public static List<AlluxioURI> checkConsistency(FileSystemContext fsContext, AlluxioURI path, CheckConsistencyPOptions options) throws IOException { FileSystemMasterClient client = fsContext.acquireMasterClient(); try { return client.checkConsistency(path, options); } finally { fsContext.releaseMasterClient(client); } } }
/** * Verifies and releases the master client after a test with a filesystem operation. */ public void verifyFilesystemContextAcquiredAndReleased() { verify(mFileContext).acquireMasterClient(); verify(mFileContext).releaseMasterClient(mFileSystemMasterClient); }
@Override public void run() { FileSystemMasterClient client = mFsCtx.acquireMasterClient(); mFsCtx.releaseMasterClient(client); } }
@Override public Map<String, MountPointInfo> getMountTable() throws IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { return masterClient.getMountTable(); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public List<SyncPointInfo> getSyncPathList() throws IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { return masterClient.getSyncPathList(); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void unmount(AlluxioURI path, UnmountPOptions options) throws IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.unmount(path); LOG.debug("Unmounted {}, options: {}", path.getPath(), options); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void mount(AlluxioURI alluxioPath, AlluxioURI ufsPath, MountPOptions options) throws IOException, AlluxioException { checkUri(alluxioPath); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { // TODO(calvin): Make this fail on the master side masterClient.mount(alluxioPath, ufsPath, options); LOG.info("Mount " + ufsPath.toString() + " to " + alluxioPath.getPath()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Persists the given file to the under file system. * * @param fs {@link FileSystem} to carry out Alluxio operations * @param fsContext the {@link FileSystemContext} linked to the {@link FileSystem} client * @param uri the uri of the file to persist */ public static void persistFile(final FileSystem fs, final FileSystemContext fsContext, final AlluxioURI uri) throws IOException, TimeoutException, InterruptedException { FileSystemMasterClient client = fsContext.acquireMasterClient(); try { client.scheduleAsyncPersist(uri); } finally { fsContext.releaseMasterClient(client); } CommonUtils.waitFor(String.format("%s to be persisted", uri) , () -> { try { return fs.getStatus(uri).isPersisted(); } catch (Exception e) { Throwables.propagateIfPossible(e); throw new RuntimeException(e); } }, WaitForOptions.defaults().setTimeoutMs(20 * Constants.MINUTE_MS) .setInterval(Constants.SECOND_MS)); }
/** * Starts the active syncing process on an Alluxio path. * * @param path the path to sync */ @Override public void startSync(AlluxioURI path) throws FileDoesNotExistException, IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.startSync(path); LOG.debug("Start syncing for {}", path.getPath()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Stops the active syncing process on an Alluxio path. * @param path the path to stop syncing */ @Override public void stopSync(AlluxioURI path) throws FileDoesNotExistException, IOException, AlluxioException { FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.stopSync(path); LOG.debug("Stop syncing for {}", path.getPath()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void free(AlluxioURI path, FreePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.free(path, options); LOG.debug("Freed {}, options: {}", path.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void setAcl(AlluxioURI path, SetAclAction action, List<AclEntry> entries, SetAclPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.setAcl(path, action, entries, options); LOG.debug("Set ACL for {}, entries: {} options: {}", path.getPath(), entries, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void setAttribute(AlluxioURI path, SetAttributePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.setAttribute(path, options); LOG.debug("Set attributes for {}, options: {}", path.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public boolean exists(AlluxioURI path, ExistsPOptions options) throws InvalidPathException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { // TODO(calvin): Make this more efficient masterClient.getStatus(path, GrpcUtils.toGetStatusOptions(options)); return true; } catch (NotFoundException e) { return false; } catch (InvalidArgumentException e) { // The server will throw this when a prefix of the path is a file. // TODO(andrew): Change the server so that a prefix being a file means the path does not exist return false; } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public URIStatus getStatus(AlluxioURI path, GetStatusPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { return masterClient.getStatus(path, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); // TODO(calvin): Fix the exception handling in the master try { return masterClient.listStatus(path, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void delete(AlluxioURI path, DeletePOptions options) throws DirectoryNotEmptyException, FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.delete(path, options); LOG.debug("Deleted {}, options: {}", path.getPath(), options); } catch (FailedPreconditionException e) { // A little sketchy, but this should be the only case that throws FailedPrecondition. throw new DirectoryNotEmptyException(e.getMessage()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void rename(AlluxioURI src, AlluxioURI dst, RenamePOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(src); checkUri(dst); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { // TODO(calvin): Update this code on the master side. masterClient.rename(src, dst, options); LOG.debug("Renamed {} to {}, options: {}", src.getPath(), dst.getPath(), options); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
@Override public void createDirectory(AlluxioURI path, CreateDirectoryPOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.createDirectory(path, options); LOG.debug("Created directory {}, options: {}", path.getPath(), options); } catch (AlreadyExistsException e) { throw new FileAlreadyExistsException(e.getMessage()); } catch (InvalidArgumentException e) { throw new InvalidPathException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient);