/// <summary> /// Regression test for HDFS-2693: when doing state transitions, we need to /// lock the FSNamesystem so that we don't end up doing any writes while it's /// "in between" states. /// </summary> /// <remarks> /// Regression test for HDFS-2693: when doing state transitions, we need to /// lock the FSNamesystem so that we don't end up doing any writes while it's /// "in between" states. /// This test case starts up several client threads which do mutation operations /// while flipping a NN back and forth from active to standby. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestTransitionSynchronization() { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleHATopology()).NumDataNodes(0).Build(); try { cluster.WaitActive(); ReentrantReadWriteLock spyLock = NameNodeAdapter.SpyOnFsLock(cluster.GetNameNode( 0).GetNamesystem()); Org.Mockito.Mockito.DoAnswer(new GenericTestUtils.SleepAnswer(50)).When(spyLock). WriteLock(); FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf); MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(); for (int i = 0; i < 50; i++) { int finalI = i; ctx.AddThread(new _RepeatingTestThread_256(finalI, fs, ctx)); } ctx.AddThread(new _RepeatingTestThread_266(cluster, ctx)); ctx.StartThreads(); ctx.WaitFor(20000); ctx.Stop(); } finally { cluster.Shutdown(); } }
/// <summary> /// Test that when access time updates are not needed, the FSNamesystem /// write lock is not taken by getBlockLocations. /// </summary> /// <remarks> /// Test that when access time updates are not needed, the FSNamesystem /// write lock is not taken by getBlockLocations. /// Regression test for HDFS-3981. /// </remarks> /// <exception cref="System.IO.IOException"/> public virtual void TestGetBlockLocationsOnlyUsesReadLock() { Configuration conf = new HdfsConfiguration(); conf.SetInt(DFSConfigKeys.DfsNamenodeAccesstimePrecisionKey, 100 * 1000); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); ReentrantReadWriteLock spyLock = NameNodeAdapter.SpyOnFsLock(cluster.GetNamesystem ()); try { // Create empty file in the FSN. Path p = new Path("/empty-file"); DFSTestUtil.CreateFile(cluster.GetFileSystem(), p, 0, (short)1, 0L); // getBlockLocations() should not need the write lock, since we just created // the file (and thus its access time is already within the 100-second // accesstime precision configured above). MockitoUtil.DoThrowWhenCallStackMatches(new Exception("Should not need write lock" ), ".*getBlockLocations.*").When(spyLock).WriteLock(); cluster.GetFileSystem().GetFileBlockLocations(p, 0, 100); } finally { cluster.Shutdown(); } }