public virtual void TestFailureToTransitionCausesShutdown()
        {
            MiniDFSCluster cluster = null;

            try
            {
                Configuration conf = new Configuration();
                // Set an illegal value for the trash emptier interval. This will cause
                // the NN to fail to transition to the active state.
                conf.SetLong(CommonConfigurationKeys.FsTrashIntervalKey, -1);
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                          ()).NumDataNodes(0).CheckExitOnShutdown(false).Build();
                cluster.WaitActive();
                try
                {
                    cluster.TransitionToActive(0);
                    NUnit.Framework.Assert.Fail("Transitioned to active but should not have been able to."
                                                );
                }
                catch (ExitUtil.ExitException ee)
                {
                    GenericTestUtils.AssertExceptionContains("Cannot start trash emptier with negative interval"
                                                             , ee);
                }
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
        public virtual void TestStartup()
        {
            Configuration conf = new Configuration();

            HAUtil.SetAllowStandbyReads(conf, true);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(0).Build();

            try
            {
                // During HA startup, both nodes should be in
                // standby and we shouldn't have any edits files
                // in any edits directory!
                IList <URI> allDirs = Lists.NewArrayList();
                Sharpen.Collections.AddAll(allDirs, cluster.GetNameDirs(0));
                Sharpen.Collections.AddAll(allDirs, cluster.GetNameDirs(1));
                allDirs.AddItem(cluster.GetSharedEditsDir(0, 1));
                AssertNoEditFiles(allDirs);
                // Set the first NN to active, make sure it creates edits
                // in its own dirs and the shared dir. The standby
                // should still have no edits!
                cluster.TransitionToActive(0);
                AssertEditFiles(cluster.GetNameDirs(0), NNStorage.GetInProgressEditsFileName(1));
                AssertEditFiles(Sharpen.Collections.SingletonList(cluster.GetSharedEditsDir(0, 1)
                                                                  ), NNStorage.GetInProgressEditsFileName(1));
                AssertNoEditFiles(cluster.GetNameDirs(1));
                cluster.GetNameNode(0).GetRpcServer().Mkdirs("/test", FsPermission.CreateImmutable
                                                                 ((short)0x1ed), true);
                // Restarting the standby should not finalize any edits files
                // in the shared directory when it starts up!
                cluster.RestartNameNode(1);
                AssertEditFiles(cluster.GetNameDirs(0), NNStorage.GetInProgressEditsFileName(1));
                AssertEditFiles(Sharpen.Collections.SingletonList(cluster.GetSharedEditsDir(0, 1)
                                                                  ), NNStorage.GetInProgressEditsFileName(1));
                AssertNoEditFiles(cluster.GetNameDirs(1));
                // Additionally it should not have applied any in-progress logs
                // at start-up -- otherwise, it would have read half-way into
                // the current log segment, and on the next roll, it would have to
                // either replay starting in the middle of the segment (not allowed)
                // or double-replay the edits (incorrect).
                NUnit.Framework.Assert.IsNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode(1),
                                                                          "/test", true));
                cluster.GetNameNode(0).GetRpcServer().Mkdirs("/test2", FsPermission.CreateImmutable
                                                                 ((short)0x1ed), true);
                // If we restart NN0, it'll come back as standby, and we can
                // transition NN1 to active and make sure it reads edits correctly at this point.
                cluster.RestartNameNode(0);
                cluster.TransitionToActive(1);
                // NN1 should have both the edits that came before its restart, and the edits that
                // came after its restart.
                NUnit.Framework.Assert.IsNotNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode(
                                                                                 1), "/test", true));
                NUnit.Framework.Assert.IsNotNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode(
                                                                                 1), "/test2", true));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 3
