{"record":{"id":"546ce29b812f0fde","repo":"apache/hadoop","slug":"file-does-not-exist-546ce2","errorCode":null,"errorMessage":"File does not exist: {}","messagePattern":"File does not exist: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java","lineNumber":1962,"sourceCode":"   *\n   * @param src The file path\n   * @param length the length of the range, i.e., the range is [0, length]\n   * @return The checksum\n   * @see DistributedFileSystem#getFileChecksum(Path)\n   */\n  public MD5MD5CRC32FileChecksum getFileChecksum(String src, long length)\n      throws IOException {\n    return (MD5MD5CRC32FileChecksum) getFileChecksumInternal(\n        src, length, ChecksumCombineMode.MD5MD5CRC);\n  }\n\n  protected LocatedBlocks getBlockLocations(String src,\n                                            long length) throws IOException {\n    //get block locations for the file range\n    LocatedBlocks blockLocations = callGetBlockLocations(namenode,\n        src, 0, length);\n    if (null == blockLocations) {\n      throw new FileNotFoundException(\"File does not exist: \" + src);\n    }\n    if (blockLocations.isUnderConstruction()) {\n      throw new IOException(\"Fail to get checksum, since file \" + src\n          + \" is under construction.\");\n    }\n\n    return blockLocations;\n  }\n\n  protected IOStreamPair connectToDN(DatanodeInfo dn, int timeout,\n                                     Token<BlockTokenIdentifier> blockToken)\n      throws IOException {\n    return DFSUtilClient.connectToDN(dn, timeout, conf, saslClient,\n        socketFactory, getConf().isConnectToDnViaHostname(), this, blockToken);\n  }\n\n  /**\n   * Infer the checksum type for a replica by sending an OP_READ_BLOCK","sourceCodeStart":1944,"sourceCodeEnd":1980,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java#L1944-L1980","documentation":"getFileChecksum(src, length) resolves the file's block locations first; a null LocatedBlocks response means the file is not in the namespace, and the client throws FileNotFoundException before contacting any Datanode. So a checksum failure of this shape is a missing-file problem, not a checksum computation problem.","triggerScenarios":"getFileChecksum on a path deleted between the caller's existence check and the call; checksum-verification pipelines (distcp -checksum, audit tools) walking trees that a retention job is concurrently pruning; verifying output of a job that wrote to a different path.","commonSituations":"distcp source files cleaned mid-transfer; audit/verification steps racing writers; consumers verifying a file that a writer publishes via rename after the verifier started.","solutions":["Gate with getFileStatus() immediately before checksumming and re-check existence in the catch to classify the failure.","For verify-after-copy flows, checksum the same generation you copied (e.g. source snapshot) rather than a mutating live tree.","If concurrent deletes are expected, skip-and-log missing files instead of failing the whole run."],"exampleFix":"// before\nFileChecksum cs = fs.getFileChecksum(path);\n// FileNotFoundException: File does not exist: <path>\n\n// after\nFileStatus st;\ntry {\n  st = fs.getFileStatus(path);\n} catch (FileNotFoundException e) {\n  return Optional.empty(); // concurrently deleted: skip this file\n}\nFileChecksum cs = fs.getFileChecksum(path);","handlingStrategy":"try-catch","validationCode":"if (!fs.exists(path)) {\n  // vanished or never existed: skip this record instead of checksumming\n}","typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) {\n  // concurrently deleted: skip the file, or fail the transfer record with path context\n}","preventionTips":["Verify against snapshots when inputs are concurrently cleaned.","Re-check existence in the catch to distinguish deletion from real IO failures.","Make verification idempotent per file so skips can be retried later."],"tags":["hdfs","file-checksum","file-not-found","race-condition","distcp"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}