Example #1
0
        /// <summary>Check whether the secondary name-node can be started.</summary>
        /// <exception cref="System.IO.IOException"/>
        private bool CanStartSecondaryNode(Configuration conf)
        {
            // Using full name allows us not to have to add deprecation tag to
            // entire source file.
            SecondaryNameNode sn = null;

            try
            {
                sn = new SecondaryNameNode(conf);
            }
            catch (IOException e)
            {
                if (e is BindException)
                {
                    return(false);
                }
                throw;
            }
            finally
            {
                if (sn != null)
                {
                    sn.Shutdown();
                }
            }
            return(true);
        }
        public virtual void TestCheckpointWithSNN()
        {
            MiniDFSCluster        cluster = null;
            DistributedFileSystem dfs     = null;
            SecondaryNameNode     snn     = null;

            try
            {
                Configuration conf = new HdfsConfiguration();
                cluster = new MiniDFSCluster.Builder(conf).Build();
                cluster.WaitActive();
                conf.Set(DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey, "0.0.0.0:0");
                snn = new SecondaryNameNode(conf);
                dfs = cluster.GetFileSystem();
                dfs.Mkdirs(new Path("/test/foo"));
                snn.DoCheckpoint();
                //start rolling upgrade
                dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare);
                dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
                dfs.Mkdirs(new Path("/test/bar"));
                // do checkpoint in SNN again
                snn.DoCheckpoint();
            }
            finally
            {
                IOUtils.Cleanup(null, dfs);
                if (snn != null)
                {
                    snn.Shutdown();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual bool IsValidRequestor(HttpServletRequest request, Configuration
                                                         conf)
        {
            string remotePrincipal = request.GetUserPrincipal().GetName();
            string remoteShortName = request.GetRemoteUser();

            if (remotePrincipal == null)
            {
                // This really shouldn't happen...
                Log.Warn("Received null remoteUser while authorizing access to " + "GetJournalEditServlet"
                         );
                return(false);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Validating request made by " + remotePrincipal + " / " + remoteShortName
                          + ". This user is: " + UserGroupInformation.GetLoginUser());
            }
            ICollection <string> validRequestors = new HashSet <string>();

            Sharpen.Collections.AddAll(validRequestors, DFSUtil.GetAllNnPrincipals(conf));
            try
            {
                validRequestors.AddItem(SecurityUtil.GetServerPrincipal(conf.Get(DFSConfigKeys.DfsSecondaryNamenodeKerberosPrincipalKey
                                                                                 ), SecondaryNameNode.GetHttpAddress(conf).GetHostName()));
            }
            catch (Exception e)
            {
                // Don't halt if SecondaryNameNode principal could not be added.
                Log.Debug("SecondaryNameNode principal could not be added", e);
                string msg = string.Format("SecondaryNameNode principal not considered, %s = %s, %s = %s"
                                           , DFSConfigKeys.DfsSecondaryNamenodeKerberosPrincipalKey, conf.Get(DFSConfigKeys
                                                                                                              .DfsSecondaryNamenodeKerberosPrincipalKey), DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey
                                           , conf.Get(DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey, DFSConfigKeys.DfsNamenodeSecondaryHttpAddressDefault
                                                      ));
                Log.Warn(msg);
            }
            // Check the full principal name of all the configured valid requestors.
            foreach (string v in validRequestors)
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("isValidRequestor is comparing to valid requestor: " + v);
                }
                if (v != null && v.Equals(remotePrincipal))
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("isValidRequestor is allowing: " + remotePrincipal);
                    }
                    return(true);
                }
            }
            // Additionally, we compare the short name of the requestor to this JN's
            // username, because we want to allow requests from other JNs during
            // recovery, but we can't enumerate the full list of JNs.
            if (remoteShortName.Equals(UserGroupInformation.GetLoginUser().GetShortUserName()
                                       ))
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("isValidRequestor is allowing other JN principal: " + remotePrincipal);
                }
                return(true);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("isValidRequestor is rejecting: " + remotePrincipal);
            }
            return(false);
        }
Example #4
0
        public virtual void TestCheckpoint()
        {
            MiniDFSCluster    cluster   = null;
            SecondaryNameNode secondary = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).Build();
                cluster.WaitActive();
                secondary = new SecondaryNameNode(conf);
                SnapshotManager nnSnapshotManager        = cluster.GetNamesystem().GetSnapshotManager();
                SnapshotManager secondarySnapshotManager = secondary.GetFSNamesystem().GetSnapshotManager
                                                               ();
                FileSystem fs    = cluster.GetFileSystem();
                HdfsAdmin  admin = new HdfsAdmin(FileSystem.GetDefaultUri(conf), conf);
                NUnit.Framework.Assert.AreEqual(0, nnSnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(0, nnSnapshotManager.GetNumSnapshottableDirs());
                NUnit.Framework.Assert.AreEqual(0, secondarySnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(0, secondarySnapshotManager.GetNumSnapshottableDirs
                                                    ());
                // 1. Create a snapshottable directory foo on the NN.
                fs.Mkdirs(TestPath);
                admin.AllowSnapshot(TestPath);
                NUnit.Framework.Assert.AreEqual(0, nnSnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(1, nnSnapshotManager.GetNumSnapshottableDirs());
                // 2. Create a snapshot of the dir foo. This will be referenced both in
                // the SnapshotManager as well as in the file system tree. The snapshot
                // count will go up to 1.
                Path snapshotPath = fs.CreateSnapshot(TestPath);
                NUnit.Framework.Assert.AreEqual(1, nnSnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(1, nnSnapshotManager.GetNumSnapshottableDirs());
                // 3. Start up a 2NN and have it do a checkpoint. It will have foo and its
                // snapshot in its list of snapshottable dirs referenced from the
                // SnapshotManager, as well as in the file system tree.
                secondary.DoCheckpoint();
                NUnit.Framework.Assert.AreEqual(1, secondarySnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(1, secondarySnapshotManager.GetNumSnapshottableDirs
                                                    ());
                // 4. Disallow snapshots on and delete foo on the NN. The snapshot count
                // will go down to 0 and the snapshottable dir will be removed from the fs
                // tree.
                fs.DeleteSnapshot(TestPath, snapshotPath.GetName());
                admin.DisallowSnapshot(TestPath);
                NUnit.Framework.Assert.AreEqual(0, nnSnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(0, nnSnapshotManager.GetNumSnapshottableDirs());
                // 5. Have the NN do a saveNamespace, writing out a new fsimage with
                // snapshot count 0.
                NameNodeAdapter.EnterSafeMode(cluster.GetNameNode(), false);
                NameNodeAdapter.SaveNamespace(cluster.GetNameNode());
                NameNodeAdapter.LeaveSafeMode(cluster.GetNameNode());
                // 6. Have the still-running 2NN do a checkpoint. It will notice that the
                // fsimage has changed on the NN and redownload/reload from that image.
                // This will replace all INodes in the file system tree as well as reset
                // the snapshot counter to 0 in the SnapshotManager. However, it will not
                // clear the list of snapshottable dirs referenced from the
                // SnapshotManager. When it writes out an fsimage, the 2NN will write out
                // 0 for the snapshot count, but still serialize the snapshottable dir
                // referenced in the SnapshotManager even though it no longer appears in
                // the file system tree. The NN will not be able to start up with this.
                secondary.DoCheckpoint();
                NUnit.Framework.Assert.AreEqual(0, secondarySnapshotManager.GetNumSnapshots());
                NUnit.Framework.Assert.AreEqual(0, secondarySnapshotManager.GetNumSnapshottableDirs
                                                    ());
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
                if (secondary != null)
                {
                    secondary.Shutdown();
                }
            }
        }