{"record":{"id":"1ef0394d6d5d1b9f","repo":"apache/druid","slug":"can-t-find-previously-allocated-segmentid-s-for","errorCode":null,"errorMessage":"Can't find previously allocated segmentId[%s] for sequence[%s]","messagePattern":"Can't find previously allocated segmentId\\[(.+?)\\] for sequence\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/SinglePhaseParallelIndexTaskRunner.java","lineNumber":236,"sourceCode":"  ) throws IOException\n  {\n    NonnullPair<Interval, String> intervalAndVersion = findIntervalAndVersion(timestamp, LockGranularity.TIME_CHUNK);\n\n    MutableObject<SegmentIdWithShardSpec> segmentIdHolder = new MutableObject<>();\n    sequenceToSegmentIds.compute(sequenceName, (k, v) -> {\n      final int prevSegmentIdIndex;\n      final List<String> segmentIds;\n      if (prevSegmentId == null) {\n        prevSegmentIdIndex = -1;\n        segmentIds = v == null ? new ArrayList<>() : v;\n      } else {\n        segmentIds = v;\n        if (segmentIds == null) {\n          throw new ISE(\"Can't find previous segmentIds for sequence[%s]\", sequenceName);\n        }\n        prevSegmentIdIndex = segmentIds.indexOf(prevSegmentId);\n        if (prevSegmentIdIndex == -1) {\n          throw new ISE(\"Can't find previously allocated segmentId[%s] for sequence[%s]\", prevSegmentId, sequenceName);\n        }\n      }\n      final int nextSegmentIdIndex = prevSegmentIdIndex + 1;\n      final SegmentIdWithShardSpec newSegmentId;\n      if (nextSegmentIdIndex < segmentIds.size()) {\n        SegmentId segmentId = SegmentId.tryParse(dataSource, segmentIds.get(nextSegmentIdIndex));\n        if (segmentId == null) {\n          throw new ISE(\"Illegal segmentId format [%s]\", segmentIds.get(nextSegmentIdIndex));\n        }\n        newSegmentId = new SegmentIdWithShardSpec(\n            segmentId.getDataSource(),\n            segmentId.getInterval(),\n            segmentId.getVersion(),\n            new BuildingNumberedShardSpec(segmentId.getPartitionNum())\n        );\n      } else {\n        final int partitionNum = Counters.getAndIncrementInt(partitionNumCountersPerInterval, intervalAndVersion.lhs);\n        newSegmentId = new SegmentIdWithShardSpec(","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/SinglePhaseParallelIndexTaskRunner.java#L218-L254","documentation":"Thrown by SinglePhaseParallelIndexTaskRunner.allocateNewSegment when the sequence's list of previously allocated segment IDs exists but does not contain the prevSegmentId reported by the caller. The runner expects each new allocation request to reference a segment ID it previously handed out for that sequence, appended in order. A missing ID means the caller's view of the allocation history is out of sync with the runner's.","triggerScenarios":"A subtask requests the successor segment for prevSegmentId X for sequence S, but S's ID list in the runner's map contains other IDs (e.g., from a different attempt) and not X — typically after task retries with stale allocation state or manually resubmitted subtask specs.","commonSituations":"Parallel batch ingestion where some subtasks from an earlier attempt survive or are retried after the supervisor rebuilt its partition map; cloning/restoring task state; running overlapping compaction or append tasks on the same interval.","solutions":["Resubmit the supervisor task so all subtask attempts and segment allocations restart consistently","Inspect the supervisor's task reports and locate the subtask whose reported prevSegmentId no longer matches; kill stale subtasks","Confirm you are not reusing old subtask spec IDs against a restarted supervisor","Check for known fixed bugs in your Druid version and upgrade if affected"],"exampleFix":"// before: stale subtask reports prevSegmentId from a prior attempt\nrunner.allocated(prevSegmentId /* from attempt 1 */, sequenceName);\n// after: ensure the subtask is restarted with current attempt state,\n// or validate membership before requesting:\nif (segmentIds.contains(prevSegmentId)) { runner.allocated(prevSegmentId, sequenceName); }","handlingStrategy":"retry","validationCode":"// confirm the reported segment belongs to the current allocation state\nList<String> ids = partitionMap.get(sequenceName);\nboolean valid = ids != null && ids.contains(prevSegmentId);\nif (!valid) { throw new IllegalStateException(\"stale prevSegmentId \" + prevSegmentId); }","typeGuard":null,"tryCatchPattern":"catch (ISE e) {\n  if (e.getMessage().contains(\"Can't find previously allocated segmentId\")) {\n    killStaleSubtasks(supervisorTaskId);\n    resubmitSupervisor(taskSpec); // full restart rebuilds allocation history\n  } else throw e;\n}","preventionTips":["Always restart the entire supervisor task rather than individual subtasks after failures","Kill orphaned subtasks from earlier attempts before retrying","Avoid concurrent tasks (compaction/ingestion) targeting the same intervals without locks","Track attempt numbers in monitoring to detect stale subtask reports"],"tags":["ingestion","batch-ingestion","segment-allocation"],"backgroundTag":"record-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}