Java Code Examples for org.apache.hadoop.fs.BlockLocation#getCachedHosts()
The following examples show how to use
org.apache.hadoop.fs.BlockLocation#getCachedHosts() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCacheDirectives.java From hadoop with Apache License 2.0 | 5 votes |
private static void checkNumCachedReplicas(final DistributedFileSystem dfs, final List<Path> paths, final int expectedBlocks, final int expectedReplicas) throws Exception { int numCachedBlocks = 0; int numCachedReplicas = 0; for (Path p: paths) { final FileStatus f = dfs.getFileStatus(p); final long len = f.getLen(); final long blockSize = f.getBlockSize(); // round it up to full blocks final long numBlocks = (len + blockSize - 1) / blockSize; BlockLocation[] locs = dfs.getFileBlockLocations(p, 0, len); assertEquals("Unexpected number of block locations for path " + p, numBlocks, locs.length); for (BlockLocation l: locs) { if (l.getCachedHosts().length > 0) { numCachedBlocks++; } numCachedReplicas += l.getCachedHosts().length; } } LOG.info("Found " + numCachedBlocks + " of " + expectedBlocks + " blocks"); LOG.info("Found " + numCachedReplicas + " of " + expectedReplicas + " replicas"); assertEquals("Unexpected number of cached blocks", expectedBlocks, numCachedBlocks); assertEquals("Unexpected number of cached replicas", expectedReplicas, numCachedReplicas); }
Example 2
Source File: Main.java From hdfs-metadata with GNU General Public License v3.0 | 5 votes |
private void printBlockMetadata(BlockLocation blockLocation, String[] dataDirs) throws IOException { System.out.println(" Offset: " + blockLocation.getOffset()); System.out.println(" Length: " + blockLocation.getLength()); String[] cachedHosts = blockLocation.getCachedHosts(); if (cachedHosts.length == 0) { System.out.println(" No cached hosts"); } System.out.println(" Replicas:"); VolumeId[] volumeIds = blockLocation instanceof BlockStorageLocation ? (((BlockStorageLocation) blockLocation).getVolumeIds()) : null; String[] hosts = blockLocation.getHosts(); String[] names = blockLocation.getNames(); String[] topologyPaths = blockLocation.getTopologyPaths(); for (int i = 0; i < topologyPaths.length; i++) { int diskId = volumeIds != null ? DistributedFileSystemMetadata.getDiskId(volumeIds[i]) : -1; System.out.println(" Replica (" + i + "):"); System.out.println(" Host: " + hosts[i]); if(diskId == -1) System.out.println(" DiskId: unknown"); else if(dataDirs != null && diskId < dataDirs.length) System.out.println(" Location: " + dataDirs[diskId] + " (DiskId: " + diskId + ")"); else System.out.println(" DiskId: " + diskId); System.out.println(" Name: " + names[i]); System.out.println(" TopologyPaths: " + topologyPaths[i]); } if (cachedHosts.length > 0) { System.out.println(" Cached hosts:"); for (String cachedHost : cachedHosts) { System.out.println(" Host: " + cachedHost); } } }
Example 3
Source File: TestCacheDirectives.java From big-c with Apache License 2.0 | 5 votes |
private static void checkNumCachedReplicas(final DistributedFileSystem dfs, final List<Path> paths, final int expectedBlocks, final int expectedReplicas) throws Exception { int numCachedBlocks = 0; int numCachedReplicas = 0; for (Path p: paths) { final FileStatus f = dfs.getFileStatus(p); final long len = f.getLen(); final long blockSize = f.getBlockSize(); // round it up to full blocks final long numBlocks = (len + blockSize - 1) / blockSize; BlockLocation[] locs = dfs.getFileBlockLocations(p, 0, len); assertEquals("Unexpected number of block locations for path " + p, numBlocks, locs.length); for (BlockLocation l: locs) { if (l.getCachedHosts().length > 0) { numCachedBlocks++; } numCachedReplicas += l.getCachedHosts().length; } } LOG.info("Found " + numCachedBlocks + " of " + expectedBlocks + " blocks"); LOG.info("Found " + numCachedReplicas + " of " + expectedReplicas + " replicas"); assertEquals("Unexpected number of cached blocks", expectedBlocks, numCachedBlocks); assertEquals("Unexpected number of cached replicas", expectedReplicas, numCachedReplicas); }