/// <summary> /// Test that the NN initializes its under-replicated blocks queue /// before it is ready to exit safemode (HDFS-1476) /// </summary> /// <exception cref="System.Exception"/> public virtual void TestInitializeReplQueuesEarly() { Log.Info("Starting testInitializeReplQueuesEarly"); // Spray the blocks around the cluster when we add DNs instead of // concentrating all blocks on the first node. BlockManagerTestUtil.SetWritingPrefersLocalNode(cluster.GetNamesystem().GetBlockManager (), false); cluster.StartDataNodes(conf, 2, true, HdfsServerConstants.StartupOption.Regular, null); cluster.WaitActive(); Log.Info("Creating files"); DFSTestUtil.CreateFile(fs, TestPath, 15 * BlockSize, (short)1, 1L); Log.Info("Stopping all DataNodes"); IList <MiniDFSCluster.DataNodeProperties> dnprops = Lists.NewLinkedList(); dnprops.AddItem(cluster.StopDataNode(0)); dnprops.AddItem(cluster.StopDataNode(0)); dnprops.AddItem(cluster.StopDataNode(0)); cluster.GetConfiguration(0).SetFloat(DFSConfigKeys.DfsNamenodeReplQueueThresholdPctKey , 1f / 15f); Log.Info("Restarting NameNode"); cluster.RestartNameNode(); NameNode nn = cluster.GetNameNode(); string status = nn.GetNamesystem().GetSafemode(); NUnit.Framework.Assert.AreEqual("Safe mode is ON. The reported blocks 0 needs additional " + "15 blocks to reach the threshold 0.9990 of total blocks 15." + Newline + "The number of live datanodes 0 has reached the minimum number 0. " + "Safe mode will be turned off automatically once the thresholds " + "have been reached." , status); NUnit.Framework.Assert.IsFalse("Mis-replicated block queues should not be initialized " + "until threshold is crossed", NameNodeAdapter.SafeModeInitializedReplQueues(nn )); Log.Info("Restarting one DataNode"); cluster.RestartDataNode(dnprops.Remove(0)); // Wait for block reports from all attached storages of // the restarted DN to come in. GenericTestUtils.WaitFor(new _Supplier_214(this), 10, 10000); int safe = NameNodeAdapter.GetSafeModeSafeBlocks(nn); NUnit.Framework.Assert.IsTrue("Expected first block report to make some blocks safe." , safe > 0); NUnit.Framework.Assert.IsTrue("Did not expect first block report to make all blocks safe." , safe < 15); NUnit.Framework.Assert.IsTrue(NameNodeAdapter.SafeModeInitializedReplQueues(nn)); // Ensure that UnderReplicatedBlocks goes up to 15 - safe. Misreplicated // blocks are processed asynchronously so this may take a few seconds. // Failure here will manifest as a test timeout. BlockManagerTestUtil.UpdateState(nn.GetNamesystem().GetBlockManager()); long underReplicatedBlocks = nn.GetNamesystem().GetUnderReplicatedBlocks(); while (underReplicatedBlocks != (15 - safe)) { Log.Info("UnderReplicatedBlocks expected=" + (15 - safe) + ", actual=" + underReplicatedBlocks ); Sharpen.Thread.Sleep(100); BlockManagerTestUtil.UpdateState(nn.GetNamesystem().GetBlockManager()); underReplicatedBlocks = nn.GetNamesystem().GetUnderReplicatedBlocks(); } cluster.RestartDataNodes(); }