From 7b795f6a7c768896a5e77146cf274d3661b680b2 Mon Sep 17 00:00:00 2001 From: Colin McCabe Date: Mon, 9 Jun 2014 18:40:00 +0000 Subject: [PATCH] HDFS-6257. TestCacheDirectives#testExceedsCapacity fails occasionally (cmccabe) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1601474 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../server/namenode/TestCacheDirectives.java | 35 ++++++++++++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 4ca3c67162e..708c0ac9ba5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -336,6 +336,9 @@ Release 2.5.0 - UNRELEASED HDFS-6500. Snapshot shouldn't be removed silently after renaming to an existing snapshot. (Nicholas SZE via junping_du) + HDFS-6257. TestCacheDirectives#testExceedsCapacity fails occasionally + (cmccabe) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java index ed124603f3d..8ef3887dd56 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java @@ -72,7 +72,9 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor; +import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList.Type; +import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.io.nativeio.NativeIO; @@ -1401,6 +1403,20 @@ public void testMaxRelativeExpiry() throws Exception { .build()); } + /** + * Check that the NameNode is not attempting to cache anything. + */ + private void checkPendingCachedEmpty(MiniDFSCluster cluster) + throws Exception { + final DatanodeManager datanodeManager = + cluster.getNamesystem().getBlockManager().getDatanodeManager(); + for (DataNode dn : cluster.getDataNodes()) { + DatanodeDescriptor descriptor = + datanodeManager.getDatanode(dn.getDatanodeId()); + Assert.assertTrue(descriptor.getPendingCached().isEmpty()); + } + } + @Test(timeout=60000) public void testExceedsCapacity() throws Exception { // Create a giant file @@ -1418,21 +1434,16 @@ public void testExceedsCapacity() throws Exception { .setPath(fileName).setReplication((short) 1).build()); waitForCachedBlocks(namenode, -1, numCachedReplicas, "testExceeds:1"); - // Check that no DNs saw an excess CACHE message - int lines = appender.countLinesWithMessage( - "more bytes in the cache: " + - DFSConfigKeys.DFS_DATANODE_MAX_LOCKED_MEMORY_KEY); - assertEquals("Namenode should not send extra CACHE commands", 0, lines); + checkPendingCachedEmpty(cluster); + Thread.sleep(1000); + checkPendingCachedEmpty(cluster); + // Try creating a file with giant-sized blocks that exceed cache capacity dfs.delete(fileName, false); DFSTestUtil.createFile(dfs, fileName, 4096, fileLen, CACHE_CAPACITY * 2, (short) 1, 0xFADED); - // Nothing will get cached, so just force sleep for a bit - Thread.sleep(4000); - // Still should not see any excess commands - lines = appender.countLinesWithMessage( - "more bytes in the cache: " + - DFSConfigKeys.DFS_DATANODE_MAX_LOCKED_MEMORY_KEY); - assertEquals("Namenode should not send extra CACHE commands", 0, lines); + checkPendingCachedEmpty(cluster); + Thread.sleep(1000); + checkPendingCachedEmpty(cluster); } }