← Back to Pull requests

fix: sys.segments is_realtime is 0 for published segments served only by realtime tasks #20930

Closed
unknown closed this pull request without merging on Nov 19, 2026 22:15 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 20:09 UTC
Author

Description

sys.segments.is_realtime is documented as:

1 if this segment is _only_ served by realtime tasks, and 0 if any Historical process is serving this segment.

It did not do that for published segments. A segment that was published but not handed off yet, and so was served only by its realtime task, showed is_realtime = 0.

This replaces #20926, which worked around the wrong value in a test. See https://github.com/apache/druid/pull/20926#discussion_r4619696682.

Root cause

For segments returned by the Coordinator, SystemSchema copied is_realtime from SegmentStatusInCluster. MetadataResource sets that flag to false for every published segment. The Coordinator only uses it to mark the unpublished realtime segments it adds when centralized datasource schema is enabled.

Fix

The Broker already tracks which servers serve each segment. AvailableSegmentMetadata.isRealtime() is 0 as soon as any Historical serves the segment and 1 while only realtime servers do. SystemSchema now uses that value for a published segment that the Broker sees being served, and falls back to the Coordinator's value otherwise.

is_published, is_available and is_active are unchanged.

Flaky stream test

This also fixes the flaky row count in KafkaIndexFaultToleranceTest.test_supervisorRecovers_afterCoordinatorRestart that #20926 was about:

StreamIndexTestBase.verifyRowCount:216
Query[SELECT COUNT(*) FROM %s] failed ==> expected: <3000> but was: <2480>

The test's supervisor has a 5 second completion timeout. When the Coordinator restart takes longer than that, the supervisor kills a publishing task that is still waiting for handoff. The task's segments are published, but no server serves them until a Historical loads them, and a count that runs in that window is short. The timeline from a failed run is in #20926.

  • Add EmbeddedClusterApis.waitForAllSegmentsToBeHandedOff. It polls sys.segments until the number of segments with is_available = 1 AND is_realtime = 0 reaches the number of used segments.

  • StreamIndexTestBase.verifyRowCount calls it in place of waitForAllSegmentsToBeAvailable, which sums the Broker's schema refresh count since startup and so can pass before handoff.
  • The completion timeout in the test is unchanged.

    Release note

    sys.segments.is_realtime is now 1 for a segment that has been published but is still served only by realtime tasks. Before, it was 0 for every published segment.

    Testing

  • New SystemSchemaTest.testSegmentsTableIsRealtimeForPublishedSegments covers published segments served by a Historical only, by a Historical and a realtime server, by a realtime server only, and by no server. It fails without the fix.

  • The four test classes that use verifyRowCount pass locally (19 tests). The failure is rare, so this shows that the wait works, not that the flake is gone.
  • ##### Key changed/added classes in this PR
    SystemSchema
    EmbeddedClusterApis
    * StreamIndexTestBase

    This PR has:

  • been self-reviewed.

  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.

  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • 🤖 Generated with Claude Code

    Diff: 421 lines (+315 / -106) across 5 files Reviewer: gianm Review duration: 1565m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 421 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #20930"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45% (MEDIUM) · Higher = larger blast radius
    45%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%
    Repository