/// <summary> /// Make sure that clients will receive StandbyExceptions even when a /// checkpoint is in progress on the SBN, and therefore the StandbyCheckpointer /// thread will have FSNS lock. /// </summary> /// <remarks> /// Make sure that clients will receive StandbyExceptions even when a /// checkpoint is in progress on the SBN, and therefore the StandbyCheckpointer /// thread will have FSNS lock. Regression test for HDFS-4591. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestStandbyExceptionThrownDuringCheckpoint() { // Set it up so that we know when the SBN checkpoint starts and ends. FSImage spyImage1 = NameNodeAdapter.SpyOnFsImage(nn1); GenericTestUtils.DelayAnswer answerer = new GenericTestUtils.DelayAnswer(Log); Org.Mockito.Mockito.DoAnswer(answerer).When(spyImage1).SaveNamespace(Org.Mockito.Mockito .Any <FSNamesystem>(), Org.Mockito.Mockito.Eq(NNStorage.NameNodeFile.Image), Org.Mockito.Mockito .Any <Canceler>()); // Perform some edits and wait for a checkpoint to start on the SBN. DoEdits(0, 1000); nn0.GetRpcServer().RollEditLog(); answerer.WaitForCall(); NUnit.Framework.Assert.IsTrue("SBN is not performing checkpoint but it should be." , answerer.GetFireCount() == 1 && answerer.GetResultCount() == 0); // Make sure that the lock has actually been taken by the checkpointing // thread. ThreadUtil.SleepAtLeastIgnoreInterrupts(1000); try { // Perform an RPC to the SBN and make sure it throws a StandbyException. nn1.GetRpcServer().GetFileInfo("/"); NUnit.Framework.Assert.Fail("Should have thrown StandbyException, but instead succeeded." ); } catch (StandbyException se) { GenericTestUtils.AssertExceptionContains("is not supported", se); } // Make sure new incremental block reports are processed during // checkpointing on the SBN. NUnit.Framework.Assert.AreEqual(0, cluster.GetNamesystem(1).GetPendingDataNodeMessageCount ()); DoCreate(); Sharpen.Thread.Sleep(1000); NUnit.Framework.Assert.IsTrue(cluster.GetNamesystem(1).GetPendingDataNodeMessageCount () > 0); // Make sure that the checkpoint is still going on, implying that the client // RPC to the SBN happened during the checkpoint. NUnit.Framework.Assert.IsTrue("SBN should have still been checkpointing.", answerer .GetFireCount() == 1 && answerer.GetResultCount() == 0); answerer.Proceed(); answerer.WaitForResult(); NUnit.Framework.Assert.IsTrue("SBN should have finished checkpointing.", answerer .GetFireCount() == 1 && answerer.GetResultCount() == 1); }
/// <exception cref="System.Exception"/> public virtual void TestReadsAllowedDuringCheckpoint() { // Set it up so that we know when the SBN checkpoint starts and ends. FSImage spyImage1 = NameNodeAdapter.SpyOnFsImage(nn1); GenericTestUtils.DelayAnswer answerer = new GenericTestUtils.DelayAnswer(Log); Org.Mockito.Mockito.DoAnswer(answerer).When(spyImage1).SaveNamespace(Org.Mockito.Mockito .Any <FSNamesystem>(), Org.Mockito.Mockito.Any <NNStorage.NameNodeFile>(), Org.Mockito.Mockito .Any <Canceler>()); // Perform some edits and wait for a checkpoint to start on the SBN. DoEdits(0, 1000); nn0.GetRpcServer().RollEditLog(); answerer.WaitForCall(); NUnit.Framework.Assert.IsTrue("SBN is not performing checkpoint but it should be." , answerer.GetFireCount() == 1 && answerer.GetResultCount() == 0); // Make sure that the lock has actually been taken by the checkpointing // thread. ThreadUtil.SleepAtLeastIgnoreInterrupts(1000); // Perform an RPC that needs to take the write lock. Sharpen.Thread t = new _Thread_404(this); t.Start(); // Make sure that our thread is waiting for the lock. ThreadUtil.SleepAtLeastIgnoreInterrupts(1000); NUnit.Framework.Assert.IsFalse(nn1.GetNamesystem().GetFsLockForTests().HasQueuedThreads ()); NUnit.Framework.Assert.IsFalse(nn1.GetNamesystem().GetFsLockForTests().IsWriteLocked ()); NUnit.Framework.Assert.IsTrue(nn1.GetNamesystem().GetCpLockForTests().HasQueuedThreads ()); // Get /jmx of the standby NN web UI, which will cause the FSNS read lock to // be taken. string pageContents = DFSTestUtil.UrlGet(new Uri("http://" + nn1.GetHttpAddress() .GetHostName() + ":" + nn1.GetHttpAddress().Port + "/jmx")); NUnit.Framework.Assert.IsTrue(pageContents.Contains("NumLiveDataNodes")); // Make sure that the checkpoint is still going on, implying that the client // RPC to the SBN happened during the checkpoint. NUnit.Framework.Assert.IsTrue("SBN should have still been checkpointing.", answerer .GetFireCount() == 1 && answerer.GetResultCount() == 0); answerer.Proceed(); answerer.WaitForResult(); NUnit.Framework.Assert.IsTrue("SBN should have finished checkpointing.", answerer .GetFireCount() == 1 && answerer.GetResultCount() == 1); t.Join(); }
/// <summary> /// Test for the case when the SBN is configured to checkpoint based /// on a time period, but no transactions are happening on the /// active. /// </summary> /// <remarks> /// Test for the case when the SBN is configured to checkpoint based /// on a time period, but no transactions are happening on the /// active. Thus, it would want to save a second checkpoint at the /// same txid, which is a no-op. This test makes sure this doesn't /// cause any problem. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestCheckpointWhenNoNewTransactionsHappened() { // Checkpoint as fast as we can, in a tight loop. cluster.GetConfiguration(1).SetInt(DFSConfigKeys.DfsNamenodeCheckpointPeriodKey, 0); cluster.RestartNameNode(1); nn1 = cluster.GetNameNode(1); FSImage spyImage1 = NameNodeAdapter.SpyOnFsImage(nn1); // We shouldn't save any checkpoints at txid=0 Sharpen.Thread.Sleep(1000); Org.Mockito.Mockito.Verify(spyImage1, Org.Mockito.Mockito.Never()).SaveNamespace( (FSNamesystem)Org.Mockito.Mockito.AnyObject()); // Roll the primary and wait for the standby to catch up HATestUtil.WaitForStandbyToCatchUp(nn0, nn1); Sharpen.Thread.Sleep(2000); // We should make exactly one checkpoint at this new txid. Org.Mockito.Mockito.Verify(spyImage1, Org.Mockito.Mockito.Times(1)).SaveNamespace ((FSNamesystem)Org.Mockito.Mockito.AnyObject(), Org.Mockito.Mockito.Eq(NNStorage.NameNodeFile .Image), (Canceler)Org.Mockito.Mockito.AnyObject()); }