0
        public virtual void TestFailoverWithBK()
        {
            MiniDFSCluster cluster = null;

            try
            {
                Configuration conf = new Configuration();
                conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
                conf.Set(DFSConfigKeys.DfsNamenodeSharedEditsDirKey, BKJMUtil.CreateJournalURI("/hotfailover"
                                                                                               ).ToString());
                BKJMUtil.AddJournalManagerDefinition(conf);
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                          ()).NumDataNodes(0).ManageNameDfsSharedDirs(false).Build();
                NameNode nn1 = cluster.GetNameNode(0);
                NameNode nn2 = cluster.GetNameNode(1);
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                Path       p  = new Path("/testBKJMfailover");
                FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                fs.Mkdirs(p);
                cluster.ShutdownNameNode(0);
                cluster.TransitionToActive(1);
                NUnit.Framework.Assert.IsTrue(fs.Exists(p));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Test that transitioning a service to the state that it is already
        /// in is a nop, specifically, an exception is not thrown.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestTransitionToCurrentStateIsANop()
        {
            Configuration conf = new Configuration();

            conf.SetLong(DFSConfigKeys.DfsNamenodePathBasedCacheRefreshIntervalMs, 1L);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();
            List <Sharpen.Thread> crmThreads = new List <Sharpen.Thread>();

            try
            {
                cluster.WaitActive();
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToActive(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToActive(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToStandby(0);
                AddCrmThreads(cluster, crmThreads);
                cluster.TransitionToStandby(0);
                AddCrmThreads(cluster, crmThreads);
            }
            finally
            {
                cluster.Shutdown();
            }
            // Verify that all cacheReplicationMonitor threads shut down
            foreach (Sharpen.Thread thread in crmThreads)
            {
                Uninterruptibles.JoinUninterruptibly(thread);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This test also serves to test
        /// <see cref="Org.Apache.Hadoop.Hdfs.HAUtil.GetProxiesForAllNameNodesInNameservice(Org.Apache.Hadoop.Conf.Configuration, string)
        ///     "/>
        /// and
        /// <see cref="Org.Apache.Hadoop.Hdfs.DFSUtil.GetRpcAddressesForNameserviceId(Org.Apache.Hadoop.Conf.Configuration, string, string)
        ///     "/>
        /// by virtue of the fact that it wouldn't work properly if the proxies
        /// returned were not for the correct NNs.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestIsAtLeastOneActive()
        {
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration()).NnTopology
                                         (MiniDFSNNTopology.SimpleHATopology()).NumDataNodes(0).Build();

            try
            {
                Configuration conf = new HdfsConfiguration();
                HATestUtil.SetFailoverConfigurations(cluster, conf);
                IList <ClientProtocol> namenodes = HAUtil.GetProxiesForAllNameNodesInNameservice(conf
                                                                                                 , HATestUtil.GetLogicalHostname(cluster));
                NUnit.Framework.Assert.AreEqual(2, namenodes.Count);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToActive(0);
                NUnit.Framework.Assert.IsTrue(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToStandby(0);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToActive(1);
                NUnit.Framework.Assert.IsTrue(HAUtil.IsAtLeastOneActive(namenodes));
                cluster.TransitionToStandby(1);
                NUnit.Framework.Assert.IsFalse(HAUtil.IsAtLeastOneActive(namenodes));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Ejemplo n.º 6
0
        public virtual void TestStartingWithUpgradeInProgressSucceeds()
        {
            MiniDFSCluster cluster = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                          ()).NumDataNodes(0).Build();
                // Simulate an upgrade having started.
                for (int i = 0; i < 2; i++)
                {
                    foreach (URI uri in cluster.GetNameDirs(i))
                    {
                        FilePath prevTmp = new FilePath(new FilePath(uri), Storage.StorageTmpPrevious);
                        Log.Info("creating previous tmp dir: " + prevTmp);
                        NUnit.Framework.Assert.IsTrue(prevTmp.Mkdirs());
                    }
                }
                cluster.RestartNameNodes();
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Ejemplo n.º 7
0
        /// <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();
            }
        }
Ejemplo n.º 8
0
        public virtual void TestNfsUpgrade()
        {
            MiniDFSCluster cluster = null;
            FileSystem     fs      = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                          ()).NumDataNodes(0).Build();
                FilePath sharedDir = new FilePath(cluster.GetSharedEditsDir(0, 1));
                // No upgrade is in progress at the moment.
                CheckClusterPreviousDirExistence(cluster, false);
                AssertCTimesEqual(cluster);
                CheckPreviousDirExistence(sharedDir, false);
                // Transition NN0 to active and do some FS ops.
                cluster.TransitionToActive(0);
                fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo1")));
                // Do the upgrade. Shut down NN1 and then restart NN0 with the upgrade
                // flag.
                cluster.ShutdownNameNode(1);
                cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Upgrade
                                                          );
                cluster.RestartNameNode(0, false);
                CheckNnPreviousDirExistence(cluster, 0, true);
                CheckNnPreviousDirExistence(cluster, 1, false);
                CheckPreviousDirExistence(sharedDir, true);
                // NN0 should come up in the active state when given the -upgrade option,
                // so no need to transition it to active.
                NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo2")));
                // Restart NN0 without the -upgrade flag, to make sure that works.
                cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Regular
                                                          );
                cluster.RestartNameNode(0, false);
                // Make sure we can still do FS ops after upgrading.
                cluster.TransitionToActive(0);
                NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo3")));
                // Now bootstrap the standby with the upgraded info.
                int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration
                                                  (1));
                NUnit.Framework.Assert.AreEqual(0, rc);
                // Now restart NN1 and make sure that we can do ops against that as well.
                cluster.RestartNameNode(1);
                cluster.TransitionToStandby(0);
                cluster.TransitionToActive(1);
                NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo4")));
                AssertCTimesEqual(cluster);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>Test that delegation tokens continue to work after the failover.</summary>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestDelegationTokensAfterFailover()
        {
            Configuration conf = new Configuration();

            conf.SetBoolean(DFSConfigKeys.DfsNamenodeDelegationTokenAlwaysUseKey, true);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(0).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                NameNode nn1     = cluster.GetNameNode(0);
                NameNode nn2     = cluster.GetNameNode(1);
                string   renewer = UserGroupInformation.GetLoginUser().GetUserName();
                Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = nn1.GetRpcServer
                                                                                               ().GetDelegationToken(new Text(renewer));
                Log.Info("Failing over to NN 1");
                cluster.TransitionToStandby(0);
                cluster.TransitionToActive(1);
                nn2.GetRpcServer().RenewDelegationToken(token);
                nn2.GetRpcServer().CancelDelegationToken(token);
                token = nn2.GetRpcServer().GetDelegationToken(new Text(renewer));
                NUnit.Framework.Assert.IsTrue(token != null);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 10
0
 public virtual void SetUpNameNode()
 {
     conf    = new HdfsConfiguration();
     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                               ()).NumDataNodes(0).Build();
     HATestUtil.SetFailoverConfigurations(cluster, conf);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Regression test for HDFS-2795:
        /// - Start an HA cluster with a DN.
        /// </summary>
        /// <remarks>
        /// Regression test for HDFS-2795:
        /// - Start an HA cluster with a DN.
        /// - Write several blocks to the FS with replication 1.
        /// - Shutdown the DN
        /// - Wait for the NNs to declare the DN dead. All blocks will be under-replicated.
        /// - Restart the DN.
        /// In the bug, the standby node would only very slowly notice the blocks returning
        /// to the cluster.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestDatanodeRestarts()
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, 1024);
            // We read from the standby to watch block locations
            HAUtil.SetAllowStandbyReads(conf, true);
            conf.SetLong(DFSConfigKeys.DfsNamenodeAccesstimePrecisionKey, 0);
            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();

            try
            {
                NameNode nn0 = cluster.GetNameNode(0);
                NameNode nn1 = cluster.GetNameNode(1);
                cluster.TransitionToActive(0);
                // Create 5 blocks.
                DFSTestUtil.CreateFile(cluster.GetFileSystem(0), TestFilePath, 5 * 1024, (short)1
                                       , 1L);
                HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
                // Stop the DN.
                DataNode dn     = cluster.GetDataNodes()[0];
                string   dnName = dn.GetDatanodeId().GetXferAddr();
                MiniDFSCluster.DataNodeProperties dnProps = cluster.StopDataNode(0);
                // Make sure both NNs register it as dead.
                BlockManagerTestUtil.NoticeDeadDatanode(nn0, dnName);
                BlockManagerTestUtil.NoticeDeadDatanode(nn1, dnName);
                BlockManagerTestUtil.UpdateState(nn0.GetNamesystem().GetBlockManager());
                BlockManagerTestUtil.UpdateState(nn1.GetNamesystem().GetBlockManager());
                NUnit.Framework.Assert.AreEqual(5, nn0.GetNamesystem().GetUnderReplicatedBlocks()
                                                );
                // The SBN will not have any blocks in its neededReplication queue
                // since the SBN doesn't process replication.
                NUnit.Framework.Assert.AreEqual(0, nn1.GetNamesystem().GetUnderReplicatedBlocks()
                                                );
                LocatedBlocks locs = nn1.GetRpcServer().GetBlockLocations(TestFile, 0, 1);
                NUnit.Framework.Assert.AreEqual("Standby should have registered that the block has no replicas"
                                                , 0, locs.Get(0).GetLocations().Length);
                cluster.RestartDataNode(dnProps);
                // Wait for both NNs to re-register the DN.
                cluster.WaitActive(0);
                cluster.WaitActive(1);
                BlockManagerTestUtil.UpdateState(nn0.GetNamesystem().GetBlockManager());
                BlockManagerTestUtil.UpdateState(nn1.GetNamesystem().GetBlockManager());
                NUnit.Framework.Assert.AreEqual(0, nn0.GetNamesystem().GetUnderReplicatedBlocks()
                                                );
                NUnit.Framework.Assert.AreEqual(0, nn1.GetNamesystem().GetUnderReplicatedBlocks()
                                                );
                locs = nn1.GetRpcServer().GetBlockLocations(TestFile, 0, 1);
                NUnit.Framework.Assert.AreEqual("Standby should have registered that the block has replicas again"
                                                , 1, locs.Get(0).GetLocations().Length);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Test a cluster with even distribution, then a new empty node is added to
        /// the cluster.
        /// </summary>
        /// <remarks>
        /// Test a cluster with even distribution, then a new empty node is added to
        /// the cluster. Test start a cluster with specified number of nodes, and fills
        /// it to be 30% full (with a single file replicated identically to all
        /// datanodes); It then adds one new empty node and starts balancing.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestBalancerWithHANameNodes()
        {
            Configuration conf = new HdfsConfiguration();

            TestBalancer.InitConf(conf);
            long newNodeCapacity = TestBalancer.Capacity;
            // new node's capacity
            string newNodeRack = TestBalancer.Rack2;

            // new node's rack
            // array of racks for original nodes in cluster
            string[] racks = new string[] { TestBalancer.Rack0, TestBalancer.Rack1 };
            // array of capacities of original nodes in cluster
            long[] capacities = new long[] { TestBalancer.Capacity, TestBalancer.Capacity };
            NUnit.Framework.Assert.AreEqual(capacities.Length, racks.Length);
            int numOfDatanodes = capacities.Length;

            MiniDFSNNTopology.NNConf nn1Conf = new MiniDFSNNTopology.NNConf("nn1");
            nn1Conf.SetIpcPort(NameNode.DefaultPort);
            Configuration copiedConf = new Configuration(conf);

            cluster = new MiniDFSCluster.Builder(copiedConf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                            ()).NumDataNodes(capacities.Length).Racks(racks).SimulatedCapacities(capacities)
                      .Build();
            HATestUtil.SetFailoverConfigurations(cluster, conf);
            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(1);
                Sharpen.Thread.Sleep(500);
                client = NameNodeProxies.CreateProxy <ClientProtocol>(conf, FileSystem.GetDefaultUri
                                                                          (conf)).GetProxy();
                long totalCapacity = TestBalancer.Sum(capacities);
                // fill up the cluster to be 30% full
                long totalUsedSpace = totalCapacity * 3 / 10;
                TestBalancer.CreateFile(cluster, TestBalancer.filePath, totalUsedSpace / numOfDatanodes
                                        , (short)numOfDatanodes, 1);
                // start up an empty node with the same capacity and on the same rack
                cluster.StartDataNodes(conf, 1, true, null, new string[] { newNodeRack }, new long
                                       [] { newNodeCapacity });
                totalCapacity += newNodeCapacity;
                TestBalancer.WaitForHeartBeat(totalUsedSpace, totalCapacity, client, cluster);
                ICollection <URI> namenodes = DFSUtil.GetNsServiceRpcUris(conf);
                NUnit.Framework.Assert.AreEqual(1, namenodes.Count);
                NUnit.Framework.Assert.IsTrue(namenodes.Contains(HATestUtil.GetLogicalUri(cluster
                                                                                          )));
                int r = Org.Apache.Hadoop.Hdfs.Server.Balancer.Balancer.Run(namenodes, Balancer.Parameters
                                                                            .Default, conf);
                NUnit.Framework.Assert.AreEqual(ExitStatus.Success.GetExitCode(), r);
                TestBalancer.WaitForBalancer(totalUsedSpace, totalCapacity, client, cluster, Balancer.Parameters
                                             .Default);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 13
0
 public virtual void StartCluster()
 {
     conf = new Configuration();
     conf.SetBoolean(DFSConfigKeys.DfsBlockAccessTokenEnableKey, true);
     // Set short retry timeouts so this test runs faster
     conf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 10);
     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                               ()).NumDataNodes(1).Build();
 }
Ejemplo n.º 14
0
        /// <exception cref="System.Exception"/>
        private void DoWriteOverFailoverTest(TestPipelinesFailover.TestScenario scenario,
                                             TestPipelinesFailover.MethodToTestIdempotence methodToTest)
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, BlockSize);
            // Don't check replication periodically.
            conf.SetInt(DFSConfigKeys.DfsNamenodeReplicationIntervalKey, 1000);
            FSDataOutputStream stm     = null;
            MiniDFSCluster     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                     .SimpleHATopology()).NumDataNodes(3).Build();

            try
            {
                int sizeWritten = 0;
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                Sharpen.Thread.Sleep(500);
                Log.Info("Starting with NN 0 active");
                FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                stm = fs.Create(TestPath);
                // write a block and a half
                AppendTestUtil.Write(stm, 0, BlockAndAHalf);
                sizeWritten += BlockAndAHalf;
                // Make sure all of the blocks are written out before failover.
                stm.Hflush();
                Log.Info("Failing over to NN 1");
                scenario.Run(cluster);
                // NOTE: explicitly do *not* make any further metadata calls
                // to the NN here. The next IPC call should be to allocate the next
                // block. Any other call would notice the failover and not test
                // idempotence of the operation (HDFS-3031)
                FSNamesystem ns1 = cluster.GetNameNode(1).GetNamesystem();
                BlockManagerTestUtil.UpdateState(ns1.GetBlockManager());
                NUnit.Framework.Assert.AreEqual(0, ns1.GetPendingReplicationBlocks());
                NUnit.Framework.Assert.AreEqual(0, ns1.GetCorruptReplicaBlocks());
                NUnit.Framework.Assert.AreEqual(0, ns1.GetMissingBlocksCount());
                // If we're testing allocateBlock()'s idempotence, write another
                // block and a half, so we have to allocate a new block.
                // Otherise, don't write anything, so our next RPC will be
                // completeFile() if we're testing idempotence of that operation.
                if (methodToTest == TestPipelinesFailover.MethodToTestIdempotence.AllocateBlock)
                {
                    // write another block and a half
                    AppendTestUtil.Write(stm, sizeWritten, BlockAndAHalf);
                    sizeWritten += BlockAndAHalf;
                }
                stm.Close();
                stm = null;
                AppendTestUtil.Check(fs, TestPath, sizeWritten);
            }
            finally
            {
                IOUtils.CloseStream(stm);
                cluster.Shutdown();
            }
        }
