{"record":{"id":"5acb00f56721f652","repo":"apache/hadoop","slug":"cannot-get-filechannel-from-block-inputstream-meta","errorCode":null,"errorMessage":"Cannot get FileChannel from Block InputStream meta file.","messagePattern":"Cannot get FileChannel from Block InputStream meta file\\.","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/NativePmemMappableBlockLoader.java","lineNumber":132,"sourceCode":"    return mappableBlock;\n  }\n\n  /**\n   * Verifies the block's checksum meanwhile map block to persistent memory.\n   * This is an I/O intensive operation.\n   */\n  private void verifyChecksumAndMapBlock(POSIX.PmemMappedRegion region,\n      long length, FileInputStream metaIn, FileChannel blockChannel,\n      String blockFileName) throws IOException {\n    // Verify the checksum from the block's meta file\n    // Get the DataChecksum from the meta file header\n    BlockMetadataHeader header =\n        BlockMetadataHeader.readHeader(new DataInputStream(\n            new BufferedInputStream(metaIn, BlockMetadataHeader\n                .getHeaderSize())));\n    try (FileChannel metaChannel = metaIn.getChannel()) {\n      if (metaChannel == null) {\n        throw new IOException(\"Cannot get FileChannel\" +\n            \" from Block InputStream meta file.\");\n      }\n      DataChecksum checksum = header.getChecksum();\n      final int bytesPerChecksum = checksum.getBytesPerChecksum();\n      final int checksumSize = checksum.getChecksumSize();\n      final int numChunks = (8 * 1024 * 1024) / bytesPerChecksum;\n      ByteBuffer blockBuf = ByteBuffer.allocate(numChunks * bytesPerChecksum);\n      ByteBuffer checksumBuf = ByteBuffer.allocate(numChunks * checksumSize);\n      // Verify the checksum\n      int bytesVerified = 0;\n      long mappedAddress = -1L;\n      if (region != null) {\n        mappedAddress = region.getAddress();\n      }\n      while (bytesVerified < length) {\n        Preconditions.checkState(bytesVerified % bytesPerChecksum == 0,\n            \"Unexpected partial chunk before EOF.\");\n        assert bytesVerified % bytesPerChecksum == 0;","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/NativePmemMappableBlockLoader.java#L114-L150","documentation":"Thrown by NativePmemMappableBlockLoader.verifyChecksumAndMapBlock() (NativePmemMappableBlockLoader.java:132) when metaIn.getChannel() returns null while verifying checksums before committing a block into pmem cache. Like the sibling guards in MappableBlockLoader and the other loaders, FileInputStream.getChannel() never actually returns null on a stock JDK, making this a defensive, effectively unreachable branch.","triggerScenarios":"Only a non-standard JVM/instrumented stream could trip it; the native pmem cache path itself passes a plain FileInputStream opened on the block meta file.","commonSituations":"Does not occur in practice; if seen, investigate the JVM rather than HDFS or pmem configuration.","solutions":["Retest on a stock supported JDK without agents/instrumentation","If reproducible, add the stream class name to the exception via a debug patch and open a Hadoop JIRA","No data is corrupted - the load aborts before the mapping is published, and the cache directive retries later"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  verifyChecksumAndMapBlock(region, length, metaIn, blockChannel, blockFileName);\n} catch (IOException e) {\n  // loader's finally releases the mapped region; log and let the cache directive retry\n  LOG.warn(\"pmem cache verify failed for {}: {}\", blockFileName, e);\n}","preventionTips":["Stock JDK only - the null-channel branch is unreachable for FileInputStream.getChannel()","Guard the real risks instead: valid meta files and healthy block replicas on the volume"],"tags":["hdfs","datanode","pmem","centralized-cache","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"}