示例#1
0
        /* End of Under-Construction Feature */
        /* Start of Snapshot Feature */
        public virtual FileWithSnapshotFeature AddSnapshotFeature(FileDiffList diffs)
        {
            Preconditions.CheckState(!IsWithSnapshot(), "File is already with snapshot");
            FileWithSnapshotFeature sf = new FileWithSnapshotFeature(diffs);

            this.AddFeature(sf);
            return(sf);
        }
示例#2
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);
        }
示例#3
0
        public sealed override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                                      summary)
        {
            ContentCounts           counts = summary.GetCounts();
            FileWithSnapshotFeature sf     = GetFileWithSnapshotFeature();
            long fileLen = 0;

            if (sf == null)
            {
                fileLen = ComputeFileSize();
                counts.AddContent(Content.File, 1);
            }
            else
            {
                FileDiffList diffs = sf.GetDiffs();
                int          n     = diffs.AsList().Count;
                counts.AddContent(Content.File, n);
                if (n > 0 && sf.IsCurrentFileDeleted())
                {
                    fileLen = diffs.GetLast().GetFileSize();
                }
                else
                {
                    fileLen = ComputeFileSize();
                }
            }
            counts.AddContent(Content.Length, fileLen);
            counts.AddContent(Content.Diskspace, StoragespaceConsumed());
            if (GetStoragePolicyID() != BlockStoragePolicySuite.IdUnspecified)
            {
                BlockStoragePolicy bsp = summary.GetBlockStoragePolicySuite().GetPolicy(GetStoragePolicyID
                                                                                            ());
                IList <StorageType> storageTypes = bsp.ChooseStorageTypes(GetFileReplication());
                foreach (StorageType t in storageTypes)
                {
                    if (!t.SupportTypeQuota())
                    {
                        continue;
                    }
                    counts.AddTypeSpace(t, fileLen);
                }
            }
            return(summary);
        }
示例#4
0
 public INodeFile(INodeFile that, FileDiffList diffs)
     : this(that)
 {
     Preconditions.CheckArgument(!that.IsWithSnapshot());
     this.AddSnapshotFeature(diffs);
 }