Ejemplo n.º 15
0
 public virtual void Setup()
 {
     conf    = new Configuration();
     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                               ()).NumDataNodes(0).Build();
     tool = new DFSHAAdmin();
     tool.SetConf(conf);
     tool.SetErrOut(new TextWriter(errOutBytes));
     cluster.WaitActive();
     nn1Port = cluster.GetNameNodePort(0);
 }
Ejemplo n.º 16
0
        public virtual void SetupCluster()
        {
            conf = new Configuration();
            conf.SetInt(DFSConfigKeys.DfsHaLogrollPeriodKey, 1);
            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            HAUtil.SetAllowStandbyReads(conf, true);
            MiniDFSNNTopology topology = MiniDFSNNTopology.SimpleHATopology();

            cluster = new MiniDFSCluster.Builder(conf).NnTopology(topology).NumDataNodes(0).Build
                          ();
            cluster.WaitActive();
            ShutdownClusterAndRemoveSharedEditsDir();
        }
Ejemplo n.º 17
0
        /// <exception cref="System.Exception"/>
        public virtual void TestStandbyIsHot()
        {
            Configuration conf = new Configuration();

            // We read from the standby to watch block locations
            HAUtil.SetAllowStandbyReads(conf, true);
            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(3).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                NameNode   nn1 = cluster.GetNameNode(0);
                NameNode   nn2 = cluster.GetNameNode(1);
                FileSystem fs  = HATestUtil.ConfigureFailoverFs(cluster, conf);
                Sharpen.Thread.Sleep(1000);
                System.Console.Error.WriteLine("==================================");
                DFSTestUtil.WriteFile(fs, TestFilePath, TestFileData);
                // Have to force an edit log roll so that the standby catches up
                nn1.GetRpcServer().RollEditLog();
                System.Console.Error.WriteLine("==================================");
                // Block locations should show up on standby.
                Log.Info("Waiting for block locations to appear on standby node");
                WaitForBlockLocations(cluster, nn2, TestFile, 3);
                // Trigger immediate heartbeats and block reports so
                // that the active "trusts" all of the DNs
                cluster.TriggerHeartbeats();
                cluster.TriggerBlockReports();
                // Change replication
                Log.Info("Changing replication to 1");
                fs.SetReplication(TestFilePath, (short)1);
                BlockManagerTestUtil.ComputeAllPendingWork(nn1.GetNamesystem().GetBlockManager());
                WaitForBlockLocations(cluster, nn1, TestFile, 1);
                nn1.GetRpcServer().RollEditLog();
                Log.Info("Waiting for lowered replication to show up on standby");
                WaitForBlockLocations(cluster, nn2, TestFile, 1);
                // Change back to 3
                Log.Info("Changing replication to 3");
                fs.SetReplication(TestFilePath, (short)3);
                BlockManagerTestUtil.ComputeAllPendingWork(nn1.GetNamesystem().GetBlockManager());
                nn1.GetRpcServer().RollEditLog();
                Log.Info("Waiting for higher replication to show up on standby");
                WaitForBlockLocations(cluster, nn2, TestFile, 3);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 18
0
 public virtual void Setup()
 {
     conf = new HdfsConfiguration();
     conf.SetBoolean(DFSConfigKeys.DfsNamenodeEnableRetryCacheKey, true);
     conf.SetInt(DFSConfigKeys.DfsClientTestDropNamenodeResponseNumKey, 2);
     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                               ()).NumDataNodes(3).Build();
     cluster.WaitActive();
     cluster.TransitionToActive(namenodeId);
     HATestUtil.SetFailoverConfigurations(cluster, conf);
     filesystem = (DistributedFileSystem)HATestUtil.ConfigureFailoverFs(cluster, conf);
     namesystem = cluster.GetNamesystem(namenodeId);
     metrics    = namesystem.GetRetryCache().GetMetricsForTests();
 }
