private void LoadRootINode(FsImageProto.INodeSection.INode p) { INodeDirectory root = LoadINodeDirectory(p, parent.GetLoaderContext()); QuotaCounts q = root.GetQuotaCounts(); long nsQuota = q.GetNameSpace(); long dsQuota = q.GetStorageSpace(); if (nsQuota != -1 || dsQuota != -1) { dir.rootDir.GetDirectoryWithQuotaFeature().SetQuota(nsQuota, dsQuota); } EnumCounters <StorageType> typeQuotas = q.GetTypeSpaces(); if (typeQuotas.AnyGreaterOrEqual(0)) { dir.rootDir.GetDirectoryWithQuotaFeature().SetQuota(typeQuotas); } dir.rootDir.CloneModificationTime(root); dir.rootDir.ClonePermissionStatus(root); AclFeature af = root.GetFeature(typeof(AclFeature)); if (af != null) { dir.rootDir.AddAclFeature(af); } // root dir supports having extended attributes according to POSIX XAttrFeature f = root.GetXAttrFeature(); if (f != null) { dir.rootDir.AddXAttrFeature(f); } dir.AddRootDirToEncryptionZone(f); }
/// <summary>Set the namespace, storagespace and typespace quota for a directory.</summary> /// <remarks> /// Set the namespace, storagespace and typespace quota for a directory. /// Note: This does not support ".inodes" relative path. /// </remarks> /// <exception cref="System.IO.IOException"/> internal static void SetQuota(FSDirectory fsd, string src, long nsQuota, long ssQuota , StorageType type) { if (fsd.IsPermissionEnabled()) { FSPermissionChecker pc = fsd.GetPermissionChecker(); pc.CheckSuperuserPrivilege(); } fsd.WriteLock(); try { INodeDirectory changed = UnprotectedSetQuota(fsd, src, nsQuota, ssQuota, type); if (changed != null) { QuotaCounts q = changed.GetQuotaCounts(); if (type == null) { fsd.GetEditLog().LogSetQuota(src, q.GetNameSpace(), q.GetStorageSpace()); } else { fsd.GetEditLog().LogSetQuotaByStorageType(src, q.GetTypeSpaces().Get(type), type); } } } finally { fsd.WriteUnlock(); } }
/// <summary> /// Serialize a /// <see cref="INodeDirectory"/> /// </summary> /// <param name="node">The node to write</param> /// <param name="out"> /// The /// <see cref="System.IO.DataOutput"/> /// where the fields are written /// </param> /// <exception cref="System.IO.IOException"/> public static void WriteINodeDirectory(INodeDirectory node, DataOutput @out) { WriteLocalName(node, @out); @out.WriteLong(node.GetId()); @out.WriteShort(0); // replication @out.WriteLong(node.GetModificationTime()); @out.WriteLong(0); // access time @out.WriteLong(0); // preferred block size @out.WriteInt(-1); // # of blocks WriteQuota(node.GetQuotaCounts(), @out); if (node.IsSnapshottable()) { @out.WriteBoolean(true); } else { @out.WriteBoolean(false); @out.WriteBoolean(node.IsWithSnapshot()); } WritePermissionStatus(node, @out); }
public CopyWithQuota(INodeDirectory dir) : base(dir) { Preconditions.CheckArgument(dir.IsQuotaSet()); QuotaCounts q = dir.GetQuotaCounts(); this.quota = new QuotaCounts.Builder().QuotaCount(q).Build(); }
/// <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); } }