Exemplo n.º 1
0
        public virtual void TestRestartDFS()
        {
            Configuration  conf    = new HdfsConfiguration();
            MiniDFSCluster cluster = null;
            FSNamesystem   fsn     = null;
            int            numNamenodeDirs;
            DFSTestUtil    files = new DFSTestUtil.Builder().SetName("TestRestartDFS").SetNumFiles
                                       (200).Build();
            string     dir      = "/srcdat";
            Path       rootpath = new Path("/");
            Path       dirpath  = new Path(dir);
            long       rootmtime;
            FileStatus rootstatus;
            FileStatus dirstatus;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).Format(true).NumDataNodes(NumDatanodes
                                                                                     ).Build();
                string[] nameNodeDirs = conf.GetStrings(DFSConfigKeys.DfsNamenodeNameDirKey, new
                                                        string[] {  });
                numNamenodeDirs = nameNodeDirs.Length;
                NUnit.Framework.Assert.IsTrue("failed to get number of Namenode StorageDirs", numNamenodeDirs
                                              != 0);
                FileSystem fs = cluster.GetFileSystem();
                files.CreateFiles(fs, dir);
                rootmtime  = fs.GetFileStatus(rootpath).GetModificationTime();
                rootstatus = fs.GetFileStatus(dirpath);
                dirstatus  = fs.GetFileStatus(dirpath);
                fs.SetOwner(rootpath, rootstatus.GetOwner() + "_XXX", null);
                fs.SetOwner(dirpath, null, dirstatus.GetGroup() + "_XXX");
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
            try
            {
                // Force the NN to save its images on startup so long as
                // there are any uncheckpointed txns
                conf.SetInt(DFSConfigKeys.DfsNamenodeCheckpointTxnsKey, 1);
                // Here we restart the MiniDFScluster without formatting namenode
                cluster = new MiniDFSCluster.Builder(conf).Format(false).NumDataNodes(NumDatanodes
                                                                                      ).Build();
                fsn = cluster.GetNamesystem();
                FileSystem fs = cluster.GetFileSystem();
                NUnit.Framework.Assert.IsTrue("Filesystem corrupted after restart.", files.CheckFiles
                                                  (fs, dir));
                FileStatus newrootstatus = fs.GetFileStatus(rootpath);
                NUnit.Framework.Assert.AreEqual(rootmtime, newrootstatus.GetModificationTime());
                NUnit.Framework.Assert.AreEqual(rootstatus.GetOwner() + "_XXX", newrootstatus.GetOwner
                                                    ());
                NUnit.Framework.Assert.AreEqual(rootstatus.GetGroup(), newrootstatus.GetGroup());
                FileStatus newdirstatus = fs.GetFileStatus(dirpath);
                NUnit.Framework.Assert.AreEqual(dirstatus.GetOwner(), newdirstatus.GetOwner());
                NUnit.Framework.Assert.AreEqual(dirstatus.GetGroup() + "_XXX", newdirstatus.GetGroup
                                                    ());
                rootmtime = fs.GetFileStatus(rootpath).GetModificationTime();
                string checkAfterRestart = CheckImages(fsn, numNamenodeDirs);
                // Modify the system and then perform saveNamespace
                files.Cleanup(fs, dir);
                files.CreateFiles(fs, dir);
                fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                cluster.GetNameNodeRpc().SaveNamespace();
                string checkAfterModify = CheckImages(fsn, numNamenodeDirs);
                NUnit.Framework.Assert.IsFalse("Modified namespace should change fsimage contents. "
                                               + "was: " + checkAfterRestart + " now: " + checkAfterModify, checkAfterRestart.
                                               Equals(checkAfterModify));
                fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
                files.Cleanup(fs, dir);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }