public virtual void TestRollbackWithQJM()
        {
            Configuration      conf    = new HdfsConfiguration();
            MiniJournalCluster mjc     = null;
            MiniDFSCluster     cluster = null;
            Path foo = new Path("/foo");
            Path bar = new Path("/bar");

            try
            {
                mjc = new MiniJournalCluster.Builder(conf).NumJournalNodes(NumJournalNodes).Build
                          ();
                conf.Set(DFSConfigKeys.DfsNamenodeEditsDirKey, mjc.GetQuorumJournalURI(JournalId)
                         .ToString());
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build();
                cluster.WaitActive();
                DistributedFileSystem dfs = cluster.GetFileSystem();
                DFSAdmin dfsadmin         = new DFSAdmin(conf);
                dfs.Mkdirs(foo);
                // start rolling upgrade
                dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                NUnit.Framework.Assert.AreEqual(0, dfsadmin.Run(new string[] { "-rollingUpgrade",
                                                                               "prepare" }));
                dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
                // create new directory
                dfs.Mkdirs(bar);
                dfs.Close();
                // rollback
                cluster.RestartNameNode("-rollingUpgrade", "rollback");
                // make sure /foo is still there, but /bar is not
                dfs = cluster.GetFileSystem();
                NUnit.Framework.Assert.IsTrue(dfs.Exists(foo));
                NUnit.Framework.Assert.IsFalse(dfs.Exists(bar));
                // check storage in JNs
                for (int i = 0; i < NumJournalNodes; i++)
                {
                    FilePath dir = mjc.GetCurrentDir(0, JournalId);
                    // segments:(startSegment, mkdir, endSegment), (startSegment, upgrade
                    // marker, mkdir, endSegment)
                    CheckJNStorage(dir, 4, 7);
                }
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
                if (mjc != null)
                {
                    mjc.Shutdown();
                }
            }
        }
Beispiel #2
0
        public virtual void TestSingleThreaded()
        {
            Configuration      conf    = new Configuration();
            MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).Build();
            URI uri = cluster.GetQuorumJournalURI(Jid);
            QuorumJournalManager qjm = new QuorumJournalManager(conf, uri, FakeNsinfo);

            try
            {
                qjm.Format(FakeNsinfo);
            }
            finally
            {
                qjm.Close();
            }
            try
            {
                // With no failures or contention, epochs should increase one-by-one
                for (int i = 0; i < 5; i++)
                {
                    qjm = new QuorumJournalManager(conf, uri, FakeNsinfo);
                    try
                    {
                        qjm.CreateNewUniqueEpoch();
                        NUnit.Framework.Assert.AreEqual(i + 1, qjm.GetLoggerSetForTests().GetEpoch());
                    }
                    finally
                    {
                        qjm.Close();
                    }
                }
                long prevEpoch = 5;
                // With some failures injected, it should still always increase, perhaps
                // skipping some
                for (int i_1 = 0; i_1 < 20; i_1++)
                {
                    long newEpoch = -1;
                    while (true)
                    {
                        qjm = new QuorumJournalManager(conf, uri, FakeNsinfo, new TestEpochsAreUnique.FaultyLoggerFactory
                                                           (this));
                        try
                        {
                            qjm.CreateNewUniqueEpoch();
                            newEpoch = qjm.GetLoggerSetForTests().GetEpoch();
                            break;
                        }
                        catch (IOException)
                        {
                        }
                        finally
                        {
                            // It's OK to fail to create an epoch, since we randomly inject
                            // faults. It's possible we'll inject faults in too many of the
                            // underlying nodes, and a failure is expected in that case
                            qjm.Close();
                        }
                    }
                    Log.Info("Created epoch " + newEpoch);
                    NUnit.Framework.Assert.IsTrue("New epoch " + newEpoch + " should be greater than previous "
                                                  + prevEpoch, newEpoch > prevEpoch);
                    prevEpoch = newEpoch;
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }