apache/hadoop · error · InvalidRequestException

Default Replication is negative

Error message

Default Replication is negative

What it means

CachePoolInfo.validate() rejects a cache pool whose default replication factor is set to a negative value. The default replication controls how many cached replicas the NameNode aims for for directives in this pool that do not override replication.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/CachePoolInfo.java:226

        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);
  }

  public static void validateName(String poolName) throws IOException {
    if (poolName == null || poolName.isEmpty()) {
      // Empty pool names are not allowed because they would be highly
      // confusing.  They would also break the ability to list all pools

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass a non-negative short (0 means use the system default, >0 sets an explicit default replication).
  2. Omit setDefaultReplication entirely to inherit the system default.
  3. Guard external input: if (repl != null && repl >= 0) info.setDefaultReplication(repl);

Example fix

// before
info.setDefaultReplication(Short.parseShort(cfg.get("pool.replication", "-1")));

// after
String v = cfg.get("pool.replication");
if (v != null) {
  short repl = Short.parseShort(v);
  if (repl >= 0) info.setDefaultReplication(repl);
}
Defensive patterns

Strategy: validation

Validate before calling

if (repl != null && (repl < 0 || repl > Short.MAX_VALUE)) {
  throw new IllegalArgumentException("default replication must be in [0, 32767], got " + repl);
}
info.setDefaultReplication(repl);

Try / catch

try { dfs.modifyCachePool(info); }
catch (InvalidRequestException e) { /* fix the source of the negative value, then retry */ }

Prevention

When it happens

Trigger: addCachePool/modifyCachePool with CachePoolInfo.setDefaultReplication(negative), e.g. -1 from unset-variable arithmetic or from misreading '0 means default' semantics.

Common situations: Configuration-driven pool creation where the replication property is missing and parsed as a negative sentinel; code copied from block replication handling.

Related errors


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