From 89a838769ff5b6c64565e6949b14d7fed05daf54 Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Fri, 15 Apr 2016 10:49:21 -0700 Subject: [PATCH] HDFS-10283. o.a.h.hdfs.server.namenode.TestFSImageWithSnapshot#testSaveLoadImageWithAppending fails intermittently. Contributed by Mingliang Liu. --- .../namenode/TestFSImageWithSnapshot.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java index 1904bbc122..6be39509c9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java @@ -47,6 +47,7 @@ import org.apache.hadoop.hdfs.util.Canceler; import org.apache.hadoop.test.GenericTestUtils; import org.apache.log4j.Level; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -62,7 +63,7 @@ public class TestFSImageWithSnapshot { } static final long seed = 0; - static final short REPLICATION = 3; + static final short NUM_DATANODES = 3; static final int BLOCKSIZE = 1024; static final long txid = 1; @@ -78,7 +79,7 @@ public class TestFSImageWithSnapshot { @Before public void setUp() throws Exception { conf = new Configuration(); - cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION) + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DATANODES) .build(); cluster.waitActive(); fsn = cluster.getNamesystem(); @@ -177,7 +178,7 @@ public void testSnapshotOnRoot() throws Exception { cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -188,7 +189,7 @@ public void testSnapshotOnRoot() throws Exception { hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -215,7 +216,7 @@ public void testSnapshotOnRoot() throws Exception { hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -248,20 +249,20 @@ public void testSaveLoadImage() throws Exception { hdfs.createSnapshot(dir, "s" + ++s); Path sub1file1 = new Path(sub1, "sub1file1"); Path sub1file2 = new Path(sub1, "sub1file2"); - DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, REPLICATION, seed); - DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, REPLICATION, seed); + DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, (short) 1, seed); + DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, (short) 1, seed); checkImage(s); hdfs.createSnapshot(dir, "s" + ++s); Path sub2 = new Path(dir, "sub2"); Path sub2file1 = new Path(sub2, "sub2file1"); Path sub2file2 = new Path(sub2, "sub2file2"); - DFSTestUtil.createFile(hdfs, sub2file1, BLOCKSIZE, REPLICATION, seed); - DFSTestUtil.createFile(hdfs, sub2file2, BLOCKSIZE, REPLICATION, seed); + DFSTestUtil.createFile(hdfs, sub2file1, BLOCKSIZE, (short) 1, seed); + DFSTestUtil.createFile(hdfs, sub2file2, BLOCKSIZE, (short) 1, seed); checkImage(s); hdfs.createSnapshot(dir, "s" + ++s); - hdfs.setReplication(sub1file1, (short) (REPLICATION - 1)); + hdfs.setReplication(sub1file1, (short) 1); hdfs.delete(sub1file2, true); hdfs.setOwner(sub2, "dr.who", "unknown"); hdfs.delete(sub2file1, true); @@ -300,7 +301,7 @@ void checkImage(int s) throws IOException { // restart the cluster, and format the cluster cluster = new MiniDFSCluster.Builder(conf).format(true) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -338,8 +339,8 @@ public void testSaveLoadImageWithAppending() throws Exception { Path sub1 = new Path(dir, "sub1"); Path sub1file1 = new Path(sub1, "sub1file1"); Path sub1file2 = new Path(sub1, "sub1file2"); - DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, REPLICATION, seed); - DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, REPLICATION, seed); + DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, (short) 1, seed); + DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, (short) 1, seed); // 1. create snapshot s0 hdfs.allowSnapshot(dir); @@ -372,7 +373,7 @@ public void testSaveLoadImageWithAppending() throws Exception { out.close(); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(true) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -394,8 +395,8 @@ public void testLoadImageWithAppending() throws Exception { Path sub1 = new Path(dir, "sub1"); Path sub1file1 = new Path(sub1, "sub1file1"); Path sub1file2 = new Path(sub1, "sub1file2"); - DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, REPLICATION, seed); - DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, REPLICATION, seed); + DFSTestUtil.createFile(hdfs, sub1file1, BLOCKSIZE, (short) 1, seed); + DFSTestUtil.createFile(hdfs, sub1file2, BLOCKSIZE, (short) 1, seed); hdfs.allowSnapshot(dir); hdfs.createSnapshot(dir, "s0"); @@ -410,7 +411,7 @@ public void testLoadImageWithAppending() throws Exception { cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem(); @@ -440,7 +441,7 @@ public void testLoadImageWithEmptyFile() throws Exception { // restart cluster cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); hdfs = cluster.getFileSystem(); @@ -478,7 +479,7 @@ public void testSaveLoadImageAfterSnapshotDeletion() Path newDir = new Path(subsubDir, "newdir"); Path newFile = new Path(newDir, "newfile"); hdfs.mkdirs(newDir); - DFSTestUtil.createFile(hdfs, newFile, BLOCKSIZE, REPLICATION, seed); + DFSTestUtil.createFile(hdfs, newFile, BLOCKSIZE, (short) 1, seed); // create another snapshot SnapshotTestHelper.createSnapshot(hdfs, dir, "s2"); @@ -491,7 +492,7 @@ public void testSaveLoadImageAfterSnapshotDeletion() // restart cluster cluster.shutdown(); - cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION) + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_DATANODES) .format(false).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); @@ -504,7 +505,7 @@ public void testSaveLoadImageAfterSnapshotDeletion() cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) - .numDataNodes(REPLICATION).build(); + .numDataNodes(NUM_DATANODES).build(); cluster.waitActive(); fsn = cluster.getNamesystem(); hdfs = cluster.getFileSystem();