Skip to content

Allow skipping local shard with missing table when skip_unavailable_shards is enabled - #100141

Merged
alexey-milovidov merged 31 commits into
masterfrom
fix-skip-local-missing-table
May 6, 2026
Merged

alexey-milovidov merged 31 commits into
masterfrom
fix-skip-local-missing-table

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 19, 2026 •

Copy link
Copy Markdown
Member

When a distributed query targets a table that doesn't exist on a local replica and there are no remote replicas to fall back to, the query would always fail with UNKNOWN_TABLE even when skip_unavailable_shards was enabled. Remote shards with missing tables could be skipped, but local shards could not, which was inconsistent.

Now, when skip_unavailable_shards is enabled and the table is absent on the local replica with no remote replicas configured, the shard is skipped instead of failing.

Closes #100134

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Allow skipping local shard with missing table when skip_unavailable_shards is enabled.

Version info

  • Merged into: 26.5.1.344

…shards` is enabled

When a distributed query targets a table that doesn't exist on a local
replica and there are no remote replicas to fall back to, the query
would always fail with `UNKNOWN_TABLE` even when `skip_unavailable_shards`
was enabled. Remote shards with missing tables could be skipped, but
local shards could not, which was inconsistent.

Now, when `skip_unavailable_shards` is enabled and the table is absent
on the local replica with no remote replicas configured, the shard is
skipped instead of failing.

Closes #100134

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cbb83a4]

Summary: ✅


AI Review

Summary

This PR makes skip_unavailable_shards behavior consistent for local replicas with missing tables (when no remote replicas are configured), wires local and remote skip accounting through a shared UnavailableShardTracker, and adds coverage for both the skip path and skip-limit enforcement. I did not find blocker or major correctness/safety issues in the current diff.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 19, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov
alexey-milovidov marked this pull request as draft March 19, 2026 23:28
alexey-milovidov and others added 2 commits March 20, 2026 00:41
… shards are skipped

When `skip_unavailable_shards` causes all shards to be skipped (e.g., the
only shard has a missing table with no remote replicas), throw a proper
`ALL_CONNECTION_TRIES_FAILED` exception instead of `LOGICAL_ERROR: Pipeline
is not initialized`.

Update the test to expect this error for the single-shard case.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100141&sha=latest&name_0=PR

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…code path is tested

Without this, the test runner's randomized settings can set
`prefer_localhost_replica = 0`, causing the shard to be treated as remote
and producing `ALL_CONNECTION_TRIES_FAILED` instead of `UNKNOWN_TABLE`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review March 23, 2026 20:13
@alexey-milovidov
alexey-milovidov marked this pull request as draft March 23, 2026 20:15
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Hung check failure is fixed by #102008 and #102010, let's update the branch

alexey-milovidov and others added 10 commits April 12, 2026 13:31
…sing-table skip path

The new local-missing-table skip path in `SelectStreamFactory::createForShardImpl`
was skipping shards without going through `UnavailableShardTracker`, so
`max_skip_unavailable_shards_num` and `max_skip_unavailable_shards_ratio` were
not enforced for that path.

Move the tracker construction ahead of the per-shard loop in
`ClusterProxy::executeQuery` and pass it into `SelectStreamFactory::createForShard`,
which calls `onShardSkipped` when it drops a local shard with a missing table.
The same tracker continues to be moved into `ReadFromRemote` for remote shards,
so both skip paths share a single counter.

Extend `04050_skip_unavailable_shards_local_missing_table.sql` with a two-shard
case over `test_cluster_two_shards` that asserts `TOO_MANY_UNAVAILABLE_SHARDS`
when `max_skip_unavailable_shards_num=1` or `max_skip_unavailable_shards_ratio=0.4`
are exceeded.
…ter with two `localhost` shards

The two-shard scenarios used `test_cluster_two_shards`, which has shards
on `127.0.0.1` and `127.0.0.2`. ClickHouse intentionally treats
`127.0.0.{2..255}` as non-local (see `isLocalAddress.cpp`) so that those
addresses can be used to emulate distributed queries across localhost.
As a result the second shard was routed through the remote path, the
analyzer on the receiving side failed with `UNKNOWN_TABLE`, and the test
returned `UNKNOWN_TABLE` instead of the expected
`TOO_MANY_UNAVAILABLE_SHARDS`.

Use `test_cluster_two_shards_localhost`, which points both shards at
`localhost` so each shard is detected as local and the new
local-missing-table skip path runs for both.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Add an integration test where the local shard does not have the table, but another shard has. Check that skipping the local shard is done correctly, and we will read from the remote shard.

alexey-milovidov and others added 5 commits May 1, 2026 10:46
…e shard

Covers the scenario from the review on
#100141: a two-shard cluster
where the local shard has no underlying table and the remote shard has
the table populated. With `skip_unavailable_shards = 1` and
`prefer_localhost_replica = 1`, the local shard is skipped and the
query reads from the remote shard. Without the setting, the local shard
fails with `UNKNOWN_TABLE`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 96.15% (50/52) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 6, 2026
@alexey-milovidov alexey-milovidov self-assigned this May 6, 2026
Merged via the queue into master with commit 930f458 May 6, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-skip-local-missing-table branch May 6, 2026 16:02
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 6, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The upgrade test in CI installs a previous release binary, runs the test
suite, then upgrades to the new server build and restarts. Tables created
on the old binary with columns like `Nullable(Tuple(`null` UInt32))` fail
to attach on the new binary because PR ClickHouse#98377 forbade Tuple element name
`null` to avoid ambiguity with the Nullable null-map subcolumn name.

This is a known consequence of the backward-incompatible change, not a
regression introduced by any in-flight PR. Add the exact reserved-name
phrase to the upgrade-runner error filter so unrelated PRs no longer fail
the upgrade check on this message.

Observed on PR ClickHouse#100141: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100141&sha=ca91e01ef6f3c799bddb2176485608a8c9eaf151&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

Local replica or shard cannot be skipped in the case of missing table.

3 participants