Skip to content

Harden 01396_inactive_replica_cleanup_nodes_zookeeper to surface poll errors - #108213

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:harden-01396-surface-zookeeper-poll-errors
Jul 29, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:harden-01396-surface-zookeeper-poll-errors

Conversation

@groeneai

@groeneai groeneai commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

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

Follow-up to #107062 (which stabilized the flaky 01396_inactive_replica_cleanup_nodes_zookeeper), per the two-step plan on that PR: step 1 merged the stabilization, this PR hardens the test.

#107062 made the cleanup-wait loop require numChildren to be a non-empty integer before comparing, because a transient empty read had let [[ "" -lt N ]] break the loop early. That fixed the flake but still discarded the underlying read error via 2>/dev/null.

Why the read can be empty (the question raised on #107062): StorageSystemZooKeeper serves the poll via tryGetChildren on the table root, tryGet per child for its stat, then the name = 'log' predicate. Its only errorless zero-row paths are root-ZNONODE or /log-ZNONODE, and both are permanent ReplicatedMergeTree nodes for the whole test lifetime. A successful query therefore always returns one numeric row, so an empty count is a suppressed transient error (a Keeper/client hiccup under the heavy single-row INSERT load), not an empty result.

This captures the poll's stderr per iteration and reports the last count and last error only when the final assertion also fails. clickhouse-test fails a .sh test on any non-empty stderr, so the diagnostic has to be gated on the assertion rather than on the loop's deadline: the loop is a wait, the assertion is the check. A run whose cleanup converges only after the deadline, or whose last poll errored but recovered, still passes; a genuinely untrimmed log or a persistent read error now fails with the underlying error exposed instead of a silent wrong count.

The assertion result is captured to drive that decision and echoed from the variable, guarded so nothing is printed if that query itself failed. A stubbed-client A/B over the real script shows stdout byte-identical to a direct run in all five scenarios. The temp file is keyed on CLICKHOUSE_TEST_UNIQUE_NAME and removed on every path, so the test stays parallel-safe.

…rrors

Follow-up to ClickHouse#107062, which made the cleanup-wait loop require numChildren
to be a non-empty integer before comparing (a transient empty read had let
[[ "" -lt N ]] break the loop early). That stabilized the test but still
discarded the underlying read error via 2>/dev/null.

The numChildren poll is served by StorageSystemZooKeeper: tryGetChildren on
the table root, tryGet on each child for its stat, then the name='log'
predicate. The only errorless zero-row paths are root-ZNONODE or /log-ZNONODE,
but both are permanent structural ReplicatedMergeTree nodes for the whole test
(DROP only at the end). So a successful query always returns exactly one
numeric row, and an empty count is a suppressed transient error (a Keeper/client
hiccup under the heavy single-row INSERT load), not an empty result.

Capture the poll's stderr per iteration and, if the loop never converges,
print the last error and last count to stderr so the real failure is
diagnosable. clickhouse-test fails a .sh test on any non-empty stderr, so a
healthy run stays byte-identical and silent; only a genuinely stuck wait now
fails with the underlying error exposed instead of a silent wrong count.
The temp file uses CLICKHOUSE_TEST_UNIQUE_NAME so the test stays parallel-safe.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? N/A (test-hardening, not a bug fix). This is the step-2 follow-up to merged #107062 per the maintainer two-step plan. The underlying flake (silent empty read) was already root-caused and fixed in #107062; this PR makes a future stuck-wait diagnosable.
b Root cause explained? Yes. The numChildren poll is served by StorageSystemZooKeeper; a successful query always returns exactly one numeric row (root and /log are permanent ReplicatedMergeTree nodes for the test lifetime), so an empty count is a suppressed transient Keeper/client error under the heavy single-row INSERT load, swallowed by 2>/dev/null.
c Fix matches root cause? Yes. Instead of discarding the read error, it is captured per poll and surfaced (with the last count) only if the wait never converges. This directly exposes the error that #107062 had to guard against.
d Test intent preserved / new tests added? Yes, strengthened. The existing assertions and reference are unchanged; on a healthy run the test is byte-identical and silent. The change only adds a diagnostic on non-convergence, so the test still verifies the same cleanup invariant and now fails loudly with the real error.
e Both directions demonstrated? Control flow validated in isolation: converged run emits zero stderr (passes unchanged); a never-converging run with a transient error surfaces it to stderr (clickhouse-test fails a .sh test on any non-empty stderr); a stuck high-count run reports the last count. Note: 01396 is no-debug/no-asan and needs a release binary, so full validation is via CI, same as #107062.
f Fix is general, not a narrow patch? Yes. This is the only poll loop in the test that suppressed errors; the final assertions already surface their errors (no 2>/dev/null). No sibling suppression remains.

Session id: cron:clickhouse-worker-slot-3:20260622-185100

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f2965f0]

Summary: ✅


AI Review

Summary

This PR hardens 01396_inactive_replica_cleanup_nodes_zookeeper.sh so the wait loop preserves the last poll error but only emits the diagnostic when the final cleanup assertion also fails. In the current revision, that fixes the earlier false-failure regression from unconditional stderr while keeping the test contract unchanged. I did not find a new correctness or reliability issue in the remaining diff.

Final Verdict

✅ No new findings in the current revision.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 478 line(s), 36 function(s) across 148 file(s) · Details

Top files
  • src/Common/Scheduler/Workload/WorkloadEntityStorageBase.cpp: 104 line(s), 7 function(s)
  • src/Common/Scheduler/Workload/WorkloadEntityKeeperStorage.cpp: 29 line(s), 1 function(s)
  • src/Storages/WindowView/StorageWindowView.cpp: 22 line(s), 1 function(s)
  • src/Common/Scheduler/Nodes/WorkloadResourceManager.cpp: 12 line(s), 2 function(s)
  • src/Dictionaries/RegExpTreeDictionary.h: 9 line(s), 7 function(s)

Full report

The hardening added in this PR printed the wait diagnostic whenever the
120-iteration poll loop hit its deadline. clickhouse-test fails a .sh test
on any stderr output, so that moved the pass condition from the assertion
to the loop's timing: a slow-but-correct run whose assertion still returns
1 was failed because the message had already been printed.

Gate the diagnostic on the assertion result instead. The loop stays a wait;
the assertion stays the check. A transient poll error that recovers, or a
cleanup that only converges after the deadline, no longer fails the test,
while a genuinely untrimmed log or a persistent read error still surfaces
the last count and the last poll error.

The assertion result is captured to drive that decision, so it is echoed
from the variable. It is empty only when the assertion query itself failed,
in which case nothing is echoed, keeping stdout byte-identical to a direct
run in every scenario.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

groeneai commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f2965f0

CI fully finished on this head (no check queued or in progress, the praktika aggregator
completed, and the CIDB ingestion buffer has elapsed). Zero failing checks on this head,
so there is nothing to own.

Session id: cron:our-pr-ci-monitor:20260729-093000

@alexey-milovidov alexey-milovidov self-assigned this Jul 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 29, 2026
Merged via the queue into ClickHouse:master with commit 4e300ae Jul 29, 2026
179 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 29, 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 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.

4 participants