{"record":{"id":"3a833743115187c7","repo":"apache/hadoop","slug":"block-inputstream-has-no-filechannel","errorCode":null,"errorMessage":"Block InputStream has no FileChannel.","messagePattern":"Block InputStream has no FileChannel\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/MemoryMappableBlockLoader.java","lineNumber":77,"sourceCode":"   *                       start. The caller must close this.\n   * @param metaIn         The meta file input stream. Should be positioned at\n   *                       the start. The caller must close this.\n   * @param blockFileName  The block file name, for logging purposes.\n   * @param key            The extended block ID.\n   *\n   * @throws IOException   If mapping block to memory fails or checksum fails.\n\n   * @return               The Mappable block.\n   */\n  @Override\n  MappableBlock load(long length, FileInputStream blockIn,\n      FileInputStream metaIn, String blockFileName, ExtendedBlockId key)\n      throws IOException {\n    MemoryMappedBlock mappableBlock = null;\n    MappedByteBuffer mmap = null;\n    try (FileChannel blockChannel = blockIn.getChannel()) {\n      if (blockChannel == null) {\n        throw new IOException(\"Block InputStream has no FileChannel.\");\n      }\n      mmap = blockChannel.map(FileChannel.MapMode.READ_ONLY, 0, length);\n      NativeIO.POSIX.getCacheManipulator().mlock(blockFileName, mmap, length);\n      verifyChecksum(length, metaIn, blockChannel, blockFileName);\n      mappableBlock = new MemoryMappedBlock(mmap, length);\n    } finally {\n      if (mappableBlock == null) {\n        if (mmap != null) {\n          NativeIO.POSIX.munmap(mmap); // unmapping also unlocks\n        }\n      }\n    }\n    return mappableBlock;\n  }\n\n  @Override\n  public long getCacheUsed() {\n    return memCacheStats.getCacheUsed();","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/MemoryMappableBlockLoader.java#L59-L95","documentation":"Thrown by MemoryMappableBlockLoader.load() (MemoryMappableBlockLoader.java:77), the DRAM (mmap+mlock) loader for HDFS centralized caching, when blockIn.getChannel() returns null. As with the other loaders this is a defensive check - FileInputStream.getChannel() on a stock JDK never returns null - so the branch is effectively theoretical; the realistic failure modes of this loader are mmap/mlock failures (ulimits), which throw different errors.","triggerScenarios":"A cache directive on a cluster with dfs.datanode.max.locked.memory configured, where blockIn is somehow not backed by a real file channel (custom/instrumented JDK, exotic filesystem returning unusable channels).","commonSituations":"Practically does not occur; if reported, look at JVM-level tampering (agents, patched JDK) rather than HDFS configuration.","solutions":["Reproduce on a stock supported JDK; remove JVM agents/instrumentation and retest","If it persists, capture the FileInputStream concrete class in the exception (getClass()) via a debug patch and file a Hadoop JIRA","FsDatasetCache already marks the caching attempt failed and frees the reservation - no manual cleanup beyond retrying the directive is needed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  mappableBlock = new MemoryMappableBlockLoader(...).load(\n      length, blockIn, metaIn, blockFileName, key);\n} catch (IOException e) {\n  // load() already munmaps on failure in its finally; just report and let the cache retry\n  LOG.warn(\"DRAM caching failed for {}: {}\", key, e);\n}","preventionTips":["Use a stock JDK; the null-channel guard is unreachable in normal operation","For the realistic mlock failures instead: raise ulimits (memlock) and set dfs.datanode.max.locked.memory"],"tags":["hdfs","datanode","centralized-cache","mlock","filechannel","defensive-check"],"backgroundTag":"file-channel-unavailable","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}