apache/hadoop · error · InvalidRequestException
Limit is negative.
Error message
Limit is negative.
What it means
Client-side validation in CachePoolInfo.validate(): a cache pool limit that is set (non-null) and negative is rejected with InvalidRequestException before/while the request reaches the NameNode. The limit is the aggregate byte cap for a cache pool; negative values have no meaning.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/CachePoolInfo.java:222
@Override
public int hashCode() {
return new HashCodeBuilder().
append(poolName).
append(ownerName).
append(groupName).
append(mode).
append(limit).
append(defaultReplication).
append(maxRelativeExpiryMs).
hashCode();
}
public static void validate(CachePoolInfo info) throws IOException {
if (info == null) {
throw new InvalidRequestException("CachePoolInfo is null");
}
if ((info.getLimit() != null) && (info.getLimit() < 0)) {
throw new InvalidRequestException("Limit is negative.");
}
if ((info.getDefaultReplication() != null)
&& (info.getDefaultReplication() < 0)) {
throw new InvalidRequestException("Default Replication is negative");
}
if (info.getMaxRelativeExpiryMs() != null) {
long maxRelativeExpiryMs = info.getMaxRelativeExpiryMs();
if (maxRelativeExpiryMs < 0l) {
throw new InvalidRequestException("Max relative expiry is negative.");
}
if (maxRelativeExpiryMs > Expiration.MAX_RELATIVE_EXPIRY_MS) {
throw new InvalidRequestException("Max relative expiry is too big.");
}
}
validateName(info.poolName);
}
View on GitHub (pinned to 2add963021)
Solutions
- Do not set a negative limit; to express 'no limit' leave the limit unset (null) or set CachePoolInfo.limitUnlimited.
- Clamp computed limits: long limit = Math.max(0, computedLimit).
- Validate CachePoolInfo before submitting if the value comes from external input.
Example fix
// before
CachePoolInfo info = new CachePoolInfo("pool").setLimit(requestedLimit); // requestedLimit = -1
// after
CachePoolInfo info = new CachePoolInfo("pool");
if (requestedLimit != null && requestedLimit >= 0) {
info.setLimit(requestedLimit);
} Defensive patterns
Strategy: validation
Validate before calling
if (info.getLimit() != null && info.getLimit() < 0) {
throw new IllegalArgumentException("limit must be >= 0, got " + info.getLimit());
}
dfs.addCachePool(info); Try / catch
try { dfs.addCachePool(info); }
catch (InvalidRequestException e) { /* surface field error to caller/config */ } Prevention
- Centralize CachePoolInfo construction in one factory that clamps limit/replication/expiry to valid ranges.
- Use null (unset) to mean 'no limit' rather than a negative sentinel.
- Validate config-derived values before submitting them to the NameNode.
When it happens
Trigger: addCachePool or modifyCachePool with CachePoolInfo.setLimit(-1) (or any negative long), including arithmetic that computes a limit from free space and underflows below zero.
Common situations: Scripts computing pool limits from cluster metrics where subtraction yields a negative number; porting code from a system where -1 meant 'unlimited'.
Related errors
- {key} = {v} <= 0
- Requested replication factor of {replication}{err} for {src}
- dfs.datanode.parallel.volumes.load.threads.num = {} < 1
- Invalid values: dfs.bytes-per-checksum (={}) must divide cel
- Invalid checksum type: userOpt=${userOpt}, default=${default
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/686a1761e531ff52.
Report an issue: GitHub.