← Back to Pull requests

perf: pick a single random server without copying the replica set #20951

Open
unknown opened this pull request with 266 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 21, 2026 05:03 UTC
Author

Description

Tier selector strategies pick one server per segment by calling ServerSelectorStrategy.pick(servers, segment, 1). When a segment has more than one replica, RandomServerSelectorStrategy handled that by copying the set into a list, shuffling it, and copying the first element into another list. It did that for every segment of every query: once when routing segments to servers, and once in the result-level cache ETag computation, which checks per segment that the picked server is a Historical.

In a sampling profile of a Broker serving result-level cache hits over 160,983 segments, those copies were about 18% of the query thread. The profile had about 110 samples on that thread, so the share is approximate.

Choose one server directly for a single pick

When numServersToPick is 1 and there is more than one server, RandomServerSelectorStrategy now returns one server chosen with Iterators.get(servers.iterator(), random index), the same way its single-server pick(servers, segment) already did. Every server is still equally likely to be picked. Picks of more than one server, and sets no larger than the number requested, behave as before. Other server and tier selector strategies are unchanged.

An alternative was to change AbstractTierSelectorStrategy to call the single-server pick directly. I didn't, because several tier strategies (preferred, strict, pooled) override the list-returning pick, and their single picks go through that override.

<hr>

##### Key changed/added classes in this PR
* RandomServerSelectorStrategy

<hr>

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.

  • - TierSelectorStrategyTest: single picks return one server and reach every server, and picks of 2 and 3 servers still work.
  • been tested in a test Druid cluster.
  • Diff: 266 lines (+199 / -67) across 3 files Reviewer: FrankChen021 Review duration: 14564m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.39) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 266 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.334
    Real PR Conversation Timeline
    1 comments
    "Review active on #20951"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 22.4% · Safe to merge
    22.4%
    Repository