/** * fake the rawblocks since map reduce uses the block offsets to * fo some computations regarding the blocks * @param rawBlocks the raw blocks returned by the filesystem * @return faked blocks with changed offsets. */ private BlockLocation[] fakeBlockLocations(BlockLocation[] rawBlocks, long startIndex) { for (BlockLocation block : rawBlocks) { long rawOffset = block.getOffset(); block.setOffset(rawOffset - startIndex); } return rawBlocks; }
@Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { try { CrailBlockLocation[] _locations = dfs.lookup(file.getPath().toUri().getRawPath()).get().asFile().getBlockLocations(start, len); BlockLocation[] locations = new BlockLocation[_locations.length]; for (int i = 0; i < locations.length; i++){ locations[i] = new BlockLocation(); locations[i].setOffset(_locations[i].getOffset()); locations[i].setLength(_locations[i].getLength()); locations[i].setNames(_locations[i].getNames()); locations[i].setHosts(_locations[i].getHosts()); locations[i].setTopologyPaths(_locations[i].getTopology()); } return locations; } catch(Exception e){ throw new IOException(e); } }
@Override public BlockLocation[] getFileBlockLocations(Path path, long start, long len) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException { try { CrailBlockLocation[] _locations = dfs.lookup(path.toUri().getRawPath()).get().asFile().getBlockLocations(start, len); BlockLocation[] locations = new BlockLocation[_locations.length]; for (int i = 0; i < locations.length; i++){ locations[i] = new BlockLocation(); locations[i].setOffset(_locations[i].getOffset()); locations[i].setLength(_locations[i].getLength()); locations[i].setNames(_locations[i].getNames()); locations[i].setHosts(_locations[i].getHosts()); locations[i].setTopologyPaths(_locations[i].getTopology()); } return locations; } catch(Exception e){ throw new IOException(e); } }
@Override public BlockLocation[] getFileBlockLocations(Path path, long start, long len) throws IOException { try { CrailBlockLocation[] _locations = dfs.lookup(path.toUri().getRawPath()).get().asFile().getBlockLocations(start, len); BlockLocation[] locations = new BlockLocation[_locations.length]; for (int i = 0; i < locations.length; i++){ locations[i] = new BlockLocation(); locations[i].setOffset(_locations[i].getOffset()); locations[i].setLength(_locations[i].getLength()); locations[i].setNames(_locations[i].getNames()); locations[i].setHosts(_locations[i].getHosts()); locations[i].setTopologyPaths(_locations[i].getTopology()); } return locations; } catch(Exception e){ throw new IOException(e); } }
@Override public BlockLocation[] getFileBlockLocations(Path path, long start, long len) throws IOException { try { statistics.incrementReadOps(1); CrailBlockLocation[] _locations = dfs.lookup(path.toUri().getRawPath()).get().asFile().getBlockLocations(start, len); BlockLocation[] locations = new BlockLocation[_locations.length]; for (int i = 0; i < locations.length; i++){ locations[i] = new BlockLocation(); locations[i].setOffset(_locations[i].getOffset()); locations[i].setLength(_locations[i].getLength()); locations[i].setNames(_locations[i].getNames()); locations[i].setHosts(_locations[i].getHosts()); locations[i].setTopologyPaths(_locations[i].getTopology()); } return locations; } catch(Exception e){ throw new IOException(e); } }
/** * Call each of the setters and verify */ @Test(timeout = 5000) public void testBlockLocationSetters() throws Exception { BlockLocation loc; loc = new BlockLocation(); // Test that null sets the empty array loc.setHosts(null); loc.setCachedHosts(null); loc.setNames(null); loc.setTopologyPaths(null); checkBlockLocation(loc); // Test that not-null gets set properly String[] names = new String[] { "name" }; String[] hosts = new String[] { "host" }; String[] cachedHosts = new String[] { "cachedHost" }; String[] topologyPaths = new String[] { "path" }; loc.setNames(names); loc.setHosts(hosts); loc.setCachedHosts(cachedHosts); loc.setTopologyPaths(topologyPaths); loc.setOffset(1); loc.setLength(2); loc.setCorrupt(true); checkBlockLocation(loc, names, hosts, cachedHosts, topologyPaths, 1, 2, true); } }
/** * Call each of the setters and verify */ @Test(timeout = 5000) public void testBlockLocationSetters() throws Exception { BlockLocation loc; loc = new BlockLocation(); // Test that null sets the empty array loc.setHosts(null); loc.setCachedHosts(null); loc.setNames(null); loc.setTopologyPaths(null); checkBlockLocation(loc); // Test that not-null gets set properly String[] names = new String[] { "name" }; String[] hosts = new String[] { "host" }; String[] cachedHosts = new String[] { "cachedHost" }; String[] topologyPaths = new String[] { "path" }; loc.setNames(names); loc.setHosts(hosts); loc.setCachedHosts(cachedHosts); loc.setTopologyPaths(topologyPaths); loc.setOffset(1); loc.setLength(2); loc.setCorrupt(true); checkBlockLocation(loc, names, hosts, cachedHosts, topologyPaths, 1, 2, true); } }