{"record":{"id":"cde07f9db4b14b73","repo":"apache/hadoop","slug":"cannot-find-a-block-policy-with-the-name-poli","errorCode":null,"errorMessage":"\"Cannot find a block policy with the name \" + policyName","messagePattern":"\"Cannot find a block policy with the name \" \\+ policyName","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java","lineNumber":172,"sourceCode":"      }\n    } finally {\n      fsd.writeUnlock();\n    }\n    return isFile;\n  }\n\n  static FileStatus unsetStoragePolicy(FSDirectory fsd, FSPermissionChecker pc,\n      BlockManager bm, String src) throws IOException {\n    return setStoragePolicy(fsd, pc, bm, src,\n        HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED);\n  }\n\n  static FileStatus setStoragePolicy(FSDirectory fsd, FSPermissionChecker pc,\n      BlockManager bm, String src, final String policyName) throws IOException {\n    // get the corresponding policy and make sure the policy name is valid\n    BlockStoragePolicy policy = bm.getStoragePolicy(policyName);\n    if (policy == null) {\n      throw new HadoopIllegalArgumentException(\n          \"Cannot find a block policy with the name \" + policyName);\n    }\n    return setStoragePolicy(fsd, pc, bm, src, policy.getId());\n  }\n\n  static FileStatus setStoragePolicy(FSDirectory fsd, FSPermissionChecker pc,\n      BlockManager bm, String src, final byte policyId)\n      throws IOException {\n    INodesInPath iip;\n    fsd.writeLock();\n    try {\n      iip = fsd.resolvePath(pc, src, DirOp.WRITE);\n\n      if (fsd.isPermissionEnabled()) {\n        fsd.checkPathAccess(pc, iip, FsAction.WRITE);\n      }\n\n      unprotectedSetStoragePolicy(fsd, bm, iip, policyId);","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java#L154-L190","documentation":"setStoragePolicy first resolves the policy name through the NameNode's BlockStoragePolicySuite; an unknown name returns null and FSDirAttrOp throws HadoopIllegalArgumentException. Names are case-sensitive and limited to the suite the NN loaded - the built-ins are HOT, WARM, COLD, ALL_SSD, ONE_SSD, LAZY_PERSIST, plus version-dependent ones like ALL_NVDIMM and PROVIDED.","triggerScenarios":"DistributedFileSystem.setStoragePolicy(path, name) or 'hdfs storagepolicies -setStoragePolicy -policy <name>' with a typo, wrong case ('hot'), or a policy the NN suite does not define (e.g. PROVIDED on an older cluster).","commonSituations":"Policy scripts hardcoded across Hadoop versions; clusters with custom policy suites where the client and NN disagree; case mismatches or trailing whitespace in names from config/CLI input.","solutions":["List what the NameNode supports: 'hdfs storagepolicies -listStoragePolicies' (or DistributedFileSystem.getStoragePolicies()) and use one of those names exactly.","Check spelling and case - names are the uppercase constants from HdfsConstants.StoragePolicy.","If a custom/newer policy is expected, confirm the NameNode actually loaded it; the suite is NN-side, not client config."],"exampleFix":"// before\nfs.setStoragePolicy(path, policyName); // HadoopIllegalArgumentException on typo\n\n// after: validate against the NN's suite\nBlockStoragePolicy[] available = ((DistributedFileSystem) fs).getStoragePolicies();\nboolean known = Arrays.stream(available)\n    .anyMatch(p -> p.getName().equals(policyName));\nif (!known) {\n  throw new IllegalArgumentException(\"Unknown policy \" + policyName\n      + \"; available: \" + Arrays.toString(available));\n}\nfs.setStoragePolicy(path, policyName);","handlingStrategy":"validation","validationCode":"BlockStoragePolicy[] available = ((DistributedFileSystem) fs).getStoragePolicies();\nboolean known = Arrays.stream(available).anyMatch(sp -> sp.getName().equals(policyName));\nif (!known) {\n  throw new IllegalArgumentException(\"Unknown storage policy \" + policyName\n      + \"; available on this NameNode: \" + Arrays.toString(available));\n}\nfs.setStoragePolicy(path, policyName);","typeGuard":null,"tryCatchPattern":"try {\n  fs.setStoragePolicy(path, policyName);\n} catch (HadoopIllegalArgumentException e) {\n  if (e.getMessage().contains(\"Cannot find a block policy\")) {\n    // typo or version mismatch: list policies with getStoragePolicies() and re-run\n  }\n}","preventionTips":["Fetch the policy list at job start instead of hardcoding names.","Pin policy names per cluster version in deployment config, not in code."],"tags":["hdfs","storage-policy","namenode","validation"],"backgroundTag":"unknown-storage-policy","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}