@Override public List<String> getFileLocations(String path) throws IOException { return getFileLocations(path, FileLocationOptions.defaults()); }
@Override public List<String> get(long blockId, AlluxioURI fileUri, long offset) { List<String> locations = mCache.getIfPresent(blockId); if (locations != null) { return locations; } try { MountTable.Resolution resolution = mMountTable.resolve(fileUri); String ufsUri = resolution.getUri().toString(); try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); locations = ufs.getFileLocations(ufsUri, FileLocationOptions.defaults().setOffset(offset)); } if (locations != null) { mCache.put(blockId, locations); return locations; } } catch (InvalidPathException | IOException e) { LOG.warn("Failed to get locations for block {} in file {} with offset {}: {}", blockId, fileUri, offset, e); } return null; } }
/** * Tests for default {@link FileLocationOptions}. */ @Test public void defaults() throws IOException { FileLocationOptions options = FileLocationOptions.defaults(); Assert.assertEquals(0, options.getOffset()); }
/** * Tests getting and setting fields. */ @Test public void fields() { FileLocationOptions options = FileLocationOptions.defaults(); long[] offsets = {100, 110, 150, 200}; for (long offset : offsets) { options.setOffset(offset); Assert.assertEquals(offset, options.getOffset()); } }
@Override public List<String> getFileLocations(String path) throws IOException { return getFileLocations(path, FileLocationOptions.defaults()); }
@Override public List<String> get(long blockId, AlluxioURI fileUri, long offset) { List<String> locations = mCache.getIfPresent(blockId); if (locations != null) { return locations; } try { MountTable.Resolution resolution = mMountTable.resolve(fileUri); String ufsUri = resolution.getUri().toString(); try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); locations = ufs.getFileLocations(ufsUri, FileLocationOptions.defaults().setOffset(offset)); } if (locations != null) { mCache.put(blockId, locations); return locations; } } catch (InvalidPathException | IOException e) { LOG.warn("Failed to get locations for block {} in file {} with offset {}: {}", blockId, fileUri, offset, e); } return null; } }