Ejemplo n.º 19
0
        public virtual void SetupCluster()
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            HAUtil.SetAllowStandbyReads(conf, true);
            cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                      ()).NumDataNodes(1).WaitSafeMode(false).Build();
            cluster.WaitActive();
            nn0 = cluster.GetNameNode(0);
            nn1 = cluster.GetNameNode(1);
            fs  = HATestUtil.ConfigureFailoverFs(cluster, conf);
            cluster.TransitionToActive(0);
        }
        /// <exception cref="System.Exception"/>
        private void TestFailoverFinalizesAndReadsInProgress(bool partialTxAtEnd)
        {
            Configuration  conf    = new Configuration();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(0).Build();

            try
            {
                // Create a fake in-progress edit-log in the shared directory
                URI          sharedUri = cluster.GetSharedEditsDir(0, 1);
                FilePath     sharedDir = new FilePath(sharedUri.GetPath(), "current");
                FSNamesystem fsn       = cluster.GetNamesystem(0);
                FSImageTestUtil.CreateAbortedLogWithMkdirs(sharedDir, NumDirsInLog, 1, fsn.GetFSDirectory
                                                               ().GetLastInodeId() + 1);
                AssertEditFiles(Sharpen.Collections.SingletonList(sharedUri), NNStorage.GetInProgressEditsFileName
                                    (1));
                if (partialTxAtEnd)
                {
                    FileOutputStream outs = null;
                    try
                    {
                        FilePath editLogFile = new FilePath(sharedDir, NNStorage.GetInProgressEditsFileName
                                                                (1));
                        outs = new FileOutputStream(editLogFile, true);
                        outs.Write(new byte[] { unchecked ((int)(0x18)), unchecked ((int)(0x00)), unchecked (
                                                    (int)(0x00)), unchecked ((int)(0x00)) });
                        Log.Error("editLogFile = " + editLogFile);
                    }
                    finally
                    {
                        IOUtils.Cleanup(Log, outs);
                    }
                }
                // Transition one of the NNs to active
                cluster.TransitionToActive(0);
                // In the transition to active, it should have read the log -- and
                // hence see one of the dirs we made in the fake log.
                string testPath = "/dir" + NumDirsInLog;
                NUnit.Framework.Assert.IsNotNull(cluster.GetNameNode(0).GetRpcServer().GetFileInfo
                                                     (testPath));
                // It also should have finalized that log in the shared directory and started
                // writing to a new one at the next txid.
                AssertEditFiles(Sharpen.Collections.SingletonList(sharedUri), NNStorage.GetFinalizedEditsFileName
                                    (1, NumDirsInLog + 1), NNStorage.GetInProgressEditsFileName(NumDirsInLog + 2));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 21
0
        /// <summary>Tests manual failover back and forth between two NameNodes.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestManualFailoverAndFailback()
        {
            Configuration  conf    = new Configuration();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();

            try
            {
                cluster.WaitActive();
                // test the only namespace
                TestManualFailoverFailback(cluster, conf, 0);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 22
0
        /// <exception cref="System.Exception"/>
        private void DoTestWriteOverFailoverWithDnFail(TestPipelinesFailover.TestScenario
                                                       scenario)
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, BlockSize);
            FSDataOutputStream stm     = null;
            MiniDFSCluster     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                     .SimpleHATopology()).NumDataNodes(5).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                Sharpen.Thread.Sleep(500);
                Log.Info("Starting with NN 0 active");
                FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                stm = fs.Create(TestPath);
                // write a block and a half
                AppendTestUtil.Write(stm, 0, BlockAndAHalf);
                // Make sure all the blocks are written before failover
                stm.Hflush();
                Log.Info("Failing over to NN 1");
                scenario.Run(cluster);
                NUnit.Framework.Assert.IsTrue(fs.Exists(TestPath));
                cluster.StopDataNode(0);
                // write another block and a half
                AppendTestUtil.Write(stm, BlockAndAHalf, BlockAndAHalf);
                stm.Hflush();
                Log.Info("Failing back to NN 0");
                cluster.TransitionToStandby(1);
                cluster.TransitionToActive(0);
                cluster.StopDataNode(1);
                AppendTestUtil.Write(stm, BlockAndAHalf * 2, BlockAndAHalf);
                stm.Hflush();
                stm.Close();
                stm = null;
                AppendTestUtil.Check(fs, TestPath, BlockAndAHalf * 3);
            }
            finally
            {
                IOUtils.CloseStream(stm);
                cluster.Shutdown();
            }
        }
Ejemplo n.º 23
0
        public virtual void TestTailer()
        {
            Configuration conf = new HdfsConfiguration();

            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            HAUtil.SetAllowStandbyReads(conf, true);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(0).Build();

            cluster.WaitActive();
            cluster.TransitionToActive(0);
            NameNode nn1 = cluster.GetNameNode(0);
            NameNode nn2 = cluster.GetNameNode(1);

            try
            {
                for (int i = 0; i < DirsToMake / 2; i++)
                {
                    NameNodeAdapter.Mkdirs(nn1, GetDirPath(i), new PermissionStatus("test", "test", new
                                                                                    FsPermission((short)0x1ed)), true);
                }
                HATestUtil.WaitForStandbyToCatchUp(nn1, nn2);
                for (int i_1 = 0; i_1 < DirsToMake / 2; i_1++)
                {
                    NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(nn2, GetDirPath(i_1), false
                                                                              ).IsDir());
                }
                for (int i_2 = DirsToMake / 2; i_2 < DirsToMake; i_2++)
                {
                    NameNodeAdapter.Mkdirs(nn1, GetDirPath(i_2), new PermissionStatus("test", "test",
                                                                                      new FsPermission((short)0x1ed)), true);
                }
                HATestUtil.WaitForStandbyToCatchUp(nn1, nn2);
                for (int i_3 = DirsToMake / 2; i_3 < DirsToMake; i_3++)
                {
                    NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(nn2, GetDirPath(i_3), false
                                                                              ).IsDir());
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 24
0
        public virtual void TestInitializeBKSharedEdits()
        {
            MiniDFSCluster cluster = null;

            try
            {
                Configuration conf = new Configuration();
                HAUtil.SetAllowStandbyReads(conf, true);
                conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
                MiniDFSNNTopology topology = MiniDFSNNTopology.SimpleHATopology();
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(topology).NumDataNodes(0).Build
                              ();
                cluster.WaitActive();
                // Shutdown and clear the current filebased shared dir.
                cluster.ShutdownNameNodes();
                FilePath shareddir = new FilePath(cluster.GetSharedEditsDir(0, 1));
                NUnit.Framework.Assert.IsTrue("Initial Shared edits dir not fully deleted", FileUtil
                                              .FullyDelete(shareddir));
                // Check namenodes should not start without shared dir.
                AssertCanNotStartNamenode(cluster, 0);
                AssertCanNotStartNamenode(cluster, 1);
                // Configure bkjm as new shared edits dir in both namenodes
                Configuration nn1Conf = cluster.GetConfiguration(0);
                Configuration nn2Conf = cluster.GetConfiguration(1);
                nn1Conf.Set(DFSConfigKeys.DfsNamenodeSharedEditsDirKey, BKJMUtil.CreateJournalURI
                                ("/initializeSharedEdits").ToString());
                nn2Conf.Set(DFSConfigKeys.DfsNamenodeSharedEditsDirKey, BKJMUtil.CreateJournalURI
                                ("/initializeSharedEdits").ToString());
                BKJMUtil.AddJournalManagerDefinition(nn1Conf);
                BKJMUtil.AddJournalManagerDefinition(nn2Conf);
                // Initialize the BKJM shared edits.
                NUnit.Framework.Assert.IsFalse(NameNode.InitializeSharedEdits(nn1Conf));
                // NameNode should be able to start and should be in sync with BKJM as
                // shared dir
                AssertCanStartHANameNodes(cluster, conf, "/testBKJMInitialize");
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
        public virtual void SetupCluster()
        {
            SecurityUtilTestHelper.SetTokenServiceUseIp(true);
            conf.SetBoolean(DFSConfigKeys.DfsNamenodeDelegationTokenAlwaysUseKey, true);
            conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthToLocal, "RULE:[2:$1@$0](JobTracker@.*FOO.COM)s/@.*//"
                     + "DEFAULT");
            cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                      ()).NumDataNodes(0).Build();
            cluster.WaitActive();
            string logicalName = HATestUtil.GetLogicalHostname(cluster);

            HATestUtil.SetFailoverConfigurations(cluster, conf, logicalName, 0);
            nn0 = cluster.GetNameNode(0);
            nn1 = cluster.GetNameNode(1);
            fs  = HATestUtil.ConfigureFailoverFs(cluster, conf);
            dfs = (DistributedFileSystem)fs;
            cluster.TransitionToActive(0);
            dtSecretManager = NameNodeAdapter.GetDtSecretManager(nn0.GetNamesystem());
        }
Ejemplo n.º 26
0
        public virtual void TestMultiplePrimariesStarted()
        {
            Path           p1      = new Path("/testBKJMMultiplePrimary");
            MiniDFSCluster cluster = null;

            try
            {
                Configuration conf = new Configuration();
                conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
                conf.Set(DFSConfigKeys.DfsNamenodeSharedEditsDirKey, BKJMUtil.CreateJournalURI("/hotfailoverMultiple"
                                                                                               ).ToString());
                BKJMUtil.AddJournalManagerDefinition(conf);
                cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology.SimpleHATopology
                                                                          ()).NumDataNodes(0).ManageNameDfsSharedDirs(false).CheckExitOnShutdown(false).Build
                              ();
                NameNode nn1 = cluster.GetNameNode(0);
                NameNode nn2 = cluster.GetNameNode(1);
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                fs.Mkdirs(p1);
                nn1.GetRpcServer().RollEditLog();
                cluster.TransitionToActive(1);
                fs = cluster.GetFileSystem(0);
                // get the older active server.
                try
                {
                    fs.Delete(p1, true);
                    NUnit.Framework.Assert.Fail("Log update on older active should cause it to exit");
                }
                catch (RemoteException re)
                {
                    NUnit.Framework.Assert.IsTrue(re.GetClassName().Contains("ExitException"));
                }
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Ejemplo n.º 27
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();
            }
        }
