/// <exception cref="System.IO.IOException"/>
 private static ContentSummary GetContentSummaryInt(FSDirectory fsd, INodesInPath
                                                    iip)
 {
     fsd.ReadLock();
     try
     {
         INode targetNode = iip.GetLastINode();
         if (targetNode == null)
         {
             throw new FileNotFoundException("File does not exist: " + iip.GetPath());
         }
         else
         {
             // Make it relinquish locks everytime contentCountLimit entries are
             // processed. 0 means disabled. I.e. blocking for the entire duration.
             ContentSummaryComputationContext cscc = new ContentSummaryComputationContext(fsd,
                                                                                          fsd.GetFSNamesystem(), fsd.GetContentCountLimit(), fsd.GetContentSleepMicroSec()
                                                                                          );
             ContentSummary cs = targetNode.ComputeAndConvertContentSummary(cscc);
             fsd.AddYieldCount(cscc.GetYieldCount());
             return(cs);
         }
     }
     finally
     {
         fsd.ReadUnlock();
     }
 }
Exemple #2
0
        /// <summary>
        /// Compute
        /// <see cref="Org.Apache.Hadoop.FS.ContentSummary"/>
        /// .
        /// </summary>
        public ContentSummary ComputeAndConvertContentSummary(ContentSummaryComputationContext
                                                              summary)
        {
            ContentCounts counts = ComputeContentSummary(summary).GetCounts();
            QuotaCounts   q      = GetQuotaCounts();

            return(new ContentSummary.Builder().Length(counts.GetLength()).FileCount(counts.GetFileCount
                                                                                         () + counts.GetSymlinkCount()).DirectoryCount(counts.GetDirectoryCount()).Quota(
                       q.GetNameSpace()).SpaceConsumed(counts.GetStoragespace()).SpaceQuota(q.GetStorageSpace
                                                                                                ()).TypeConsumed(counts.GetTypeSpaces()).TypeQuota(q.GetTypeSpaces().AsArray()).
                   Build());
        }
Exemple #3
0
        internal ContentSummaryComputationContext ComputeContentSummary(INodeDirectory dir
                                                                        , ContentSummaryComputationContext summary)
        {
            long original      = summary.GetCounts().GetStoragespace();
            long oldYieldCount = summary.GetYieldCount();

            dir.ComputeDirectoryContentSummary(summary, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                               .CurrentStateId);
            // Check only when the content has not changed in the middle.
            if (oldYieldCount == summary.GetYieldCount())
            {
                CheckStoragespace(dir, summary.GetCounts().GetStoragespace() - original);
            }
            return(summary);
        }
        public override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                               summary)
        {
            DirectoryWithSnapshotFeature sf = GetDirectoryWithSnapshotFeature();

            if (sf != null)
            {
                sf.ComputeContentSummary4Snapshot(summary.GetBlockStoragePolicySuite(), summary.GetCounts
                                                      ());
            }
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            if (q != null)
            {
                return(q.ComputeContentSummary(this, summary));
            }
            else
            {
                return(ComputeDirectoryContentSummary(summary, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                      .CurrentStateId));
            }
        }
        protected internal virtual ContentSummaryComputationContext ComputeDirectoryContentSummary
            (ContentSummaryComputationContext summary, int snapshotId)
        {
            ReadOnlyList <INode> childrenList = GetChildrenList(snapshotId);

            // Explicit traversing is done to enable repositioning after relinquishing
            // and reacquiring locks.
            for (int i = 0; i < childrenList.Size(); i++)
            {
                INode  child          = childrenList.Get(i);
                byte[] childName      = child.GetLocalNameBytes();
                long   lastYieldCount = summary.GetYieldCount();
                child.ComputeContentSummary(summary);
                // Check whether the computation was paused in the subtree.
                // The counts may be off, but traversing the rest of children
                // should be made safe.
                if (lastYieldCount == summary.GetYieldCount())
                {
                    continue;
                }
                // The locks were released and reacquired. Check parent first.
                if (GetParent() == null)
                {
                    // Stop further counting and return whatever we have so far.
                    break;
                }
                // Obtain the children list again since it may have been modified.
                childrenList = GetChildrenList(snapshotId);
                // Reposition in case the children list is changed. Decrement by 1
                // since it will be incremented when loops.
                i = NextChild(childrenList, childName) - 1;
            }
            // Increment the directory count for this directory.
            summary.GetCounts().AddContent(Content.Directory, 1);
            // Relinquish and reacquire locks if necessary.
            summary.Yield();
            return(summary);
        }
Exemple #6
0
 /// <summary>
 /// Count subtree content summary with a
 /// <see cref="ContentCounts"/>
 /// .
 /// </summary>
 /// <param name="summary">the context object holding counts for the subtree.</param>
 /// <returns>The same objects as summary.</returns>
 public abstract ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                        summary);
Exemple #7
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);
        }
Exemple #8
0
 public override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                        summary)
 {
     summary.GetCounts().AddContent(Content.Symlink, 1);
     return(summary);
 }
Exemple #9
0
            public sealed override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                                          summary)
            {
                //only count storagespace for WithName
                QuotaCounts q = new QuotaCounts.Builder().Build();

                ComputeQuotaUsage(summary.GetBlockStoragePolicySuite(), GetStoragePolicyID(), q,
                                  false, lastSnapshotId);
                summary.GetCounts().AddContent(Content.Diskspace, q.GetStorageSpace());
                summary.GetCounts().AddTypeSpaces(q.GetTypeSpaces());
                return(summary);
            }
Exemple #10
0
 public override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                        summary)
 {
     return(referred.ComputeContentSummary(summary));
 }
Exemple #11
0
 public override ContentSummaryComputationContext ComputeContentSummary(ContentSummaryComputationContext
                                                                        summary)
 {
     return(null);
 }