Exemplo n.º 1
0
        /// <summary>Test for HDFS-2812.</summary>
        /// <remarks>
        /// Test for HDFS-2812. Since lease renewals go from the client
        /// only to the active NN, the SBN will have out-of-date lease
        /// info when it becomes active. We need to make sure we don't
        /// accidentally mark the leases as expired when the failover
        /// proceeds.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestLeasesRenewedOnTransition()
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();
            FSDataOutputStream stm = null;
            FileSystem         fs  = HATestUtil.ConfigureFailoverFs(cluster, conf);
            NameNode           nn0 = cluster.GetNameNode(0);
            NameNode           nn1 = cluster.GetNameNode(1);

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                Log.Info("Starting with NN 0 active");
                stm = fs.Create(TestFilePath);
                long nn0t0 = NameNodeAdapter.GetLeaseRenewalTime(nn0, TestFileStr);
                NUnit.Framework.Assert.IsTrue(nn0t0 > 0);
                long nn1t0 = NameNodeAdapter.GetLeaseRenewalTime(nn1, TestFileStr);
                NUnit.Framework.Assert.AreEqual("Lease should not yet exist on nn1", -1, nn1t0);
                Sharpen.Thread.Sleep(5);
                // make sure time advances!
                HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
                long nn1t1 = NameNodeAdapter.GetLeaseRenewalTime(nn1, TestFileStr);
                NUnit.Framework.Assert.IsTrue("Lease should have been created on standby. Time was: "
                                              + nn1t1, nn1t1 > nn0t0);
                Sharpen.Thread.Sleep(5);
                // make sure time advances!
                Log.Info("Failing over to NN 1");
                cluster.TransitionToStandby(0);
                cluster.TransitionToActive(1);
                long nn1t2 = NameNodeAdapter.GetLeaseRenewalTime(nn1, TestFileStr);
                NUnit.Framework.Assert.IsTrue("Lease should have been renewed by failover process"
                                              , nn1t2 > nn1t1);
            }
            finally
            {
                IOUtils.CloseStream(stm);
                cluster.Shutdown();
            }
        }