{"record":{"id":"2a3cee78a52a08a2","repo":"apache/hadoop","slug":"the-namespace-quota-directories-and-files-of-dir","errorCode":null,"errorMessage":"The NameSpace quota (directories and files) of directory pathName is exceeded: quota=quota file count=count","messagePattern":"The NameSpace quota \\(directories and files\\) of directory pathName is exceeded: quota=quota file count=count","errorType":"exception","errorClass":"NSQuotaExceededException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/DirectoryWithQuotaFeature.java","lineNumber":177,"sourceCode":"    usage.setNameSpace(c.getNameSpace());\n    usage.setStorageSpace(c.getStorageSpace());\n    usage.setTypeSpaces(c.getTypeSpaces());\n  }\n\n  /** @return the namespace and storagespace and typespace allowed. */\n  public QuotaCounts getSpaceAllowed() {\n    return new QuotaCounts.Builder().quotaCount(quota).build();\n  }\n\n  /** @return the namespace and storagespace and typespace consumed. */\n  public QuotaCounts getSpaceConsumed() {\n    return new QuotaCounts.Builder().quotaCount(usage).build();\n  }\n\n  /** Verify if the namespace quota is violated after applying delta. */\n  private void verifyNamespaceQuota(long delta) throws NSQuotaExceededException {\n    if (Quota.isViolated(quota.getNameSpace(), usage.getNameSpace(), delta)) {\n      throw new NSQuotaExceededException(quota.getNameSpace(),\n          usage.getNameSpace() + delta);\n    }\n  }\n  /** Verify if the storagespace quota is violated after applying delta. */\n  private void verifyStoragespaceQuota(long delta) throws DSQuotaExceededException {\n    if (Quota.isViolated(quota.getStorageSpace(), usage.getStorageSpace(), delta)) {\n      throw new DSQuotaExceededException(quota.getStorageSpace(),\n          usage.getStorageSpace() + delta);\n    }\n  }\n\n  private void verifyQuotaByStorageType(EnumCounters<StorageType> typeDelta)\n      throws QuotaByStorageTypeExceededException {\n    if (!isQuotaByStorageTypeSet()) {\n      return;\n    }\n    for (StorageType t: StorageType.getTypesSupportingQuota()) {\n      if (!isQuotaByStorageTypeSet(t)) {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/DirectoryWithQuotaFeature.java#L159-L195","documentation":"NSQuotaExceededException thrown from DirectoryWithQuotaFeature.verifyNamespaceQuota(), which the NameNode calls (via FSDirectory.verifyQuota) before applying any write that adds names to a directory tree. Quota.isViolated(quota, usage, delta) is true when a namespace quota is set (quota >= 0), delta > 0, and usage.getNameSpace() + delta would exceed quota.getNameSpace(). Namespace quota counts files AND directories (each contributes 1) and is set with 'hdfs dfsadmin -setQuota N path'.","triggerScenarios":"create(), mkdir(), symlink creation, or rename() of a subtree into a directory whose nearest quota'd ancestor has name usage + delta over the limit; verifyNamespaceQuota is invoked with counts.getNameSpace() from the proposed change and throws before the inode is added.","commonSituations":"Massive small-file jobs (every file and each partition dir counts 1) under a quota set for byte-scale thinking; bulk ingest or Hive partition explosion; renaming a large subtree into a quota'd area; usage already near the limit with concurrent writers racing the check.","solutions":["Raise or clear the quota: hdfs dfsadmin -setQuota <bigger-N> <path>, or hdfs dfsadmin -clrQuota <path>.","Reduce name count: delete stale files/partitions, or compact many small files into fewer larger ones (Har/compaction) under the quota'd tree.","Check current usage first: hdfs dfs -count -q <path> (QUOTA, REMAINING_QUOTA columns) to size the new limit.","For applications: catch QuotaExceededException, shed input or spill to an unquota'd path."],"exampleFix":"# before\nhdfs dfsadmin -setQuota 1000 /data/ingest   # ingest writes millions of small files\n# after\nhdfs dfs -count -q /data/ingest             # see QUOTA vs REMAINING_QUOTA\nhdfs dfsadmin -setQuota 2000000 /data/ingest","handlingStrategy":"validation","validationCode":"ContentSummary cs = dfs.getContentSummary(dir);\nlong namesUsed = cs.getFileCount() + cs.getDirectoryCount();\nlong delta = filesToAdd + dirsToAdd;             // each file/dir counts 1\nif (cs.getQuota() >= 0 && namesUsed + delta > cs.getQuota()) {\n  throw new IllegalStateException(\"namespace quota \" + cs.getQuota() + \" would be exceeded\");\n}","typeGuard":"static boolean isNamespaceQuotaExceeded(IOException e) {\n  return e instanceof NSQuotaExceededException\n      || (e instanceof RemoteException re\n          && re.getClassName().endsWith(\"NSQuotaExceededException\"));\n}","tryCatchPattern":"try {\n  fs.create(dst);\n} catch (RemoteException re) {\n  if (re.getClassName().endsWith(\"QuotaExceededException\")) {\n    // read hdfs dfs -count -q, raise dfsadmin -setQuota or shed files, then retry\n  } else { throw re; }\n}","preventionTips":["Check hdfs dfs -count -q <path> (QUOTA/REMAINING_QUOTA) before bulk loads of many small files.","Alert at 80% of namespace quota; small files dominate name usage.","Compact small files (fewer, larger files or HAR) under quota'd trees.","Size quotas by expected name counts, not by bytes."],"tags":["hdfs","quota","namenode","namespace","dfsadmin"],"backgroundTag":"hdfs-quota-exceeded","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}