apache/hadoop · error · HadoopIllegalArgumentException

The given erasure coding policy {} does not exist.

Error message

The given erasure coding policy {} does not exist.

What it means

HadoopIllegalArgumentException from getErasureCodingPolicyByName: no erasure coding policy (enabled or disabled) with the given name is registered in the NameNode's ErasureCodingPolicyManager. Unlike the 'not enabled' rejection, the name is entirely unknown - a typo, a policy never added, or one removed via removePolicy.

Source

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

    }
    return ecPolicy;
  }

  /**
   * Check if the ecPolicyName is valid, return the corresponding
   * EC policy if is, including the REPLICATION EC policy.
   * @param fsn namespace
   * @param ecPolicyName name of EC policy to be checked
   * @return an erasure coding policy if ecPolicyName is valid
   * @throws IOException
   */
  static ErasureCodingPolicy getErasureCodingPolicyByName(
      final FSNamesystem fsn, final String ecPolicyName) throws IOException {
    assert fsn.hasReadLock(RwLockMode.FS);
    ErasureCodingPolicy ecPolicy = fsn.getErasureCodingPolicyManager()
        .getErasureCodingPolicyByName(ecPolicyName);
    if (ecPolicy == null) {
      throw new HadoopIllegalArgumentException(
          "The given erasure coding " + "policy " + ecPolicyName
              + " does not exist.");
    }
    return ecPolicy;
  }

  /**
   * Set an erasure coding policy on the given path.
   *
   * @param fsn The namespace
   * @param srcArg The path of the target directory.
   * @param ecPolicyName The erasure coding policy name to set on the target
   *                    directory.
   * @param logRetryCache whether to record RPC ids in editlog for retry
   *          cache rebuilding
   * @return {@link FileStatus}
   * @throws IOException
   * @throws HadoopIllegalArgumentException if the policy is not enabled

View on GitHub (pinned to 2add963021)

Solutions

  1. List valid names with `hdfs ec -listPolicies` and use the exact spelling (including the codec and cell-size suffix).
  2. If the policy should exist, add it: `hdfs ec -addPolicies -policyFile <json>`, then enable it.
  3. If it was removed intentionally, update callers to an existing enabled policy.

Example fix

# before
hdfs ec -setPolicy -policy RS-6-3-1044k -path /ec   # typo

# after
hdfs ec -listPolicies | grep RS-6-3
hdfs ec -setPolicy -policy RS-6-3-1024k -path /ec
Defensive patterns

Strategy: validation

Validate before calling

import java.util.Arrays;
import org.apache.hadoop.hdfs.DistributedFileSystem;

static boolean ecPolicyExists(DistributedFileSystem dfs, String name) throws IOException {
  return Arrays.stream(dfs.getAllErasureCodingPolicies())
      .anyMatch(i -> i.getName().equals(name));
}

if (!ecPolicyExists(dfs, policyName)) {
  throw new IllegalArgumentException("Unknown EC policy " + policyName
      + "; valid: " + Arrays.toString(
          Arrays.stream(dfs.getAllErasureCodingPolicies())
              .map(org.apache.hadoop.io.erasurecode.ErasureCodingPolicyInfo::getName)
              .toArray(String[]::new)));
}

Try / catch

try {
  dfs.setErasureCodingPolicy(dir, policyName);
} catch (org.apache.hadoop.HadoopIllegalArgumentException e) {
  if (e.getMessage().contains("does not exist")) { /* typo or removed policy: re-list and fix name */ }
  throw e;
}

Prevention

When it happens

Trigger: `hdfs ec -setPolicy -policy RS-6-3-1044k -path /ec` (typo in the cell-size suffix); referencing a policy deleted by `hdfs ec -removePolicy`; programmatic setErasureCodingPolicy with a name copied from a different cluster; using RS-LEGACY-* names on versions where that policy was removed.

Common situations: Copy-pasting policy names across clusters or Hadoop versions (suffixes like 64k vs 1024k differ); stale runbooks or wiki docs; custom policies from another namespace; renamed policies after upgrades.

Related errors


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