Java Code Examples for org.apache.hadoop.hdfs.DFSTestUtil#waitCorruptReplicas()
The following examples show how to use
org.apache.hadoop.hdfs.DFSTestUtil#waitCorruptReplicas() .
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: TestFsck.java From hadoop with Apache License 2.0 | 4 votes |
/** * Test for blockIdCK with block corruption */ @Test public void testBlockIdCKCorruption() throws Exception { short NUM_DN = 1; final long blockSize = 512; Random random = new Random(); DFSClient dfsClient; LocatedBlocks blocks; ExtendedBlock block; short repFactor = 1; String [] racks = {"/rack1"}; String [] hosts = {"host1"}; Configuration conf = new Configuration(); conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000); // Set short retry timeouts so this test runs faster conf.setInt(DFSConfigKeys.DFS_CLIENT_RETRY_WINDOW_BASE, 10); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); MiniDFSCluster cluster = null; DistributedFileSystem dfs = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DN).hosts(hosts) .racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); cluster.waitClusterUp(); dfs = cluster.getFileSystem(); assertNotNull("Failed to get FileSystem", dfs); DFSTestUtil util = new DFSTestUtil.Builder(). setName(getClass().getSimpleName()).setNumFiles(1).build(); //create files final String pathString = new String("/testfile"); final Path path = new Path(pathString); util.createFile(dfs, path, 1024, repFactor, 1000L); util.waitReplication(dfs, path, repFactor); StringBuilder sb = new StringBuilder(); for (LocatedBlock lb: util.getAllBlocks(dfs, path)){ sb.append(lb.getBlock().getLocalBlock().getBlockName()+" "); } String[] bIds = sb.toString().split(" "); //make sure block is healthy before we corrupt it String outStr = runFsck(conf, 0, true, "/", "-blockId", bIds[0]); System.out.println(outStr); assertTrue(outStr.contains(NamenodeFsck.HEALTHY_STATUS)); // corrupt replicas block = DFSTestUtil.getFirstBlock(dfs, path); File blockFile = cluster.getBlockFile(0, block); if (blockFile != null && blockFile.exists()) { RandomAccessFile raFile = new RandomAccessFile(blockFile, "rw"); FileChannel channel = raFile.getChannel(); String badString = "BADBAD"; int rand = random.nextInt((int) channel.size()/2); raFile.seek(rand); raFile.write(badString.getBytes()); raFile.close(); } util.waitCorruptReplicas(dfs, cluster.getNamesystem(), path, block, 1); outStr = runFsck(conf, 1, false, "/", "-blockId", block.getBlockName()); System.out.println(outStr); assertTrue(outStr.contains(NamenodeFsck.CORRUPT_STATUS)); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 2
Source File: TestBlocksWithNotEnoughRacks.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testCorruptBlockRereplicatedAcrossRacks() throws Exception { Configuration conf = getConf(); short REPLICATION_FACTOR = 2; int fileLen = 512; final Path filePath = new Path("/testFile"); // Datanodes are spread across two racks String racks[] = {"/rack1", "/rack1", "/rack2", "/rack2"}; MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(racks.length).racks(racks).build(); final FSNamesystem ns = cluster.getNameNode().getNamesystem(); try { // Create a file with one block with a replication factor of 2 final FileSystem fs = cluster.getFileSystem(); DFSTestUtil.createFile(fs, filePath, fileLen, REPLICATION_FACTOR, 1L); final String fileContent = DFSTestUtil.readFile(fs, filePath); ExtendedBlock b = DFSTestUtil.getFirstBlock(fs, filePath); DFSTestUtil.waitForReplication(cluster, b, 2, REPLICATION_FACTOR, 0); // Corrupt a replica of the block int dnToCorrupt = DFSTestUtil.firstDnWithBlock(cluster, b); assertTrue(cluster.corruptReplica(dnToCorrupt, b)); // Restart the datanode so blocks are re-scanned, and the corrupt // block is detected. cluster.restartDataNode(dnToCorrupt); // Wait for the namenode to notice the corrupt replica DFSTestUtil.waitCorruptReplicas(fs, ns, filePath, b, 1); // The rack policy is still respected DFSTestUtil.waitForReplication(cluster, b, 2, REPLICATION_FACTOR, 0); // Ensure all replicas are valid (the corrupt replica may not // have been cleaned up yet). for (int i = 0; i < racks.length; i++) { String blockContent = cluster.readBlockOnDataNode(i, b); if (blockContent != null && i != dnToCorrupt) { assertEquals("Corrupt replica", fileContent, blockContent); } } } finally { cluster.shutdown(); } }
Example 3
Source File: TestFsck.java From big-c with Apache License 2.0 | 4 votes |
/** * Test for blockIdCK with block corruption */ @Test public void testBlockIdCKCorruption() throws Exception { short NUM_DN = 1; final long blockSize = 512; Random random = new Random(); DFSClient dfsClient; LocatedBlocks blocks; ExtendedBlock block; short repFactor = 1; String [] racks = {"/rack1"}; String [] hosts = {"host1"}; Configuration conf = new Configuration(); conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000); // Set short retry timeouts so this test runs faster conf.setInt(DFSConfigKeys.DFS_CLIENT_RETRY_WINDOW_BASE, 10); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); MiniDFSCluster cluster = null; DistributedFileSystem dfs = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DN).hosts(hosts) .racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); cluster.waitClusterUp(); dfs = cluster.getFileSystem(); assertNotNull("Failed to get FileSystem", dfs); DFSTestUtil util = new DFSTestUtil.Builder(). setName(getClass().getSimpleName()).setNumFiles(1).build(); //create files final String pathString = new String("/testfile"); final Path path = new Path(pathString); util.createFile(dfs, path, 1024, repFactor, 1000L); util.waitReplication(dfs, path, repFactor); StringBuilder sb = new StringBuilder(); for (LocatedBlock lb: util.getAllBlocks(dfs, path)){ sb.append(lb.getBlock().getLocalBlock().getBlockName()+" "); } String[] bIds = sb.toString().split(" "); //make sure block is healthy before we corrupt it String outStr = runFsck(conf, 0, true, "/", "-blockId", bIds[0]); System.out.println(outStr); assertTrue(outStr.contains(NamenodeFsck.HEALTHY_STATUS)); // corrupt replicas block = DFSTestUtil.getFirstBlock(dfs, path); File blockFile = cluster.getBlockFile(0, block); if (blockFile != null && blockFile.exists()) { RandomAccessFile raFile = new RandomAccessFile(blockFile, "rw"); FileChannel channel = raFile.getChannel(); String badString = "BADBAD"; int rand = random.nextInt((int) channel.size()/2); raFile.seek(rand); raFile.write(badString.getBytes()); raFile.close(); } util.waitCorruptReplicas(dfs, cluster.getNamesystem(), path, block, 1); outStr = runFsck(conf, 1, false, "/", "-blockId", block.getBlockName()); System.out.println(outStr); assertTrue(outStr.contains(NamenodeFsck.CORRUPT_STATUS)); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 4
Source File: TestBlocksWithNotEnoughRacks.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testCorruptBlockRereplicatedAcrossRacks() throws Exception { Configuration conf = getConf(); short REPLICATION_FACTOR = 2; int fileLen = 512; final Path filePath = new Path("/testFile"); // Datanodes are spread across two racks String racks[] = {"/rack1", "/rack1", "/rack2", "/rack2"}; MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(racks.length).racks(racks).build(); final FSNamesystem ns = cluster.getNameNode().getNamesystem(); try { // Create a file with one block with a replication factor of 2 final FileSystem fs = cluster.getFileSystem(); DFSTestUtil.createFile(fs, filePath, fileLen, REPLICATION_FACTOR, 1L); final String fileContent = DFSTestUtil.readFile(fs, filePath); ExtendedBlock b = DFSTestUtil.getFirstBlock(fs, filePath); DFSTestUtil.waitForReplication(cluster, b, 2, REPLICATION_FACTOR, 0); // Corrupt a replica of the block int dnToCorrupt = DFSTestUtil.firstDnWithBlock(cluster, b); assertTrue(cluster.corruptReplica(dnToCorrupt, b)); // Restart the datanode so blocks are re-scanned, and the corrupt // block is detected. cluster.restartDataNode(dnToCorrupt); // Wait for the namenode to notice the corrupt replica DFSTestUtil.waitCorruptReplicas(fs, ns, filePath, b, 1); // The rack policy is still respected DFSTestUtil.waitForReplication(cluster, b, 2, REPLICATION_FACTOR, 0); // Ensure all replicas are valid (the corrupt replica may not // have been cleaned up yet). for (int i = 0; i < racks.length; i++) { String blockContent = cluster.readBlockOnDataNode(i, b); if (blockContent != null && i != dnToCorrupt) { assertEquals("Corrupt replica", fileContent, blockContent); } } } finally { cluster.shutdown(); } }