{"record":{"id":"0c21ea3019c4e599","repo":"apache/hadoop","slug":"cannot-find-a-block-policy-with-the-name-storagep","errorCode":null,"errorMessage":"Cannot find a block policy with the name <storagePolicy>","messagePattern":"Cannot find a block policy with the name <storagePolicy>","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java","lineNumber":568,"sourceCode":"  private static INodesInPath addFile(\n      FSDirectory fsd, INodesInPath existing, byte[] localName,\n      PermissionStatus permissions, short replication, long preferredBlockSize,\n      String clientName, String clientMachine, boolean shouldReplicate,\n      String ecPolicyName, String storagePolicy) throws IOException {\n\n    Preconditions.checkNotNull(existing);\n    long modTime = now();\n    INodesInPath newiip;\n    fsd.writeLock();\n    try {\n      boolean isStriped = false;\n      ErasureCodingPolicy ecPolicy = null;\n      byte storagepolicyid = 0;\n      if (storagePolicy != null && !storagePolicy.isEmpty()) {\n        BlockStoragePolicy policy =\n            fsd.getBlockManager().getStoragePolicy(storagePolicy);\n        if (policy == null) {\n          throw new HadoopIllegalArgumentException(\n              \"Cannot find a block policy with the name \" + storagePolicy);\n        }\n        storagepolicyid = policy.getId();\n      }\n      if (!shouldReplicate) {\n        ecPolicy = FSDirErasureCodingOp.getErasureCodingPolicy(\n            fsd.getFSNamesystem(), ecPolicyName, existing);\n        if (ecPolicy != null && (!ecPolicy.isReplicationPolicy())) {\n          isStriped = true;\n        }\n      }\n      final BlockType blockType = isStriped ?\n          BlockType.STRIPED : BlockType.CONTIGUOUS;\n      final Short replicationFactor = (!isStriped ? replication : null);\n      final Byte ecPolicyID = (isStriped ? ecPolicy.getId() : null);\n      INodeFile newNode = newINodeFile(fsd.allocateNewInodeId(), permissions,\n          modTime, modTime, replicationFactor, ecPolicyID, preferredBlockSize,\n          storagepolicyid, blockType);","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java#L550-L586","documentation":"addFile resolves the caller-supplied storagePolicy string through BlockManager.getStoragePolicy(name) before creating the inode. An unknown name (misspelled, wrong case, or not defined on this cluster) returns null and startFile fails immediately with HadoopIllegalArgumentException; no file is created.","triggerScenarios":"FileSystem.create with a storagePolicy parameter that does not match a registered policy. Names are case-sensitive: ALL_SSD, not all_ssd; custom policies must be defined in NameNode configuration to resolve.","commonSituations":"Hard-coded policy names that only exist on another cluster; version drift (PROVIDED exists only on newer Hadoop); typos and case errors in job or client configs.","solutions":["List valid policies with 'hdfs storagepolicies -listPolicies' and use an exact name (HOT, WARM, COLD, ALL_SSD, ONE_SSD, LAZY_PERSIST, PROVIDED)","Drop the policy argument at create time and set it afterwards with DistributedFileSystem.setStoragePolicy, which fails with a clearer error","Register the custom policy on the NameNode before referencing it"],"exampleFix":"// before: unknown/case-wrong policy at create\nfs.create(path, perm, flags, bufSize, replication, blockSize, progress, null, \"all_ssd\", null);\n\n// after: create plainly, then set policy with validation\nFSDataOutputStream out = fs.create(path, true);\n((DistributedFileSystem) fs).setStoragePolicy(path, \"ALL_SSD\");","handlingStrategy":"validation","validationCode":"static final Set<String> KNOWN = new HashSet<>(Arrays.asList(\n    \"HOT\", \"WARM\", \"COLD\", \"ALL_SSD\", \"ONE_SSD\", \"LAZY_PERSIST\", \"PROVIDED\"));\nif (!KNOWN.contains(storagePolicy)) {\n  throw new IllegalArgumentException(\"Unknown HDFS storage policy: \" + storagePolicy\n      + \"; run 'hdfs storagepolicies -listPolicies'\");\n}","typeGuard":"static boolean isValidStoragePolicy(String name) {\n  return KNOWN.contains(name); // extend with cluster-registered custom policies\n}","tryCatchPattern":"try {\n  fs.create(path, perm, flags, bufSize, repl, bs, progress, null, storagePolicy, null);\n} catch (HadoopIllegalArgumentException e) {\n  // invalid policy name: create plainly, then set a validated policy\n  ((DistributedFileSystem) fs).setStoragePolicy(path, \"HOT\");\n}","preventionTips":["Verify policy names with hdfs storagepolicies -listPolicies before shipping configs","Policy names are case-sensitive","Set the policy after create via setStoragePolicy for a clearer failure mode"],"tags":["hdfs","storage-policy","create","argument-validation"],"backgroundTag":"unknown-storage-policy","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}