예제 #1
0
 private void RemoveStandbyNameDirs()
 {
     foreach (URI u in cluster.GetNameDirs(1))
     {
         NUnit.Framework.Assert.IsTrue(u.GetScheme().Equals("file"));
         FilePath dir = new FilePath(u.GetPath());
         Log.Info("Removing standby dir " + dir);
         NUnit.Framework.Assert.IsTrue(FileUtil.FullyDelete(dir));
     }
 }
예제 #2
0
        private static void CheckNnPreviousDirExistence(MiniDFSCluster cluster, int index
                                                        , bool shouldExist)
        {
            ICollection <URI> nameDirs = cluster.GetNameDirs(index);

            foreach (URI nnDir in nameDirs)
            {
                CheckPreviousDirExistence(new FilePath(nnDir), shouldExist);
            }
        }
예제 #3
0
        public static IList <FilePath> GetNameNodeCurrentDirs(MiniDFSCluster cluster, int
                                                              nnIdx)
        {
            IList <FilePath> nameDirs = Lists.NewArrayList();

            foreach (URI u in cluster.GetNameDirs(nnIdx))
            {
                nameDirs.AddItem(new FilePath(u.GetPath(), "current"));
            }
            return(nameDirs);
        }
예제 #4
0
        /// <returns>the fsimage with highest transaction ID in the cluster.</returns>
        private static FilePath GetHighestFsImageOnCluster(MiniDFSCluster cluster)
        {
            long     highestImageTxId = -1;
            FilePath highestImageOnNn = null;

            foreach (URI nameDir in cluster.GetNameDirs(0))
            {
                foreach (FilePath imageFile in new FilePath(new FilePath(nameDir), "current").ListFiles
                             ())
                {
                    Matcher imageMatch = ImageRegex.Matcher(imageFile.GetName());
                    if (imageMatch.Matches())
                    {
                        long imageTxId = long.Parse(imageMatch.Group(1));
                        if (imageTxId > highestImageTxId)
                        {
                            highestImageTxId = imageTxId;
                            highestImageOnNn = imageFile;
                        }
                    }
                }
            }
            return(highestImageOnNn);
        }
예제 #5
0
        public virtual void TestRollbackWithJournalNodes()
        {
            MiniQJMHACluster qjCluster = null;
            FileSystem       fs        = null;

            try
            {
                MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf);
                builder.GetDfsBuilder().NumDataNodes(0);
                qjCluster = builder.Build();
                MiniDFSCluster cluster = qjCluster.GetDfsCluster();
                // No upgrade is in progress at the moment.
                CheckClusterPreviousDirExistence(cluster, false);
                AssertCTimesEqual(cluster);
                CheckJnPreviousDirExistence(qjCluster, 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")));
                long cidBeforeUpgrade = GetCommittedTxnIdValue(qjCluster);
                // 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);
                CheckJnPreviousDirExistence(qjCluster, 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")));
                long cidDuringUpgrade = GetCommittedTxnIdValue(qjCluster);
                NUnit.Framework.Assert.IsTrue(cidDuringUpgrade > cidBeforeUpgrade);
                // Now bootstrap the standby with the upgraded info.
                int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration
                                                  (1));
                NUnit.Framework.Assert.AreEqual(0, rc);
                cluster.RestartNameNode(1);
                CheckNnPreviousDirExistence(cluster, 0, true);
                CheckNnPreviousDirExistence(cluster, 1, true);
                CheckJnPreviousDirExistence(qjCluster, true);
                AssertCTimesEqual(cluster);
                // Shut down the NNs, but deliberately leave the JNs up and running.
                ICollection <URI> nn1NameDirs = cluster.GetNameDirs(0);
                cluster.Shutdown();
                conf.SetStrings(DFSConfigKeys.DfsNamenodeNameDirKey, Joiner.On(",").Join(nn1NameDirs
                                                                                         ));
                NameNode.DoRollback(conf, false);
                long cidAfterRollback = GetCommittedTxnIdValue(qjCluster);
                NUnit.Framework.Assert.IsTrue(cidBeforeUpgrade < cidAfterRollback);
                // make sure the committedTxnId has been reset correctly after rollback
                NUnit.Framework.Assert.IsTrue(cidDuringUpgrade > cidAfterRollback);
                // The rollback operation should have rolled back the first NN's local
                // dirs, and the shared dir, but not the other NN's dirs. Those have to be
                // done by bootstrapping the standby.
                CheckNnPreviousDirExistence(cluster, 0, false);
                CheckJnPreviousDirExistence(qjCluster, false);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (qjCluster != null)
                {
                    qjCluster.Shutdown();
                }
            }
        }