Ejemplo n.º 1
0
        /// <exception cref="Org.Apache.Hadoop.HA.ServiceFailedException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.URISyntaxException"/>
        /// <exception cref="System.Exception"/>
        private void AssertCanStartHANameNodes(MiniDFSCluster cluster, Configuration conf
                                               , string path)
        {
            // Now should be able to start both NNs. Pass "false" here so that we don't
            // try to waitActive on all NNs, since the second NN doesn't exist yet.
            cluster.RestartNameNode(0, false);
            cluster.RestartNameNode(1, true);
            // Make sure HA is working.
            cluster.GetNameNode(0).GetRpcServer().TransitionToActive(new HAServiceProtocol.StateChangeRequestInfo
                                                                         (HAServiceProtocol.RequestSource.RequestByUser));
            FileSystem fs = null;

            try
            {
                Path newPath = new Path(path);
                fs = HATestUtil.ConfigureFailoverFs(cluster, conf);
                NUnit.Framework.Assert.IsTrue(fs.Mkdirs(newPath));
                HATestUtil.WaitForStandbyToCatchUp(cluster.GetNameNode(0), cluster.GetNameNode(1)
                                                   );
                NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(cluster.GetNameNode(1),
                                                                          newPath.ToString(), false).IsDir());
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
        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 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.º 4
0
 public virtual void TestFailuretoReadEdits()
 {
     NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path(TestDir1)));
     HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
     // If these two ops are applied twice, the first op will throw an
     // exception the second time its replayed.
     fs.SetOwner(new Path(TestDir1), "foo", "bar");
     NUnit.Framework.Assert.IsTrue(fs.Delete(new Path(TestDir1), true));
     // This op should get applied just fine.
     NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path(TestDir2)));
     // This is the op the mocking will cause to fail to be read.
     NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path(TestDir3)));
     TestFailureToReadEdits.LimitedEditLogAnswer answer = CauseFailureOnEditLogRead();
     try
     {
         HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
         NUnit.Framework.Assert.Fail("Standby fully caught up, but should not have been able to"
                                     );
     }
     catch (HATestUtil.CouldNotCatchUpException)
     {
     }
     // Expected. The NN did not exit.
     // Null because it was deleted.
     NUnit.Framework.Assert.IsNull(NameNodeAdapter.GetFileInfo(nn1, TestDir1, false));
     // Should have been successfully created.
     NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(nn1, TestDir2, false).IsDir
                                       ());
     // Null because it hasn't been created yet.
     NUnit.Framework.Assert.IsNull(NameNodeAdapter.GetFileInfo(nn1, TestDir3, false));
     // Now let the standby read ALL the edits.
     answer.SetThrowExceptionOnRead(false);
     HATestUtil.WaitForStandbyToCatchUp(nn0, nn1);
     // Null because it was deleted.
     NUnit.Framework.Assert.IsNull(NameNodeAdapter.GetFileInfo(nn1, TestDir1, false));
     // Should have been successfully created.
     NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(nn1, TestDir2, false).IsDir
                                       ());
     // Should now have been successfully created.
     NUnit.Framework.Assert.IsTrue(NameNodeAdapter.GetFileInfo(nn1, TestDir3, false).IsDir
                                       ());
 }