예제 #1
0
        public virtual void TestQuotaByStorageTypePersistenceInFsImage()
        {
            string MethodName   = GenericTestUtils.GetMethodName();
            Path   testDir      = new Path(dir, MethodName);
            Path   createdFile1 = new Path(testDir, "created_file1.data");

            dfs.Mkdirs(testDir);
            // set storage policy on testDir to ONESSD
            dfs.SetStoragePolicy(testDir, HdfsConstants.OnessdStoragePolicyName);
            // set quota by storage type on testDir
            long SsdQuota = Blocksize * 4;

            dfs.SetQuotaByStorageType(testDir, StorageType.Ssd, SsdQuota);
            INode testDirNode = fsdir.GetINode4Write(testDir.ToString());

            NUnit.Framework.Assert.IsTrue(testDirNode.IsDirectory());
            NUnit.Framework.Assert.IsTrue(testDirNode.IsQuotaSet());
            // Create file of size 2 * BLOCKSIZE under testDir
            long file1Len = Blocksize * 2;
            int  bufLen   = Blocksize / 16;

            DFSTestUtil.CreateFile(dfs, createdFile1, bufLen, file1Len, Blocksize, Replication
                                   , seed);
            // Verify SSD consumed before namenode restart
            long ssdConsumed = testDirNode.AsDirectory().GetDirectoryWithQuotaFeature().GetSpaceConsumed
                                   ().GetTypeSpaces().Get(StorageType.Ssd);

            NUnit.Framework.Assert.AreEqual(file1Len, ssdConsumed);
            // Restart the namenode with checkpoint to make sure fsImage is correct
            dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
            dfs.SaveNamespace();
            dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
            cluster.RestartNameNode(true);
            RefreshClusterState();
            INode testDirNodeAfterNNRestart = fsdir.GetINode4Write(testDir.ToString());

            NUnit.Framework.Assert.IsTrue(testDirNode.IsDirectory());
            NUnit.Framework.Assert.IsTrue(testDirNode.IsQuotaSet());
            QuotaCounts qc = testDirNodeAfterNNRestart.GetQuotaCounts();

            NUnit.Framework.Assert.AreEqual(SsdQuota, qc.GetTypeSpace(StorageType.Ssd));
            foreach (StorageType t in StorageType.GetTypesSupportingQuota())
            {
                if (t != StorageType.Ssd)
                {
                    NUnit.Framework.Assert.AreEqual(HdfsConstants.QuotaReset, qc.GetTypeSpace(t));
                }
            }
            long ssdConsumedAfterNNRestart = testDirNodeAfterNNRestart.AsDirectory().GetDirectoryWithQuotaFeature
                                                 ().GetSpaceConsumed().GetTypeSpaces().Get(StorageType.Ssd);

            NUnit.Framework.Assert.AreEqual(file1Len, ssdConsumedAfterNNRestart);
        }
예제 #2
0
 /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaByStorageTypeExceededException
 ///     "/>
 private void VerifyQuotaByStorageType(EnumCounters <StorageType> typeDelta)
 {
     if (!IsQuotaByStorageTypeSet())
     {
         return;
     }
     foreach (StorageType t in StorageType.GetTypesSupportingQuota())
     {
         if (!IsQuotaByStorageTypeSet(t))
         {
             continue;
         }
         if (Quota.IsViolated(quota.GetTypeSpace(t), usage.GetTypeSpace(t), typeDelta.Get(
                                  t)))
         {
             throw new QuotaByStorageTypeExceededException(quota.GetTypeSpace(t), usage.GetTypeSpace
                                                               (t) + typeDelta.Get(t), t);
         }
     }
 }
예제 #3
0
 private static FsImageProto.INodeSection.QuotaByStorageTypeFeatureProto.Builder BuildQuotaByStorageTypeEntries
     (QuotaCounts q)
 {
     FsImageProto.INodeSection.QuotaByStorageTypeFeatureProto.Builder b = FsImageProto.INodeSection.QuotaByStorageTypeFeatureProto
                                                                          .NewBuilder();
     foreach (StorageType t in StorageType.GetTypesSupportingQuota())
     {
         if (q.GetTypeSpace(t) >= 0)
         {
             FsImageProto.INodeSection.QuotaByStorageTypeEntryProto.Builder eb = FsImageProto.INodeSection.QuotaByStorageTypeEntryProto
                                                                                 .NewBuilder().SetStorageType(PBHelper.ConvertStorageType(t)).SetQuota(q.GetTypeSpace
                                                                                                                                                           (t));
             b.AddQuotas(eb);
         }
     }
     return(b);
 }