Repository navigation
Fix two distributed_index_analysis tests on an unavailable replica - #112879
PedroTadim merged 2 commits into
Conversation
03622_distributed_index_analysis_applies_skip_indexes and 03622_distributed_index_analysis_additional_table_filters both fail whenever 127.0.0.2:9000, the second replica of test_cluster_one_shard_two_replicas, is unreachable. One cause produces two divergences. First, DistributedIndexAnalyzer::establishConnectionsSync logs the connect failure at LogsLevel::warning (distributedIndexAnalysis.cpp:456). The stateless runner passes --send_logs_level=warning for every .sql test (tests/clickhouse-test:3603, default at :6646), so the record reaches the client's stderr, and any non-empty stderr fails the test (:1300). The observed runner verdict is "having stderror:", not a timeout. Second, DistributedIndexAnalyzer::run pre-sizes its result vector to the full remote-replica count and fills the address only for replicas that connected (distributedIndexAnalysis.cpp:307-309), so the dead replica's entry keeps a default-constructed address with zero counters. selectRangesToRead emits it unconditionally (ReadFromMergeTree.cpp:2958-2977) and describeIndexes prints it (:4845-4855), while the local replica absorbs the remaining parts. Both tests pin the healthy two-replica split in their .reference, so they also diverge on stdout. This means suppressing the warning alone is not sufficient: it only moves the failure to a result diff. The empty-address entry is correct behaviour and is already the pinned expectation of 03622_explain_indexes_distributed_index_analysis.reference for the unreachable replica of the parallel_replicas cluster, so this change is test-only and touches no source file. Each test now sets send_logs_level='error', matching 17 of the 22 stateless tests that enable distributed_index_analysis, and asserts the plan through select * from (explain indexes=1 ...) where explain not like '%Address:%' and ..., which drops only the per-replica rows. The aggregate Parts:/Granules: on the PrimaryKey entry survive; those are populated from received_parts and received_granules (ReadFromMergeTree.cpp:2979-2993), so the tests still prove the skip index was applied on the replicas. Forcing distributed index analysis off makes them read 100/100 and the tests fail, so the assertion did not become a tautology. Three further tests in the family lack the same guard but pin no per-replica rows, so they are latent rather than failing and are left to a separate change.
The previous commit made these two tests tolerate an unavailable 127.0.0.2 by filtering the per-replica rows out of the `EXPLAIN` output. That filter also removed the only observable that distinguished "the remote replica analyzed its own parts" from "the remote replica silently fell back to the initiator": on that fallback path `DistributedIndexAnalyzer` catches the failure, increments `DistributedIndexAnalysisReplicaFallback` and logs only at `LogsLevel::warning`, which the tests now suppress; `resolveMissingParts` then re-analyzes those parts locally, so the aggregate `Parts:` and `Granules:` counters are unchanged and the test would have passed. Add a `system.query_log` assertion on three profile events that are independent of replica availability, so it reads identically whether or not 127.0.0.2 is up: DistributedIndexAnalysisMicroseconds > 0 DistributedIndexAnalysisReplicaFallback = 0 DistributedIndexAnalysisMissingParts = 0 `DistributedIndexAnalysisReplicaFallback` and `DistributedIndexAnalysisMissingParts` are incremented only once a replica has connected and its analysis then failed, which is exactly the case that must not pass silently. `DistributedIndexAnalysisScheduledReplicas` and `DistributedIndexAnalysisReplicaUnavailable` are deliberately not asserted: both vary with replica availability and would reintroduce the flakiness these tests exist to avoid. Verified by forcing the remote analysis to fail while both replicas are up: both tests go red on the new assertion alone, on the synchronous and the asynchronous reader path, while the filtered plan output stays identical. Also wrap the literal log message excerpt and the literal setting name in the new comments in inline code blocks.
Internal second-model review (2 rounds, 6 findings, 4 agreed and fixed, 0 disagreed)Before opening this PR I ran two independent review rounds against the diff: a cold code review
Validation is summarised in the description. Beyond that: five mutations, each reddening the |
Pre-PR validation gate (click to expand)
Additional validation: five mutations each redden the tests. Four are test-side (reverting the log-level guard; reverting the subquery filter; forcing distributed index analysis off; deleting the Session id: cron:clickhouse-review-slot-11:20260801-061400 |
|
cc @azat, could you review this? Two stateless tests pinned the per-replica |
|
Workflow [PR], commit [b9db69d] Summary: ✅ AI ReviewSummaryThis PR makes two Final Verdict✅ No findings. |
…s tests
On the MSan lane these four tests intermittently die while connecting to a
127.0.0.x:9000 loopback peer:
Code: 209. DB::NetException: Timeout exceeded while reading from socket
(peer: 127.0.0.2:9000, local: 127.0.0.1:NNNNN, 10000 ms) ... (SOCKET_TIMEOUT)
10000 ms is the default handshake_timeout_ms. Connection::connect installs it as
the socket receive and send timeout for the Hello exchange only, restoring the
regular timeouts once the handshake completes, so under sanitizer instrumentation
plus 2-way-sharded host load the peer answers Hello late and the query dies before
any data moves (the CI rows show "Wrote 0 blocks and 0 rows" on the slow shard).
The timeouts are an argument of each pool get() call and are not part of the pool
or cluster identity, which is why a query-time value is effective even for the
materialized-view carrier, whose pools were created by an earlier CREATE TABLE.
Pin 60000 per test, following d4fed63, which fixed the sibling
00563_shard_insert_into_remote the same way. The shell test takes it as a client
option on its single client invocation. Unlike a no-msan/no-tsan tag this deletes
no sanitizer coverage, and it still applies in the stress jobs, where no-<build>
tags are ignored by design.
This raises the initiator's patience from 10 s; the receiver's own 30 s
handshake_timeout_milliseconds server setting still bounds the exchange, and is
left alone. It has fired once in 365 days of public CI, on an unrelated test.
Validated by putting a 12 s delay in front of the loopback peer, which makes all
four fail on demand with the signature above and pass with the pin, on the same
peer and binary. A 2000 ms and 3000 ms calibration shows the printed budget
tracking the in-file value, so the value is measured to reach the failing socket
rather than assumed to. 80 deterministic and 200 randomized runs green.
464 stateless files reference remote('127.0.0. or cluster('test_, and exactly one
pinned this setting before this change. The pin goes only where a failure was
observed, so the signal that would catch a real handshake regression stays.
Two neighbours are deliberately excluded:
03622_distributed_index_analysis_applies_skip_indexes, whose single sighting was a
swallowed warning rather than a query failure and whose oracle ClickHouse#112879 has since
made availability-independent, and 01600_benchmark_query, already fixed by
7ec04d1.
Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
03622_distributed_index_analysis_applies_skip_indexesand03622_distributed_index_analysis_additional_table_filtersboth fail whenever127.0.0.2:9000,the second replica of
test_cluster_one_shard_two_replicas, is unreachable.The server warns that the replica dropped out at
LogsLevel::warning, the stateless runner ships--send_logs_level=warningfor every.sqltest, and any non-empty stderr fails the test.Separately,
DistributedIndexAnalyzer::runfills the result address only for replicas thatconnected, so the dead replica's entry keeps an empty address with zero counters while the local
replica absorbs its parts. Both tests pin the healthy two-replica split, so they also fail on
stdout.
The empty-address entry is correct behaviour and is already a pinned expectation elsewhere in this
family, so this change is test-only.
Each test now sets
send_logs_level='error'(as most tests in the family already do) andasserts the plan through
select * from (explain indexes=1 ...) where explain not like '%Address:%' and ..., which dropsonly the per-replica rows, leaving the aggregate
Parts:/Granules:on thePrimaryKeyentry.Because the plan no longer names the replica that answered, each test also asserts from
system.query_logthatDistributedIndexAnalysisReplicaFallbackandDistributedIndexAnalysisMissingPartsare zero. Bothare incremented only after a replica connects, so they are unaffected by its availability and still
fail if the remote analysis silently falls back to the initiator.
Validated by binding a server to
127.0.0.1only so the second replica genuinely refuses: bothtests fail before the change and pass after it, in that arm and with both replicas up. Mutations
redden them, including forcing distributed index analysis off and forcing the remote analysis to
throw while the replica is up, so no assertion became a tautology. 50 randomized runs per test per
arm pass, and a 22-test sweep over the family shows no regressions.
Four more tests carry half of the same latent exposure; they are tracked separately.
Related: #111492