apache/druid · error · IAE

Interval[%s] to compact is not aligned with segmentGranulari

Error message

Interval[%s] to compact is not aligned with segmentGranularity[%s]

What it means

Major compaction requires the compaction interval to align exactly to segmentGranularity buckets: the interval start must be a bucket start and the end must be a bucket end. If the user-supplied interval doesn't equal the widened bucket-aligned interval, createMajorCompactionIoConfig throws IAE.

Source

Thrown at indexing-service/src/main/java/org/apache/druid/indexing/common/task/NativeCompactionRunner.java:194

  private static ParallelIndexIOConfig createMajorCompactionIoConfig(
      TaskToolbox toolbox,
      DataSchema dataSchema,
      Interval inputInterval,
      CoordinatorClient coordinatorClient,
      SegmentCacheManagerFactory segmentCacheManagerFactory,
      CompactionIOConfig compactionIOConfig
  )
  {
    if (!compactionIOConfig.isAllowNonAlignedInterval()) {
      final Granularity segmentGranularity = dataSchema.getGranularitySpec().getSegmentGranularity();
      final Interval widenedInterval = Intervals.utc(
          segmentGranularity.bucketStart(inputInterval.getStart()).getMillis(),
          segmentGranularity.bucketEnd(inputInterval.getEnd().minus(1)).getMillis()
      );

      if (!inputInterval.equals(widenedInterval)) {
        throw new IAE(
            "Interval[%s] to compact is not aligned with segmentGranularity[%s]",
            inputInterval,
            segmentGranularity
        );
      }
    }

    return new ParallelIndexIOConfig(
        new DruidInputSource(
            dataSchema.getDataSource(),
            inputInterval,
            null,
            null,
            null,
            null,
            toolbox.getIndexIO(),
            coordinatorClient,
            segmentCacheManagerFactory,

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Adjust the compaction interval to bucket boundaries, e.g. Intervals.utc(bucketStart, bucketEnd) via Granularity.bucketStart/bucketEnd
  2. Compute the interval from the target segments' actual min/max times then align it with segmentGranularity
  3. If alignment isn't possible, lower segmentGranularity for that compaction to match the interval

Example fix

// before
Intervals.of("2024-01-01T05:00:00/2024-01-02")  // with segmentGranularity=day
// after
Intervals.of("2024-01-01/2024-01-02")
Defensive patterns

Strategy: validation

Validate before calling

Interval aligned = Intervals.utc(
  segmentGranularity.bucketStart(input.getStart()).getMillis(),
  segmentGranularity.bucketEnd(input.getEnd().minus(1)).getMillis());
if (!input.equals(aligned)) { input = aligned; }

Try / catch

try { submitCompaction(cfg); } catch (IAE e) { if (e.getMessage().contains("not aligned with segmentGranularity")) { submitCompaction(withAlignedInterval(cfg)); } else { throw e; } }

Prevention

When it happens

Trigger: Submitting a compaction task (native runner) whose inputInterval is not bucket-aligned with the configured segmentGranularity — e.g. interval 2024-01-01T05/2024-01-02 with day granularity.

Common situations: Manually typed compaction intervals not snapped to midnight; auto-compaction configs with partial-day intervals after changing segmentGranularity; DST/timezone offsets making an interval appear misaligned.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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