Ejemplo n.º 28
0
        /// <summary>Tests lease recovery if a client crashes.</summary>
        /// <remarks>
        /// Tests lease recovery if a client crashes. This approximates the
        /// use case of HBase WALs being recovered after a NN failover.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestLeaseRecoveryAfterFailover()
        {
            Configuration conf = new Configuration();

            // Disable permissions so that another user can recover the lease.
            conf.SetBoolean(DFSConfigKeys.DfsPermissionsEnabledKey, false);
            conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, BlockSize);
            FSDataOutputStream stm     = null;
            MiniDFSCluster     cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                     .SimpleHATopology()).NumDataNodes(3).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                Sharpen.Thread.Sleep(500);
                Log.Info("Starting with NN 0 active");
                FileSystem fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                stm = fs.Create(TestPath);
                // write a block and a half
                AppendTestUtil.Write(stm, 0, BlockAndAHalf);
                stm.Hflush();
                Log.Info("Failing over to NN 1");
                cluster.TransitionToStandby(0);
                cluster.TransitionToActive(1);
                NUnit.Framework.Assert.IsTrue(fs.Exists(TestPath));
                FileSystem fsOtherUser = CreateFsAsOtherUser(cluster, conf);
                LoopRecoverLease(fsOtherUser, TestPath);
                AppendTestUtil.Check(fs, TestPath, BlockAndAHalf);
                // Fail back to ensure that the block locations weren't lost on the
                // original node.
                cluster.TransitionToStandby(1);
                cluster.TransitionToActive(0);
                AppendTestUtil.Check(fs, TestPath, BlockAndAHalf);
            }
            finally
            {
                IOUtils.CloseStream(stm);
                cluster.Shutdown();
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidateBlock()
        {
            Configuration conf = new Configuration();

            HAUtil.SetAllowStandbyReads(conf, true);
            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(3).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                NameNode   nn1 = cluster.GetNameNode(0);
                NameNode   nn2 = cluster.GetNameNode(1);
                FileSystem fs  = HATestUtil.ConfigureFailoverFs(cluster, conf);
                Sharpen.Thread.Sleep(1000);
                Log.Info("==================================");
                DFSTestUtil.WriteFile(fs, TestFilePath, TestFileData);
                // Have to force an edit log roll so that the standby catches up
                nn1.GetRpcServer().RollEditLog();
                Log.Info("==================================");
                // delete the file
                fs.Delete(TestFilePath, false);
                BlockManagerTestUtil.ComputeAllPendingWork(nn1.GetNamesystem().GetBlockManager());
                nn1.GetRpcServer().RollEditLog();
                // standby nn doesn't need to invalidate blocks.
                NUnit.Framework.Assert.AreEqual(0, nn2.GetNamesystem().GetBlockManager().GetPendingDeletionBlocksCount
                                                    ());
                cluster.TriggerHeartbeats();
                cluster.TriggerBlockReports();
                // standby nn doesn't need to invalidate blocks.
                NUnit.Framework.Assert.AreEqual(0, nn2.GetNamesystem().GetBlockManager().GetPendingDeletionBlocksCount
                                                    ());
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Test which takes a single node and flip flops between
        /// active and standby mode, making sure it doesn't
        /// double-play any edits.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestTransitionActiveToStandby()
        {
            Configuration  conf    = new Configuration();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology
                                                                                 .SimpleHATopology()).NumDataNodes(1).Build();

            try
            {
                cluster.WaitActive();
                cluster.TransitionToActive(0);
                FileSystem fs = cluster.GetFileSystem(0);
                fs.Mkdirs(TestDir);
                cluster.TransitionToStandby(0);
                try
                {
                    fs.Mkdirs(new Path("/x"));
                    NUnit.Framework.Assert.Fail("Didn't throw trying to mutate FS in standby state");
                }
                catch (Exception t)
                {
                    GenericTestUtils.AssertExceptionContains("Operation category WRITE is not supported"
                                                             , t);
                }
                cluster.TransitionToActive(0);
                // Create a file, then delete the whole directory recursively.
                DFSTestUtil.CreateFile(fs, new Path(TestDir, "foo"), 10, (short)1, 1L);
                fs.Delete(TestDir, true);
                // Now if the standby tries to replay the last segment that it just
                // wrote as active, it would fail since it's trying to create a file
                // in a non-existent directory.
                cluster.TransitionToStandby(0);
                cluster.TransitionToActive(0);
                NUnit.Framework.Assert.IsFalse(fs.Exists(TestDir));
            }
            finally
            {
                cluster.Shutdown();
            }
        }