{"record":{"id":"7cd8deeac9e6dc70","repo":"apache/druid","slug":"specified-segments-in-the-spec-are-different-from","errorCode":null,"errorMessage":"Specified segments in the spec are different from the current used segments. Possibly new segments would have been added or some segments have been unpublished.","messagePattern":"Specified segments in the spec are different from the current used segments\\. Possibly new segments would have been added or some segments have been unpublished\\.","errorType":"exception","errorClass":"ISE","httpStatus":null,"severity":"error","filePath":"indexing-service/src/main/java/org/apache/druid/indexing/common/task/CompactionTask.java","lineNumber":1405,"sourceCode":"    {\n      return new ArrayList<>(\n          actionClient.submit(\n              new RetrieveUsedSegmentsAction(\n                  dataSource,\n                  ImmutableList.of(interval),\n                  EnumSet.of(SegmentDetail.LOAD_SPEC)\n              )\n          )\n      );\n    }\n\n    void checkSegments(LockGranularity lockGranularityInUse, List<DataSegment> latestSegments)\n    {\n      if (latestSegments.isEmpty()) {\n        throw new ISE(\"No segments found for compaction. Please check that datasource name and interval are correct.\");\n      }\n      if (!inputSpec.validateSegments(lockGranularityInUse, latestSegments)) {\n        throw new ISE(\n            \"Specified segments in the spec are different from the current used segments. \"\n            + \"Possibly new segments would have been added or some segments have been unpublished.\"\n        );\n      }\n    }\n  }\n\n  public static class Builder\n  {\n    private final String dataSource;\n    private final SegmentCacheManagerFactory segmentCacheManagerFactory;\n\n    @Nullable\n    private String id;\n    private CompactionIOConfig ioConfig;\n    @Nullable\n    private DimensionsSpec dimensionsSpec;\n    @Nullable","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/indexing-service/src/main/java/org/apache/druid/indexing/common/task/CompactionTask.java#L1387-L1423","documentation":"CompactionTask's checkSegments compares the segments listed in the compaction spec's inputSpec against the segments currently published in metadata storage. If they differ (segments added or unpublished since the spec was written), this ISE is thrown to prevent compacting against stale input. The library throws it as a concurrency/staleness guard.","triggerScenarios":"Submitting a compaction spec with an explicit inputSpec listing segment IDs, but between spec creation and task execution new segments were published (real-time tasks) or some listed segments were killed/unpublished (replacement or retention rules).","commonSituations":"Compacting a datasource that is actively ingesting; a concurrent replace/kill task changed the segment set; re-submitting an old auto-compaction spec after the underlying data changed.","solutions":["Re-generate the compaction spec from current segment metadata and resubmit","Wait for ingestion to quiesce, then compact; or use segment-granularity intervals that are no longer being written","Kill or let retention rules remove obsolete segments first, then rebuild the spec","If using automatic compaction, let the coordinator recompute the latest segments instead of pinning inputSpec segments"],"exampleFix":"// before\n\"inputSpec\": { \"type\": \"segments\", \"segments\": [\"ds_2019-01-01T00:00:00.000Z_2019-01-02T00:00:00.000Z_2020-01-01T00:00:00.000Z\"] } // stale\n// after\n\"inputSpec\": { \"type\": \"interval\", \"interval\": \"2019-01-01/2019-01-02\" } // resolved against current segments at run time","handlingStrategy":"retry","validationCode":"List<String> current = coordinator.getSegmentIds(ds, interval);\nList<String> pinned = spec.getInputSpec().getSegments();\nif (!new HashSet<>(current).equals(new HashSet<>(pinned))) {\n  spec.refreshInputSpec(current); // rebuild before submitting\n}","typeGuard":null,"tryCatchPattern":"try {\n  submitCompaction(spec);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"Specified segments in the spec are different\")) {\n    spec = rebuildSpecFromCurrentMetadata(); // regenerate and retry once\n    submitCompaction(spec);\n  } else throw e;\n}","preventionTips":["Prefer interval-based inputSpec over pinned segment lists for active datasources","Compact only after ingestion for the interval is complete","Rebuild auto-compaction configs after replace/kill operations","Avoid concurrent replace and compaction on the same intervals"],"tags":["druid","compaction","stale-state","concurrency"],"backgroundTag":"invalid-state-transition","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"}