Esempio n. 1
0
        // This is the only place that needs to use the BlockStoragePolicySuite to
        // derive the intended storage type usage for quota by storage type
        public sealed override QuotaCounts ComputeQuotaUsage(BlockStoragePolicySuite bsps
                                                             , byte blockStoragePolicyId, QuotaCounts counts, bool useCache, int lastSnapshotId
                                                             )
        {
            long  nsDelta = 1;
            long  ssDeltaNoReplication;
            short replication;
            FileWithSnapshotFeature sf = GetFileWithSnapshotFeature();

            if (sf != null)
            {
                FileDiffList fileDiffList = sf.GetDiffs();
                int          last         = fileDiffList.GetLastSnapshotId();
                if (lastSnapshotId == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId ||
                    last == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId)
                {
                    ssDeltaNoReplication = StoragespaceConsumedNoReplication();
                    replication          = GetBlockReplication();
                }
                else
                {
                    if (last < lastSnapshotId)
                    {
                        ssDeltaNoReplication = ComputeFileSize(true, false);
                        replication          = GetFileReplication();
                    }
                    else
                    {
                        int sid = fileDiffList.GetSnapshotById(lastSnapshotId);
                        ssDeltaNoReplication = StoragespaceConsumedNoReplication(sid);
                        replication          = GetReplication(sid);
                    }
                }
            }
            else
            {
                ssDeltaNoReplication = StoragespaceConsumedNoReplication();
                replication          = GetBlockReplication();
            }
            counts.AddNameSpace(nsDelta);
            counts.AddStorageSpace(ssDeltaNoReplication * replication);
            if (blockStoragePolicyId != BlockStoragePolicySuite.IdUnspecified)
            {
                BlockStoragePolicy  bsp          = bsps.GetPolicy(blockStoragePolicyId);
                IList <StorageType> storageTypes = bsp.ChooseStorageTypes(replication);
                foreach (StorageType t in storageTypes)
                {
                    if (!t.SupportTypeQuota())
                    {
                        continue;
                    }
                    counts.AddTypeSpace(t, ssDeltaNoReplication);
                }
            }
            return(counts);
        }