apache/hadoop · error · IllegalArgumentException

"Illegal value for nsQuota or ssQuota : " + nsQuota + " and

Error message

"Illegal value for nsQuota or ssQuota : " + nsQuota + " and " + ssQuota

What it means

unprotectedSetQuota sanity-checks the raw longs: any negative nsQuota/ssQuota that is not the -1 QUOTA_RESET sentinel (QUOTA_DONT_SET is Long.MAX_VALUE, i.e. positive) throws IllegalArgumentException. In practice the check rejects every negative value except -1; zero and positive values proceed to the quota logic. The CLI guards most of this, so raw ClientProtocol/WebHDFS callers hit it.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java:337

   * @throws PathIsNotDirectoryException if the path is not a directory.
   * @throws QuotaExceededException if the directory tree size is
   *                                greater than the given quota
   * @throws UnresolvedLinkException if a symlink is encountered in src.
   * @throws SnapshotAccessControlException if path is in RO snapshot
   */
  static INodeDirectory unprotectedSetQuota(
      FSDirectory fsd, INodesInPath iip, long nsQuota,
      long ssQuota, StorageType type)
      throws FileNotFoundException, PathIsNotDirectoryException,
      QuotaExceededException, UnresolvedLinkException,
      SnapshotAccessControlException, UnsupportedActionException {
    assert fsd.hasWriteLock();
    // sanity check
    if ((nsQuota < 0 && nsQuota != HdfsConstants.QUOTA_DONT_SET &&
         nsQuota != HdfsConstants.QUOTA_RESET) ||
        (ssQuota < 0 && ssQuota != HdfsConstants.QUOTA_DONT_SET &&
          ssQuota != HdfsConstants.QUOTA_RESET)) {
      throw new IllegalArgumentException("Illegal value for nsQuota or " +
                                         "ssQuota : " + nsQuota + " and " +
                                         ssQuota);
    }
    // sanity check for quota by storage type
    if ((type != null) && (!fsd.isQuotaByStorageTypeEnabled() ||
        nsQuota != HdfsConstants.QUOTA_DONT_SET)) {
      throw new UnsupportedActionException(
          "Failed to set quota by storage type because either" +
          DFS_QUOTA_BY_STORAGETYPE_ENABLED_KEY + " is set to " +
          fsd.isQuotaByStorageTypeEnabled() + " or nsQuota value is illegal " +
          nsQuota);
    }

    INodeDirectory dirNode =
        INodeDirectory.valueOf(iip.getLastINode(), iip.getPath());
    final QuotaCounts oldQuota = dirNode.getQuotaCounts();
    final long oldNsQuota = oldQuota.getNameSpace();
    final long oldSsQuota = oldQuota.getStorageSpace();

View on GitHub (pinned to 2add963021)

Solutions

  1. Validate before the RPC: quota values must be >= 0 (use -1/QUOTA_RESET only via the dedicated clear operations that support it).
  2. Fail fast in your wrapper: if (quota < 0 && quota != HdfsConstants.QUOTA_RESET) throw IllegalArgumentException with the offending value.
  3. To clear quotas use 'hdfs dfsadmin -clrQuota'/'-clrSpaceQuota' or setQuota(path, HdfsConstants.QUOTA_RESET, ...) rather than inventing negative sentinels.

Example fix

// before
dfs.setQuota(path, computedQuota, HdfsConstants.QUOTA_DONT_SET);

// after
if (computedQuota < 0 && computedQuota != HdfsConstants.QUOTA_RESET) {
  throw new IllegalArgumentException("nsQuota must be >= 0, got " + computedQuota);
}
dfs.setQuota(path, computedQuota, HdfsConstants.QUOTA_DONT_SET);
Defensive patterns

Strategy: validation

Validate before calling

static long checkedQuota(long q) {
  if (q < 0 && q != HdfsConstants.QUOTA_RESET) {
    throw new IllegalArgumentException("Quota must be >= 0, got " + q);
  }
  return q;
}
dfs.setQuota(path, checkedQuota(nsQuota), checkedQuota(ssQuota));

Try / catch

try {
  dfs.setQuota(path, ns, ss);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("Illegal value for nsQuota")) {
    // your computed value went negative: fix the arithmetic, never resend unchanged
  }
}

Prevention

When it happens

Trigger: ClientProtocol.setQuota / WebHDFS SETQUOTA with a negative quota such as -5: scripts computing quota arithmetically (oldQuota - delta) that go below zero, or parsing '-1' style flags into the quota argument; dfsadmin validates client-side, so custom tooling and REST callers are the usual source.

Common situations: Automation deriving quotas from usage reports; Long values taken from config without validation; tools ported from the CLI that assumed argument checks happen server-side.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/ac2692d028ee581d. Report an issue: GitHub.