{"record":{"id":"6377bbc60c799951","repo":"apache/druid","slug":"unable-to-find-file-s-for-reading","errorCode":null,"errorMessage":"Unable to find file %s for reading","messagePattern":"Unable to find file (.+?) for reading","errorType":"exception","errorClass":"java.io.FileNotFoundException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/storage/local/LocalFileStorageConnector.java","lineNumber":74,"sourceCode":"  }\n\n  @Override\n  public boolean pathExists(String path)\n  {\n    return fileWithBasePath(path).exists();\n  }\n\n  @Override\n  public InputStream read(String path) throws IOException\n  {\n    return Files.newInputStream(fileWithBasePath(path).toPath());\n  }\n\n  @Override\n  public InputStream readRange(String path, long from, long size) throws IOException\n  {\n    if (!pathExists(path)) {\n      throw new FileNotFoundException(\"Unable to find file \" + fileWithBasePath(path).toPath() + \" for reading\");\n    }\n    long length = fileWithBasePath(path).length();\n    if (from < 0 || size < 0 || (from + size) > length) {\n      throw new IAE(\n          \"Invalid arguments for reading %s. from = %d, readSize = %d, fileSize = %d\",\n          fileWithBasePath(path).toPath(),\n          from,\n          size,\n          length\n      );\n    }\n    FileChannel fileChannel = FileChannel.open(fileWithBasePath(path).toPath(), StandardOpenOption.READ);\n    return new BoundedInputStream(Channels.newInputStream(fileChannel.position(from)), size);\n  }\n\n  /**\n   * Writes the file present with the materialized location as basePath + path.\n   * In case the parent directory does not exist, we create the parent dir recursively.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/storage/local/LocalFileStorageConnector.java#L56-L92","documentation":"LocalFileStorageConnector.readRange throws FileNotFoundException when the requested relative path does not exist under the connector's base path. It means a read of a byte range was requested for a file absent from local storage.","triggerScenarios":"readRange(path, from, size) where pathExists(path) is false: file deleted (e.g. by cleanup/kill tasks), wrong relative path, segment not yet downloaded to local cache, typo or case-mismatch on the path.","commonSituations":"Segment files cleaned up while a task still needs them; querying an export file that finished/was removed; path casing differences on case-sensitive filesystems; load rule dropped the segment from the historical's cache.","solutions":["Confirm the exact relative path exists under the base path (ls); fix typos/case mismatches.","Re-fetch or re-download the segment/file (trigger re-load or re-run export) since it may have been cleaned up.","Check retention/cleanup jobs that may have deleted the file concurrently.","Validate file existence before issuing range reads and handle FileNotFoundException explicitly in callers."],"exampleFix":"// before\nInputStream in = connector.readRange(\"export/2024/result.csv\", 0, 1024); // file deleted\n// after\nFile f = new File(basePath, \"export/2024/result.csv\");\nif (!f.isFile()) {\n  throw new FileNotFoundException(\"regenerate export: missing \" + f);\n}\nInputStream in = connector.readRange(\"export/2024/result.csv\", 0, 1024);","handlingStrategy":"try-catch","validationCode":"if (!new File(basePath, path).isFile()) throw new FileNotFoundException(path);","typeGuard":"boolean exists(StorageConnector c, String p) { try { return c.pathExists(p); } catch (IOException e) { return false; } }","tryCatchPattern":"try { in = connector.readRange(path, from, size); } catch (FileNotFoundException e) { log.warn(e, \"file missing: %s\", path); in = regenerateAndReopen(path); }","preventionTips":["Check pathExists before range reads.","Coordinate retention/cleanup jobs with consumers of the files.","Verify path casing on case-sensitive filesystems.","Re-trigger loads/exports instead of assuming files persist."],"tags":["local-storage","file-not-found","read-range"],"backgroundTag":"file-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}