apache/druid · error · SegmentLoadingException

%s

Error message

%s

What it means

MMappedQueryableSegmentizerFactory.factorize loads the segment via indexIO.loadIndex and wraps any resulting IOException in a SegmentLoadingException carrying the IO error message. It means the segment could not be memory-mapped/read from its local files.

Source

Thrown at processing/src/main/java/org/apache/druid/segment/loading/MMappedQueryableSegmentizerFactory.java:52

 */
public class MMappedQueryableSegmentizerFactory implements SegmentizerFactory
{

  private final IndexIO indexIO;

  public MMappedQueryableSegmentizerFactory(@JacksonInject IndexIO indexIO)
  {
    this.indexIO = Preconditions.checkNotNull(indexIO, "Null IndexIO");
  }

  @Override
  public Segment factorize(DataSegment dataSegment, File parentDir, boolean lazy, SegmentLazyLoadFailCallback loadFailed) throws SegmentLoadingException
  {
    try {
      return new QueryableIndexSegment(indexIO.loadIndex(parentDir, lazy, loadFailed), dataSegment.getId());
    }
    catch (IOException e) {
      throw new SegmentLoadingException(e, "%s", e.getMessage());
    }
  }
}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Check the segment files exist and are complete in parentDir
  2. Clear the corrupted segment from the local cache and let Druid re-download it
  3. Verify segment was written by a compatible Druid version
  4. Look at the wrapped IOException cause for the exact filesystem failure

Example fix

// before
// retry load against corrupt dir forever
// after
if (!indexIO.segmentExists(parentDir)) { cacheCleaner.cleanup(parentDir); }
Segment seg = new MMappedQueryableSegmentizerFactory(indexIO).factorize(segment, parentDir, lazy, cb);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!indexIO.segmentExists(parentDir)) { throw new SegmentNotLoadedException(parentDir); }

Type guard

boolean loadable(File dir) { return dir.isDirectory() && new File(dir, "meta.json").isFile() && new File(dir, "index.drd").isFile(); }

Try / catch

try { return new MMappedQueryableSegmentizerFactory(indexIO).factorize(segment, dir, lazy, cb); } catch (SegmentLoadingException e) { cacheCleaner.cleanup(dir); log.error(e, "Dropped corrupt segment dir %s", dir); throw e; }

Prevention

When it happens

Trigger: factorize is invoked during segment loading but loadIndex throws IOException due to missing/corrupt index files, mmapping failure, or unreadable segment directory.

Common situations: Corrupted historical segment cache; segment deleted mid-load; NFS/overlay filesystem mmapping issues; wrong Druid version reading segments written by an incompatible writer version.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/9722bc489fcc5432. Report an issue: GitHub.