{"record":{"id":"21b1278d9b157f80","repo":"apache/hadoop","slug":"invalid-values-for-quota","errorCode":null,"errorMessage":"Invalid values for quota :{}","messagePattern":"Invalid values for quota :(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java","lineNumber":2675,"sourceCode":"          FileNotFoundException.class,\n          NSQuotaExceededException.class,\n          DSQuotaExceededException.class,\n          QuotaByStorageTypeExceededException.class,\n          UnresolvedPathException.class,\n          SnapshotAccessControlException.class);\n    }\n  }\n\n  /**\n   * Sets or resets quotas by storage type for a directory.\n   * @see ClientProtocol#setQuota(String, long, long, StorageType)\n   */\n  void setQuotaByStorageType(String src, StorageType type, long quota)\n      throws IOException {\n    checkOpen();\n    if (quota <= 0 && quota != HdfsConstants.QUOTA_DONT_SET &&\n        quota != HdfsConstants.QUOTA_RESET) {\n      throw new IllegalArgumentException(\"Invalid values for quota :\" +\n          quota);\n    }\n    if (type == null) {\n      throw new IllegalArgumentException(\"Invalid storage type(null)\");\n    }\n    if (!type.supportTypeQuota()) {\n      throw new IllegalArgumentException(\n          \"Don't support Quota for storage type : \" + type.toString());\n    }\n    try (TraceScope ignored = newPathTraceScope(\"setQuotaByStorageType\", src)) {\n      namenode.setQuota(src, HdfsConstants.QUOTA_DONT_SET, quota, type);\n    } catch (RemoteException re) {\n      throw re.unwrapRemoteException(AccessControlException.class,\n          FileNotFoundException.class,\n          QuotaByStorageTypeExceededException.class,\n          UnresolvedPathException.class,\n          SnapshotAccessControlException.class);\n    }","sourceCodeStart":2657,"sourceCodeEnd":2693,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java#L2657-L2693","documentation":"DFSClient.setQuotaByStorageType validates its single quota the same way as the pair API: it must be positive or one of the sentinels HdfsConstants.QUOTA_DONT_SET (Long.MAX_VALUE) / QUOTA_RESET (-1). Because the sentinel is Long.MAX_VALUE, common stand-ins like 0 or -2 are rejected client-side with IllegalArgumentException.","triggerScenarios":"Calling setQuotaByStorageType with 0 (expecting 'unlimited'), -2, or an underflowed computed value; tools that parse quota strings and default missing values to 0; config round-trips losing the Long.MAX_VALUE sentinel.","commonSituations":"Storage-type quota automation (SSD/ARCHIVE tiering policies) with custom frontends; scripts migrating quota settings between clusters; JSON/YAML configs where Long.MAX_VALUE got serialized incorrectly.","solutions":["Use the sentinels explicitly: positive to set, HdfsConstants.QUOTA_RESET (-1) to clear, HdfsConstants.QUOTA_DONT_SET (Long.MAX_VALUE) to leave unchanged.","Validate the parsed value at your config/CLI boundary before it reaches the client (positive or exactly -1 / Long.MAX_VALUE).","Audit serialization of sentinel values through your config store."],"exampleFix":"// before\nclient.setQuotaByStorageType(dir, StorageType.SSD, quota); // quota = 0 or -2\n\n// after\nlong q = (quota <= 0) ? HdfsConstants.QUOTA_RESET : quota; // set: >0, reset: -1\nclient.setQuotaByStorageType(dir, StorageType.SSD, q);","handlingStrategy":"validation","validationCode":"boolean ok = quota > 0 || quota == HdfsConstants.QUOTA_DONT_SET || quota == HdfsConstants.QUOTA_RESET;\nif (!ok) {\n  throw new IllegalArgumentException(\"storage-type quota out of range: \" + quota);\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n  // report the rejected quota value and the intended storage type\n}","preventionTips":["Use HdfsConstants sentinels rather than 0 or -2 for 'clear' semantics.","Validate parsed quota values at the CLI/config boundary.","Regression-test serialization round-trips of Long.MAX_VALUE through your config store."],"tags":["hdfs","quota","storage-type","argument-validation"],"backgroundTag":"invalid-quota-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}