Add max_skip_unavailable_shards_num and max_skip_unavailable_shards_ratio settings by alexey-milovidov · Pull Request #99369 · ClickHouse/ClickHouse · GitHub
Skip to content

Add max_skip_unavailable_shards_num and max_skip_unavailable_shards_ratio settings#99369

Merged
alexey-milovidov merged 4 commits into
masterfrom
max_skip_unavailable_shards
Mar 16, 2026
Merged

Add max_skip_unavailable_shards_num and max_skip_unavailable_shards_ratio settings#99369
alexey-milovidov merged 4 commits into
masterfrom
max_skip_unavailable_shards

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Add max_skip_unavailable_shards_num (UInt64, default 0) setting: when skip_unavailable_shards is enabled, if the number of unavailable shards exceeds this value, throw TOO_MANY_UNAVAILABLE_SHARDS instead of silently skipping. A value of 0 means no limit.
  • Add max_skip_unavailable_shards_ratio (Float, default 0) setting: same but based on the ratio of unavailable shards to total shards. A value of 0 means no limit.
  • This prevents silently returning incomplete results when a large portion of the cluster is down.

Test plan

  • Added stateless test 04038_max_skip_unavailable_shards that verifies:
    • Settings have no effect when skip_unavailable_shards is disabled
    • Queries succeed when within the threshold (both num and ratio)
    • TOO_MANY_UNAVAILABLE_SHARDS is thrown when thresholds are exceeded
    • Both 2-shard and 3-shard configurations are tested

Changelog category:

  • New Feature

Changelog entry:

Added max_skip_unavailable_shards_num and max_skip_unavailable_shards_ratio settings to limit how many shards can be silently skipped when skip_unavailable_shards is enabled. If the number or ratio of unavailable shards exceeds the configured threshold, an exception is thrown instead of returning silently incomplete results.

🤖 Generated with Claude Code


Note

Medium Risk
Touches distributed query execution to optionally throw when too many shards are skipped, which could change runtime behavior for users enabling the new limits. Default settings preserve existing behavior but the new shared tracker/exception path needs careful review for concurrency and query fan-out cases.

Overview
Adds two new settings, max_skip_unavailable_shards_num and max_skip_unavailable_shards_ratio, to cap how many shards can be silently skipped when skip_unavailable_shards is enabled; exceeding either threshold now throws TOO_MANY_UNAVAILABLE_SHARDS instead of returning partial results.

Implements a shared UnavailableShardTracker wired from executeQuery into ReadFromRemote/RemoteQueryExecutor so each skipped shard is counted once across the whole distributed query, and adds a stateless test covering success/error cases for both numeric and ratio limits.

Written by Cursor Bugbot for commit 01d35a1. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.704

…s_ratio` settings

When `skip_unavailable_shards` is enabled, these settings limit how many
shards can be silently skipped before throwing an exception:

- `max_skip_unavailable_shards_num` (UInt64, default 0): if the number
  of unavailable shards exceeds this value, throw `TOO_MANY_UNAVAILABLE_SHARDS`.
  A value of 0 means no limit.

- `max_skip_unavailable_shards_ratio` (Float, default 0): if the ratio
  of unavailable shards to total shards exceeds this value, throw
  `TOO_MANY_UNAVAILABLE_SHARDS`. A value of 0 means no limit.

This prevents silently returning incomplete results when a large portion
of the cluster is down.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clickhouse-gh

clickhouse-gh Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Mar 13, 2026
Comment thread src/Processors/QueryPlan/ReadFromRemote.cpp
…s_ratio` to SettingsChangesHistory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/QueryPipeline/RemoteQueryExecutor.h
@orloffv

orloffv commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

@alexey-milovidov
One request: when shards are skipped within the threshold (no exception thrown), could the response include some signal that the result is partial — e.g. an HTTP header like X-ClickHouse-Unavailable-Shards: 2/5, or a counter in the progress/metadata block?
Without this, callers can't distinguish a complete result from a silently degraded one, which makes the feature risky to use in production.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The same UnavailableShardTracker is attached to multiple RemoteQueryExecutor instances that can correspond to one physical shard in the parallel-replicas custom-key path, so one unavailable shard can be counted multiple times and trigger TOO_MANY_UNAVAILABLE_SHARDS incorrectly.

This is alright.

…re in headers

Avoid including `UnavailableShardTracker.h` (which pulls in `Common/Exception.h`)
from high-fan-out headers `RemoteQueryExecutor.h` and `ReadFromRemote.h`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@orloffv, yes, I want to add it. It will be one of the next PRs.

Comment thread src/Interpreters/ClusterProxy/executeQuery.cpp
Comment thread src/Interpreters/ClusterProxy/executeQuery.cpp
@clickhouse-gh

clickhouse-gh Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.70% 83.70% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.20% 76.30% +0.10%

PR changed lines: PR changed-lines coverage: 99.16% (118/119, 0 noise lines excluded)
Diff coverage report
Uncovered code

@alexey-milovidov alexey-milovidov self-assigned this Mar 16, 2026
@alexey-milovidov alexey-milovidov added this pull request to the merge queue Mar 16, 2026
Merged via the queue into master with commit 5168c3b Mar 16, 2026
163 checks passed
@alexey-milovidov alexey-milovidov deleted the max_skip_unavailable_shards branch March 16, 2026 12:29
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants