public virtual void TestLowResourceVolumePolicy()
        {
            Configuration conf     = new Configuration();
            FilePath      nameDir1 = new FilePath(BaseDir, "name-dir1");
            FilePath      nameDir2 = new FilePath(BaseDir, "name-dir2");

            nameDir1.Mkdirs();
            nameDir2.Mkdirs();
            conf.Set(DFSConfigKeys.DfsNamenodeEditsDirKey, nameDir1.GetAbsolutePath() + "," +
                     nameDir2.GetAbsolutePath());
            conf.SetInt(DFSConfigKeys.DfsNamenodeCheckedVolumesMinimumKey, 2);
            NameNodeResourceChecker nnrc = new NameNodeResourceChecker(conf);
            // For the purpose of this test, we need to force the name dirs to appear to
            // be on different volumes.
            IDictionary <string, NameNodeResourceChecker.CheckedVolume> volumes = new Dictionary
                                                                                  <string, NameNodeResourceChecker.CheckedVolume>();

            NameNodeResourceChecker.CheckedVolume volume1 = Org.Mockito.Mockito.Mock <NameNodeResourceChecker.CheckedVolume
                                                                                      >();
            NameNodeResourceChecker.CheckedVolume volume2 = Org.Mockito.Mockito.Mock <NameNodeResourceChecker.CheckedVolume
                                                                                      >();
            NameNodeResourceChecker.CheckedVolume volume3 = Org.Mockito.Mockito.Mock <NameNodeResourceChecker.CheckedVolume
                                                                                      >();
            NameNodeResourceChecker.CheckedVolume volume4 = Org.Mockito.Mockito.Mock <NameNodeResourceChecker.CheckedVolume
                                                                                      >();
            NameNodeResourceChecker.CheckedVolume volume5 = Org.Mockito.Mockito.Mock <NameNodeResourceChecker.CheckedVolume
                                                                                      >();
            Org.Mockito.Mockito.When(volume1.IsResourceAvailable()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume2.IsResourceAvailable()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume3.IsResourceAvailable()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume4.IsResourceAvailable()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume5.IsResourceAvailable()).ThenReturn(true);
            // Make volumes 4 and 5 required.
            Org.Mockito.Mockito.When(volume4.IsRequired()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume5.IsRequired()).ThenReturn(true);
            volumes["volume1"] = volume1;
            volumes["volume2"] = volume2;
            volumes["volume3"] = volume3;
            volumes["volume4"] = volume4;
            volumes["volume5"] = volume5;
            nnrc.SetVolumes(volumes);
            // Initially all dirs have space.
            NUnit.Framework.Assert.IsTrue(nnrc.HasAvailableDiskSpace());
            // 1/3 redundant dir is low on space.
            Org.Mockito.Mockito.When(volume1.IsResourceAvailable()).ThenReturn(false);
            NUnit.Framework.Assert.IsTrue(nnrc.HasAvailableDiskSpace());
            // 2/3 redundant dirs are low on space.
            Org.Mockito.Mockito.When(volume2.IsResourceAvailable()).ThenReturn(false);
            NUnit.Framework.Assert.IsFalse(nnrc.HasAvailableDiskSpace());
            // Lower the minimum number of redundant volumes that must be available.
            nnrc.SetMinimumReduntdantVolumes(1);
            NUnit.Framework.Assert.IsTrue(nnrc.HasAvailableDiskSpace());
            // Just one required dir is low on space.
            Org.Mockito.Mockito.When(volume3.IsResourceAvailable()).ThenReturn(false);
            NUnit.Framework.Assert.IsFalse(nnrc.HasAvailableDiskSpace());
            // Just the other required dir is low on space.
            Org.Mockito.Mockito.When(volume3.IsResourceAvailable()).ThenReturn(true);
            Org.Mockito.Mockito.When(volume4.IsResourceAvailable()).ThenReturn(false);
            NUnit.Framework.Assert.IsFalse(nnrc.HasAvailableDiskSpace());
        }
Example #2
0
        /// <summary>Add the volume of the passed-in directory to the list of volumes to check.
        ///     </summary>
        /// <remarks>
        /// Add the volume of the passed-in directory to the list of volumes to check.
        /// If <code>required</code> is true, and this volume is already present, but
        /// is marked redundant, it will be marked required. If the volume is already
        /// present but marked required then this method is a no-op.
        /// </remarks>
        /// <param name="directoryToCheck">The directory whose volume will be checked for available space.
        ///     </param>
        /// <exception cref="System.IO.IOException"/>
        private void AddDirToCheck(URI directoryToCheck, bool required)
        {
            FilePath dir = new FilePath(directoryToCheck.GetPath());

            if (!dir.Exists())
            {
                throw new IOException("Missing directory " + dir.GetAbsolutePath());
            }
            NameNodeResourceChecker.CheckedVolume newVolume = new NameNodeResourceChecker.CheckedVolume
                                                                  (this, dir, required);
            NameNodeResourceChecker.CheckedVolume volume = volumes[newVolume.GetVolume()];
            if (volume == null || !volume.IsRequired())
            {
                volumes[newVolume.GetVolume()] = newVolume;
            }
        }