{"record":{"id":"a957914bb96210b7","repo":"apache/druid","slug":"can-t-find-segmentsforsequence-for-sequence-s","errorCode":null,"errorMessage":"Can't find segmentsForSequence for sequence[%s]","messagePattern":"Can't find segmentsForSequence for sequence\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/segment/realtime/appenderator/BatchAppenderatorDriver.java","lineNumber":168,"sourceCode":"    // Sanity check\n    final Map<SegmentIdWithShardSpec, DataSegment> pushedSegmentIdToSegmentMap = segmentsAndCommitMetadata\n        .getSegments()\n        .stream()\n        .collect(Collectors.toMap(SegmentIdWithShardSpec::fromDataSegment, Function.identity()));\n\n    if (!pushedSegmentIdToSegmentMap.keySet().equals(requestedSegmentIdsForSequences)) {\n      throw new ISE(\n          \"Pushed segments[%s] are different from the requested ones[%s]\",\n          pushedSegmentIdToSegmentMap.keySet(),\n          requestedSegmentIdsForSequences\n      );\n    }\n\n    synchronized (segments) {\n      for (String sequenceName : sequenceNames) {\n        final SegmentsForSequence segmentsForSequence = segments.get(sequenceName);\n        if (segmentsForSequence == null) {\n          throw new ISE(\"Can't find segmentsForSequence for sequence[%s]\", sequenceName);\n        }\n\n        segmentsForSequence.getAllSegmentsOfInterval().forEach(segmentsOfInterval -> {\n          final SegmentWithState appendingSegment = segmentsOfInterval.getAppendingSegment();\n          if (appendingSegment != null) {\n            final DataSegment pushedSegment = pushedSegmentIdToSegmentMap.get(appendingSegment.getSegmentIdentifier());\n            if (pushedSegment == null) {\n              throw new ISE(\"Can't find pushedSegments for segment[%s]\", appendingSegment.getSegmentIdentifier());\n            }\n\n            segmentsOfInterval.finishAppendingToCurrentActiveSegment(\n                segmentWithState -> segmentWithState.pushAndDrop(pushedSegment)\n            );\n          }\n        });\n      }\n    }\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/segment/realtime/appenderator/BatchAppenderatorDriver.java#L150-L186","documentation":"Thrown by BatchAppenderatorDriver.pushAndClear when it iterates the sequence names used for pushing and finds no SegmentsForSequence entry in the driver's internal segments map. Every sequence that had pending pushes must have bookkeeping state; a missing entry means the sequence was never registered or was already cleaned up.","triggerScenarios":"pushAndClear iterating sequenceNames after a push and encountering a sequenceName with no entry in the synchronized segments map — e.g. pushAllAndClear called with sequences whose state was already cleared by a previous pushAndClear call.","commonSituations":"Double-invocation of pushAllAndClear in the same task lifecycle; calling the driver after commit/cleanup; task restart logic reusing stale sequence names; bugs in task orchestration code around the batch driver.","solutions":["Ensure pushAllAndClear is called exactly once per batch task lifecycle, before completing the publish","Verify no code path calls pushAndClear twice or after segments were cleared","Check task logs for earlier driver calls that reset sequence state","Retry the task if the state desync resulted from a transient failure"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure each sequence still has bookkeeping state before pushing\nfor (String seq : sequenceNames) {\n  if (!driver.hasSequence(seq)) {\n    throw new IllegalStateException(\"Sequence already cleared: \" + seq);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  driver.pushAllAndClear(publisher, commitFn);\n} catch (ISE e) {\n  if (e.getMessage().startsWith(\"Can't find segmentsForSequence\")) {\n    // sequence state already cleared; restart the task rather than re-pushing\n    throw new TaskAbortedException(e);\n  }\n  throw e;\n}","preventionTips":["Never call pushAllAndClear more than once in a task lifecycle","Do not reuse stale sequence names after a prior push/clear cycle","Keep driver creation, append, and push within one well-defined task scope","On task retry, recreate the driver from scratch instead of reusing state"],"tags":["java","druid","ingestion","internal-state"],"backgroundTag":"entity-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"}