{"record":{"id":"62e023b39aa18baf","repo":"apache/druid","slug":"failed-to-get-segment-factory-for-s","errorCode":null,"errorMessage":"Failed to get segment factory for %s","messagePattern":"Failed to get segment factory for (.+?)","errorType":"exception","errorClass":"SegmentLoadingException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java","lineNumber":2460,"sourceCode":"            segment.getId(),\n            segment.getSize(),\n            result.getSize()\n        );\n      }\n    }\n\n    @GuardedBy(\"entryLock\")\n    private SegmentizerFactory getSegmentFactory(final File segmentFiles) throws SegmentLoadingException\n    {\n      final File factoryJson = new File(segmentFiles, \"factory.json\");\n      final SegmentizerFactory factory;\n\n      if (factoryJson.exists()) {\n        try {\n          factory = jsonMapper.readValue(factoryJson, SegmentizerFactory.class);\n        }\n        catch (IOException e) {\n          throw new SegmentLoadingException(e, \"Failed to get segment factory for %s\", e.getMessage());\n        }\n      } else {\n        factory = new MMappedQueryableSegmentizerFactory(indexIO);\n      }\n      return factory;\n    }\n\n    @Override\n    public boolean equals(Object o)\n    {\n      if (o == null || getClass() != o.getClass()) {\n        return false;\n      }\n      CompleteSegmentCacheEntry that = (CompleteSegmentCacheEntry) o;\n      return Objects.equals(dataSegment, that.dataSegment);\n    }\n\n    @Override","sourceCodeStart":2442,"sourceCodeEnd":2478,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/segment/loading/SegmentLocalCacheManager.java#L2442-L2478","documentation":"Thrown when the cache's factory.json (segmentizerFactory descriptor) exists for a segment but cannot be deserialized into a SegmentizerFactory due to an IOException (corrupt or unreadable JSON). This file records how to open the locally cached segment; failure blocks loading that segment from cache.","triggerScenarios":"getSegmentFactory path: factoryJson.exists() is true but jsonMapper.readValue(factoryJson, SegmentizerFactory.class) throws IOException — truncated/corrupted file (e.g. crash during write) or unreadable permissions.","commonSituations":"Unclean shutdown while factory.json was being written; disk corruption; cache directory copied/rsynced incorrectly; wrong file permissions after user change.","solutions":["Delete the corrupt factory.json (or the whole segment directory) in the cache location so the segment re-downloads fresh.","Check file permissions/readability for the Druid process user.","Look for filesystem errors (dmesg, fsck) if corruption is widespread; restore from a healthy cache or wipe the cache.","Retry the load after cleanup; the segment is re-fetched from deep storage and a new factory.json is written."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check factory.json parseability before loading from cache\nnew ObjectMapper().readValue(factoryJson, SegmentizerFactory.class); // delete file if this throws","typeGuard":null,"tryCatchPattern":"try { loadSegment(segment); } catch (SegmentLoadingException e) { if (e.getMessage().contains(\"Failed to get segment factory\")) { deleteSegmentDir(segment); retryLoad(segment); } }","preventionTips":["Avoid hard power-offs; use graceful shutdown so factory.json writes complete.","Validate cache directories after copying/migrating them between hosts.","Detect widespread corruption with periodic filesystem checks."],"tags":["segment-cache","json-deserialization","corrupt-file","factory-json"],"backgroundTag":"json-parse-error","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"}