apache/hadoop · error · HadoopIllegalArgumentException

Policy '%s' does not match any enabled erasure coding polici

Error message

Policy '%s' does not match any enabled erasure coding policies: [%s]. An erasure coding policy can be enabled by enableErasureCodingPolicy API.

What it means

Unchecked HadoopIllegalArgumentException thrown while validating an erasure coding policy name for setPolicy: the name matches none of the *enabled* policies from ErasureCodingPolicyManager.getEnabledPolicies(). A policy can exist and still be rejected - built-ins such as RS-10-4-1024k and RS-LEGACY-10-4-1024k ship disabled, and policies added via addPolicies also require an explicit enableErasureCodingPolicy call before use.

Source

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

      final FSNamesystem fsn, final String ecPolicyName) throws IOException {
    assert fsn.hasReadLock(RwLockMode.FS);
    ErasureCodingPolicy ecPolicy = fsn.getErasureCodingPolicyManager()
        .getEnabledPolicyByName(ecPolicyName);
    if (ecPolicy == null) {
      final String sysPolicies =
          Arrays.asList(
              fsn.getErasureCodingPolicyManager().getEnabledPolicies())
              .stream()
              .map(ErasureCodingPolicy::getName)
              .collect(Collectors.joining(", "));
      final String message = String.format("Policy '%s' does not match any " +
              "enabled erasure" +
              " coding policies: [%s]. An erasure coding policy can be" +
              " enabled by enableErasureCodingPolicy API.",
          ecPolicyName,
          sysPolicies
      );
      throw new HadoopIllegalArgumentException(message);
    }
    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) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Enable the policy first: `hdfs ec -enablePolicy -policy <name>`, then retry setPolicy.
  2. Or switch to a policy already marked enabled in `hdfs ec -listPolicies`.
  3. For custom schemas: `hdfs ec -addPolicies -policyFile <json>` followed by `hdfs ec -enablePolicy -policy <name>`.
  4. If the policy should be on by default, verify the NameNode's erasure-code configuration (io.erasurecode.codecs.*, dfs.namenode.ec.system.default.policies).

Example fix

# before
hdfs ec -setPolicy -policy RS-10-4-1024k -path /ec
# -> HadoopIllegalArgumentException: Policy 'RS-10-4-1024k' does not match any enabled policies

# after
hdfs ec -enablePolicy -policy RS-10-4-1024k
hdfs ec -setPolicy -policy RS-10-4-1024k -path /ec
Defensive patterns

Strategy: validation

Validate before calling

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

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

if (!ecPolicyEnabled(dfs, policyName)) {
  dfs.enableErasureCodingPolicy(policyName); // or fail fast listing enabled names
}
dfs.setErasureCodingPolicy(dir, policyName);

Try / catch

try {
  dfs.setErasureCodingPolicy(dir, policyName);
} catch (org.apache.hadoop.HadoopIllegalArgumentException e) {
  // message names the enabled set; surface it and/or enableErasureCodingPolicy then retry
  throw new IllegalStateException("EC policy not enabled: " + policyName, e);
}

Prevention

When it happens

Trigger: `hdfs ec -setPolicy -policy RS-10-4-1024k -path /ec` run before `hdfs ec -enablePolicy -policy RS-10-4-1024k`; DistributedFileSystem.setErasureCodingPolicy(path, "XOR-2-1-1024k") after an admin disabled that policy; using a just-added custom policy right after `hdfs ec -addPolicies` without enabling it.

Common situations: Fresh Hadoop 3 clusters where only a subset of built-in EC policies is enabled by default; EC scripts ported from an older cluster that had extra policies enabled; an admin previously ran `hdfs ec -disablePolicy`; assuming addPolicies auto-enables new policies.

Related errors


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