Beispiel #1
0
        /// <summary>
        /// See
        /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.ClientProtocol.SetQuota(string, long, long, Org.Apache.Hadoop.FS.StorageType)
        ///     "/>
        /// for the contract.
        /// Sets quota for for a directory.
        /// </summary>
        /// <returns>INodeDirectory if any of the quotas have changed. null otherwise.</returns>
        /// <exception cref="System.IO.FileNotFoundException">if the path does not exist.</exception>
        /// <exception cref="Org.Apache.Hadoop.FS.PathIsNotDirectoryException">if the path is not a directory.
        ///     </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException">
        /// if the directory tree size is
        /// greater than the given quota
        /// </exception>
        /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException">if a symlink is encountered in src.
        ///     </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotAccessControlException">if path is in RO snapshot
        ///     </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Namenode.UnsupportedActionException
        ///     "/>
        internal static INodeDirectory UnprotectedSetQuota(FSDirectory fsd, string src, long
                                                           nsQuota, long ssQuota, StorageType type)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            // sanity check
            if ((nsQuota < 0 && nsQuota != HdfsConstants.QuotaDontSet && nsQuota != HdfsConstants
                 .QuotaReset) || (ssQuota < 0 && ssQuota != HdfsConstants.QuotaDontSet && ssQuota
                                  != HdfsConstants.QuotaReset))
            {
                throw new ArgumentException("Illegal value for nsQuota or " + "ssQuota : " + nsQuota
                                            + " and " + ssQuota);
            }
            // sanity check for quota by storage type
            if ((type != null) && (!fsd.IsQuotaByStorageTypeEnabled() || nsQuota != HdfsConstants
                                   .QuotaDontSet))
            {
                throw new UnsupportedActionException("Failed to set quota by storage type because either"
                                                     + DFSConfigKeys.DfsQuotaByStoragetypeEnabledKey + " is set to " + fsd.IsQuotaByStorageTypeEnabled
                                                         () + " or nsQuota value is illegal " + nsQuota);
            }
            string         srcs    = FSDirectory.NormalizePath(src);
            INodesInPath   iip     = fsd.GetINodesInPath4Write(srcs, true);
            INodeDirectory dirNode = INodeDirectory.ValueOf(iip.GetLastINode(), srcs);

            if (dirNode.IsRoot() && nsQuota == HdfsConstants.QuotaReset)
            {
                throw new ArgumentException("Cannot clear namespace quota on root.");
            }
            else
            {
                // a directory inode
                QuotaCounts oldQuota   = dirNode.GetQuotaCounts();
                long        oldNsQuota = oldQuota.GetNameSpace();
                long        oldSsQuota = oldQuota.GetStorageSpace();
                if (nsQuota == HdfsConstants.QuotaDontSet)
                {
                    nsQuota = oldNsQuota;
                }
                if (ssQuota == HdfsConstants.QuotaDontSet)
                {
                    ssQuota = oldSsQuota;
                }
                // unchanged space/namespace quota
                if (type == null && oldNsQuota == nsQuota && oldSsQuota == ssQuota)
                {
                    return(null);
                }
                // unchanged type quota
                if (type != null)
                {
                    EnumCounters <StorageType> oldTypeQuotas = oldQuota.GetTypeSpaces();
                    if (oldTypeQuotas != null && oldTypeQuotas.Get(type) == ssQuota)
                    {
                        return(null);
                    }
                }
                int latest = iip.GetLatestSnapshotId();
                dirNode.RecordModification(latest);
                dirNode.SetQuota(fsd.GetBlockStoragePolicySuite(), nsQuota, ssQuota, type);
                return(dirNode);
            }
        }