Skip to content

Wait for Replicated database recovery on the replica digest instead of scanning text_log in two tests - #123816

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-recovery-tests-wait-on-replica-digest
Oct 6, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-recovery-tests-wait-on-replica-digest

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122917

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

05293_keeper_map_replica_recovery_keeps_data hit the 600 s timeout in Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel): report. The recovery took about 30 ms. The time went into the test's own wait: it counted All tables are created successfully in system.text_log three times, and each count is a full scan of the server-wide log, because the filter is not on the key. In that job the log had 12-14M rows on the s3 disk, and with the randomized read settings each scan took about 220 s. The same lane also had passing runs of 244 s and 198 s that day. 04651_timeseries_recover_lost_replica uses the same helper. It failed 5 times in 30 days in amd_tsan, flaky check with Test runs too long (> 180s) (example).

The change touches tests only. The last step of recoverLostReplica rewrites the replica's digest node, and both tests arm the recovery by setting that node to 42. The tests now wait until system.zookeeper shows that node is no longer 42, which is a small Keeper read per poll. 04651 keeps its three log-line checks but reads only the rows written since the test started (event_time >= <test start>).

Validation:

  • 50/50 randomized runs of each test, max about 5 s.
  • 3/3 runs with the failing job's settings plus async_insert=1.
  • With local reads throttled, the old tests time out and the new ones pass.
  • On the build before Keep KeeperMap data when a Replicated database replica recovers #122917, the old and new 05293 fail with the same diff.
  • When recovery is armed but never triggered, the wait runs out and prints recovered 0.

Workflow [PR]
Sync PR [sync-upstream/pr/123816]

Version info

  • Merged into: 26.10.1.1670-master (included in 26.10 and later)

05293_keeper_map_replica_recovery_keeps_data and 04651_timeseries_recover_lost_replica
detected the end of a forced Replicated database recovery by counting the line
"All tables are created successfully" in system.text_log. The filter is on
logger_name/message, not on the table key, so every count was a full scan of the
server-wide log: 3 per run in 05293, 7 in 04651. In Stateless tests (arm_binary,
AsyncInsert, s3 storage, parallel) on ClickHouse#123755 the log had 12-14M rows on the s3 disk
and, with the randomized read settings, each scan took about 220 s, so 05293 hit the
600 s timeout while the recovery itself had finished in about 30 ms. 04651 failed
8 times in 30 days in the amd_tsan flaky check with "Test runs too long".

DatabaseReplicated::recoverLostReplica rewrites the replica digest node as its last
step, and both tests arm the recovery by setting that node to 42 right before
DETACH/ATTACH DATABASE. Poll that node through system.zookeeper instead: one Keeper
read per poll, independent of the log size and of the storage. The signal is later
than the old log line, so the assertions that follow see at least as much finished
state. 04651 keeps its three log-line checks and bounds them to rows written since
the test started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (3 nits, no code findings).

# Sev Finding Verdict Evidence / action
1 💡 PR description overstated the 04651 history (8 flaky-check failures, all "too long") AGREE, fixed in the description CIDB 30 d: 5 rows are Test runs too long (> 180s); the other 3 come from a single flaky-check run of that PR (2 reference diffs, 1 timeout)
2 💡 "one Keeper read per poll" is imprecise AGREE, fixed in the description system.zookeeper with an exact path lists that node's children and reads each
3 💡 The wait loop now goes through Keeper, which CI fault-injects noted, no change 2e-5 per request, 1-2 polls per run

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-10:20261004-033400

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With local reads throttled (max_local_read_bandwidth=32768, runner --timeout 60), the old 05293 and 04651 time out every run inside a system.text_log count.
b Root cause explained? Each wait counted a log line with a full scan of the server-wide system.text_log (3 per run in 05293, 7 in 04651); with 12-14M rows on s3 and randomized read settings each scan took about 220 s, while the recovery took about 30 ms.
c Fix matches root cause? Yes. The wait polls the digest node that recoverLostReplica rewrites last; 05293 reads system.text_log 0 times, 04651 3 times bounded to its own run. No setting pinned, no tag added, no bound widened.
d Test intent preserved / new tests added? Yes. Assertions and both .reference files are unchanged; on the build before #122917 the old and new 05293 fail with the same diff.
e Both directions demonstrated? Yes. With throttled reads the old tests fail and the new ones pass. The new 05293 fails on the pre-fix build and passes on master.
f Fix is general across code paths? Yes. Both tests using the helper are fixed; the only other match for the log line is an integration test reading its own node log.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (only the wait changes). 50/50 randomized runs of each test pass, plus 3/3 with the failing job's settings and async_insert=1.
h Backward compatible? (maintainer-approved exception only) N/A (tests only).
i Invariants and contracts preserved? Yes. The digest is written only on a successful recovery, after the old log line; a missing node turns the recovered line into a stderr syntax error, and an untriggered recovery prints recovered 0.

Session id: cron:clickhouse-impl-slot-40:20261004-024800

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ce16473]

Summary: ✅


AI Review

Summary

This PR replaces the expensive system.text_log polling in two replicated-database recovery tests with a digest poll against system.zookeeper, which matches the recovery code path and should remove the timeout root cause. I found one remaining test-oracle issue in 04651: the new text_log time window starts before the start-of-test cleanup, so leftover logs from an earlier failed run on the same server can still leak into the assertions.

Findings
  • ⚠️ Majors
    • [tests/queries/0_stateless/04651_timeseries_recover_lost_replica.sh:109] TEST_START is captured before DROP DATABASE IF EXISTS ${DB}. If a previous failing run left test_rdb around, cleanup-time DatabaseCatalog retries or DatabaseReplicated recovery messages can still match the later event_time >= toDateTime(${TEST_START}) filters, so the text_log checks are not scoped to the current recovery attempt.
    • Suggested fix: move TEST_START to after the initial cleanup/CREATE DATABASE, or switch DB to a name derived from CLICKHOUSE_TEST_UNIQUE_NAME.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: scope the 04651 text_log window to after the initial cleanup so stale logs from a previous run cannot satisfy or fail the new oracles.

}

# The log checks read only this run's part of the server-wide text_log.
TEST_START=$(${CLICKHOUSE_CLIENT} -q "SELECT toUnixTimestamp(now())")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Starting TEST_START here still includes the initial DROP DATABASE IF EXISTS ${DB} cleanup window. If a previous failing run left test_rdb wedged, leftover DatabaseCatalog retries or DatabaseReplicated recovery messages written while that cleanup is tearing the old database down will satisfy the later event_time >= toDateTime(${TEST_START}) predicates, so the new log oracles are not actually scoped to the current recovery attempt. Please move TEST_START to after the initial cleanup/CREATE DATABASE, or make DB unique per run.

@PedroTadim
PedroTadim added this pull request to the merge queue Oct 6, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Good to merge!

Merged via the queue into ClickHouse:master with commit a071eef Oct 6, 2026
149 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 6, 2026
@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-ci 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