From e332e011ae6c350ee6b78c25bc4c302681775334 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Fri, 11 May 2018 09:47:57 -0700 Subject: [PATCH] HDFS-13542. TestBlockManager#testNeededReplicationWhileAppending fails due to improper cluster shutdown in TestBlockManager#testBlockManagerMachinesArray on Windows. Contributed by Anbang Hu. (cherry picked from commit d50c4d71dc42576f96ae5c268856fd1a7795f936) --- .../blockmanagement/TestBlockManager.java | 153 ++++++++++-------- 1 file changed, 84 insertions(+), 69 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java index 5219a44994f..58ca2e3d598 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java @@ -452,8 +452,8 @@ public class TestBlockManager { String src = "/test-file"; Path file = new Path(src); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); - cluster.waitActive(); try { + cluster.waitActive(); BlockManager bm = cluster.getNamesystem().getBlockManager(); FileSystem fs = cluster.getFileSystem(); NamenodeProtocols namenode = cluster.getNameNodeRpc(); @@ -492,7 +492,9 @@ public class TestBlockManager { IOUtils.closeStream(out); } } finally { - cluster.shutdown(); + if (cluster != null) { + cluster.shutdown(); + } } } @@ -1043,7 +1045,9 @@ public class TestBlockManager { assertTrue(fs.exists(file1)); fs.delete(file1, true); assertTrue(!fs.exists(file1)); - cluster.shutdown(); + if (cluster != null) { + cluster.shutdown(); + } } } @@ -1143,7 +1147,9 @@ public class TestBlockManager { assertEquals(0, bm.getBlockOpQueueLength()); assertTrue(doneLatch.await(1, TimeUnit.SECONDS)); } finally { - cluster.shutdown(); + if (cluster != null) { + cluster.shutdown(); + } } } @@ -1218,7 +1224,9 @@ public class TestBlockManager { long batched = MetricsAsserts.getLongCounter("BlockOpsBatched", rb); assertTrue(batched > 0); } finally { - cluster.shutdown(); + if (cluster != null) { + cluster.shutdown(); + } } } @@ -1227,76 +1235,83 @@ public class TestBlockManager { final Configuration conf = new HdfsConfiguration(); final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); - cluster.waitActive(); - BlockManager blockManager = cluster.getNamesystem().getBlockManager(); - FileSystem fs = cluster.getFileSystem(); - final Path filePath = new Path("/tmp.txt"); - final long fileLen = 1L; - DFSTestUtil.createFile(fs, filePath, fileLen, (short) 3, 1L); - DFSTestUtil.waitForReplication((DistributedFileSystem)fs, - filePath, (short) 3, 60000); - ArrayList datanodes = cluster.getDataNodes(); - assertEquals(datanodes.size(), 4); - FSNamesystem ns = cluster.getNamesystem(); - // get the block - final String bpid = cluster.getNamesystem().getBlockPoolId(); - File storageDir = cluster.getInstanceStorageDir(0, 0); - File dataDir = MiniDFSCluster.getFinalizedDir(storageDir, bpid); - assertTrue("Data directory does not exist", dataDir.exists()); - BlockInfo blockInfo = blockManager.blocksMap.getBlocks().iterator().next(); - ExtendedBlock blk = new ExtendedBlock(bpid, blockInfo.getBlockId(), - blockInfo.getNumBytes(), blockInfo.getGenerationStamp()); - DatanodeDescriptor failedStorageDataNode = - blockManager.getStoredBlock(blockInfo).getDatanode(0); - DatanodeDescriptor corruptStorageDataNode = - blockManager.getStoredBlock(blockInfo).getDatanode(1); + try { + cluster.waitActive(); + BlockManager blockManager = cluster.getNamesystem().getBlockManager(); + FileSystem fs = cluster.getFileSystem(); + final Path filePath = new Path("/tmp.txt"); + final long fileLen = 1L; + DFSTestUtil.createFile(fs, filePath, fileLen, (short) 3, 1L); + DFSTestUtil.waitForReplication((DistributedFileSystem)fs, + filePath, (short) 3, 60000); + ArrayList datanodes = cluster.getDataNodes(); + assertEquals(datanodes.size(), 4); + FSNamesystem ns = cluster.getNamesystem(); + // get the block + final String bpid = cluster.getNamesystem().getBlockPoolId(); + File storageDir = cluster.getInstanceStorageDir(0, 0); + File dataDir = MiniDFSCluster.getFinalizedDir(storageDir, bpid); + assertTrue("Data directory does not exist", dataDir.exists()); + BlockInfo blockInfo = + blockManager.blocksMap.getBlocks().iterator().next(); + ExtendedBlock blk = new ExtendedBlock(bpid, blockInfo.getBlockId(), + blockInfo.getNumBytes(), blockInfo.getGenerationStamp()); + DatanodeDescriptor failedStorageDataNode = + blockManager.getStoredBlock(blockInfo).getDatanode(0); + DatanodeDescriptor corruptStorageDataNode = + blockManager.getStoredBlock(blockInfo).getDatanode(1); - ArrayList reports = new ArrayList(); - for(int i=0; i reports = new ArrayList(); + for(int i=0; i