示例#1
0
        public override QuotaCounts ComputeQuotaUsage(BlockStoragePolicySuite bsps, byte
                                                      blockStoragePolicyId, QuotaCounts counts, bool useCache, int lastSnapshotId)
        {
            DirectoryWithSnapshotFeature sf = GetDirectoryWithSnapshotFeature();

            // we are computing the quota usage for a specific snapshot here, i.e., the
            // computation only includes files/directories that exist at the time of the
            // given snapshot
            if (sf != null && lastSnapshotId != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                .CurrentStateId && !(useCache && IsQuotaSet()))
            {
                ReadOnlyList <INode> childrenList = GetChildrenList(lastSnapshotId);
                foreach (INode child in childrenList)
                {
                    byte childPolicyId = child.GetStoragePolicyIDForQuota(blockStoragePolicyId);
                    child.ComputeQuotaUsage(bsps, childPolicyId, counts, useCache, lastSnapshotId);
                }
                counts.AddNameSpace(1);
                return(counts);
            }
            // compute the quota usage in the scope of the current directory tree
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            if (useCache && q != null && q.IsQuotaSet())
            {
                // use the cached quota
                return(q.AddCurrentSpaceUsage(counts));
            }
            else
            {
                useCache = q != null && !q.IsQuotaSet() ? false : useCache;
                return(ComputeDirectoryQuotaUsage(bsps, blockStoragePolicyId, counts, useCache, lastSnapshotId
                                                  ));
            }
        }
示例#2
0
        public override void DumpTreeRecursively(PrintWriter @out, StringBuilder prefix,
                                                 int snapshot)
        {
            base.DumpTreeRecursively(@out, prefix, snapshot);
            @out.Write(", childrenSize=" + GetChildrenList(snapshot).Size());
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            if (q != null)
            {
                @out.Write(", " + q);
            }
            if (this is Snapshot.Root)
            {
                @out.Write(", snapshotId=" + snapshot);
            }
            @out.WriteLine();
            if (prefix.Length >= 2)
            {
                prefix.Length = prefix.Length - 2;
                prefix.Append("  ");
            }
            DumpTreeRecursively(@out, prefix, new _IEnumerable_874(this, snapshot));
            DirectorySnapshottableFeature s = GetDirectorySnapshottableFeature();

            if (s != null)
            {
                s.DumpTreeRecursively(this, @out, prefix, snapshot);
            }
        }
示例#3
0
 internal virtual DirectoryWithQuotaFeature AddDirectoryWithQuotaFeature(DirectoryWithQuotaFeature
                                                                         q)
 {
     Preconditions.CheckState(!IsWithQuota(), "Directory is already with quota");
     AddFeature(q);
     return(q);
 }
示例#4
0
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
        public override void AddSpaceConsumed(QuotaCounts counts, bool verify)
        {
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            if (q != null)
            {
                q.AddSpaceConsumed(this, counts, verify);
            }
            else
            {
                AddSpaceConsumed2Parent(counts, verify);
            }
        }
示例#5
0
        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));
            }
        }
示例#6
0
        internal virtual void SetQuota(BlockStoragePolicySuite bsps, long nsQuota, long ssQuota
                                       , StorageType type)
        {
            DirectoryWithQuotaFeature quota = GetDirectoryWithQuotaFeature();

            if (quota != null)
            {
                // already has quota; so set the quota to the new values
                if (type != null)
                {
                    quota.SetQuota(ssQuota, type);
                }
                else
                {
                    quota.SetQuota(nsQuota, ssQuota);
                }
                if (!IsQuotaSet() && !IsRoot())
                {
                    RemoveFeature(quota);
                }
            }
            else
            {
                QuotaCounts c = ComputeQuotaUsage(bsps);
                DirectoryWithQuotaFeature.Builder builder = new DirectoryWithQuotaFeature.Builder
                                                                ().NameSpaceQuota(nsQuota);
                if (type != null)
                {
                    builder.TypeQuota(type, ssQuota);
                }
                else
                {
                    builder.StorageSpaceQuota(ssQuota);
                }
                AddDirectoryWithQuotaFeature(builder.Build()).SetSpaceConsumed(c);
            }
        }
示例#7
0
            public static INodeDirectory LoadINodeDirectory(FsImageProto.INodeSection.INode n
                                                            , FSImageFormatProtobuf.LoaderContext state)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .Directory);
                FsImageProto.INodeSection.INodeDirectory d = n.GetDirectory();
                PermissionStatus permissions = LoadPermission(d.GetPermission(), state.GetStringTable
                                                                  ());
                INodeDirectory dir = new INodeDirectory(n.GetId(), n.GetName().ToByteArray(), permissions
                                                        , d.GetModificationTime());
                long nsQuota = d.GetNsQuota();
                long dsQuota = d.GetDsQuota();

                if (nsQuota >= 0 || dsQuota >= 0)
                {
                    dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().NameSpaceQuota
                                                         (nsQuota).StorageSpaceQuota(dsQuota).Build());
                }
                EnumCounters <StorageType> typeQuotas = null;

                if (d.HasTypeQuotas())
                {
                    ImmutableList <QuotaByStorageTypeEntry> qes = LoadQuotaByStorageTypeEntries(d.GetTypeQuotas
                                                                                                    ());
                    typeQuotas = new EnumCounters <StorageType>(typeof(StorageType), HdfsConstants.QuotaReset
                                                                );
                    foreach (QuotaByStorageTypeEntry qe in qes)
                    {
                        if (qe.GetQuota() >= 0 && qe.GetStorageType() != null && qe.GetStorageType().SupportTypeQuota
                                ())
                        {
                            typeQuotas.Set(qe.GetStorageType(), qe.GetQuota());
                        }
                    }
                    if (typeQuotas.AnyGreaterOrEqual(0))
                    {
                        DirectoryWithQuotaFeature q = dir.GetDirectoryWithQuotaFeature();
                        if (q == null)
                        {
                            dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().TypeQuotas
                                                                 (typeQuotas).Build());
                        }
                        else
                        {
                            q.SetQuota(typeQuotas);
                        }
                    }
                }
                if (d.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(d.GetAcl(), state.GetStringTable
                                                                                  ()));
                    dir.AddAclFeature(new AclFeature(entries));
                }
                if (d.HasXAttrs())
                {
                    dir.AddXAttrFeature(new XAttrFeature(LoadXAttrs(d.GetXAttrs(), state.GetStringTable
                                                                        ())));
                }
                return(dir);
            }
示例#8
0
        public override QuotaCounts GetQuotaCounts()
        {
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            return(q != null?q.GetQuota() : base.GetQuotaCounts());
        }