{"record":{"id":"eba7a036b7d2ae00","repo":"apache/druid","slug":"result-partition-information-is-not-ready-yet","errorCode":null,"errorMessage":"Result partition information is not ready yet","messagePattern":"Result partition information is not ready yet","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"multi-stage-query/src/main/java/org/apache/druid/msq/kernel/controller/ControllerStageTracker.java","lineNumber":241,"sourceCode":"  {\n    return phase;\n  }\n\n  /**\n   * Whether partitions for the results of this stage have been set.\n   */\n  boolean hasResultPartitions()\n  {\n    return resultPartitions != null;\n  }\n\n  /**\n   * Partitions for the results of the stage associated with this tracker.\n   */\n  ReadablePartitions getResultPartitions()\n  {\n    if (resultPartitions == null) {\n      throw new ISE(\"Result partition information is not ready yet\");\n    } else {\n      return resultPartitions;\n    }\n  }\n\n  /**\n   * @return Partition boundaries for the results of this stage\n   */\n  ClusterByPartitions getResultPartitionBoundaries()\n  {\n    if (!getStageDefinition().doesShuffle()) {\n      throw new ISE(\"Result partition information is not relevant to this stage because it does not shuffle\");\n    } else if (resultPartitionBoundaries == null) {\n      throw new ISE(\"Result partition information is not ready yet\");\n    } else {\n      return resultPartitionBoundaries;\n    }\n  }","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/multi-stage-query/src/main/java/org/apache/druid/msq/kernel/controller/ControllerStageTracker.java#L223-L259","documentation":"ControllerStageTracker.getResultPartitions returns the ReadablePartitions for a stage's results, but until the stage finishes (or its partition count is known) the internal resultPartitions field is null. Callers that read partitions before the stage has reached a phase where partitions are known trigger this ISE — a guard against reading controller state too early.","triggerScenarios":"Calling getResultPartitions() while the tracked stage is still running (e.g. during READING_INPUT/POST_COMPUTATION phase) before resultPartitions is set by finish()/state advancement; also after controller restart if partition info was not persisted.","commonSituations":"Controller-side code that checks downstream readiness and assumes partitions are known as soon as a stage starts; custom controller extensions or debugging code polling result partitions mid-stage; race between stage completion callback and partition query.","solutions":["Check the stage phase before calling: only read partitions once the tracker reports the stage finished (or use a method that returns Optional/null for unknown partitions).","Use ControllerQueryKernel's phase-based APIs (e.g. checking resultPrefix/readyForReading) instead of direct partition access during execution.","If hit intermittently in logs, add a guard: if (tracker.getResultPartitionsIfKnown() == null) skip and re-check on next controller tick."],"exampleFix":"// before\nReadablePartitions p = tracker.getResultPartitions();\n\n// after\nif (kernel.getStagePhase(stageId) == StagePhase.FINISHED) {\n  ReadablePartitions p = tracker.getResultPartitions();\n}","handlingStrategy":"retry","validationCode":"if (kernel.getStagePhase(stageId) != StagePhase.FINISHED) {\n  // partitions not knowable yet — defer the read\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  ReadablePartitions p = tracker.getResultPartitions();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"not ready yet\")) {\n    // re-check on next controller tick\n  } else {\n    throw e;\n  }\n}","preventionTips":["Only read result partitions after the stage reaches its finished phase.","Prefer phase-gated kernel APIs over direct tracker field access in extensions.","In polling loops, treat 'not ready' as expected and back off."],"tags":["msq","controller","state-timing","internal-state"],"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-14T05:17:10.506Z"}