Skip to content

Fix flaky test_keeper_snapshot_chunked_transfer[remote_disk] - #102899

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-keeper-snapshot-chunked-transfer
May 2, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-keeper-snapshot-chunked-transfer

Conversation

@groeneai

@groeneai groeneai commented Apr 16, 2026 •

Copy link
Copy Markdown
Collaborator

The test_recover_after_interrupted_transfer[remote_disk] integration test has been chronically flaky (20+ PRs affected, 6 master failures in 30 days — issues #102040, #101969). PR #102643 added a sync() call but failures continued (master failure on 2026-04-15 on commit 118bba8 which is ahead of the fix).

Root cause

After the node restarts, Keeper may create new local snapshots asynchronously — serializeSnapshotToDisk is queued via snapshots_queue and runs in a background thread. During the write, a tmp_snapshot_* marker file is created temporarily (removed once the snapshot is fully written to disk).

The S3 assertion checked for all tmp_snapshot_* objects immediately after sync(). If a background snapshot flush happened to be in progress, its transient marker was caught as a false positive.

The local_disk variant was never flaky because it checks the specific tmp file path from the interrupted transfer, ignoring any new markers from background operations.

Fix

  1. Record the specific tmp_snapshot_* file names left by the interrupted transfer (before restart)
  2. After restart + sync(), poll for those specific files to disappear (15 s timeout) instead of asserting immediately against all tmp_snapshot_* objects
  3. New transient markers from background snapshot flushes are correctly ignored

The test still verifies the core behavior: interrupted transfer tmp files must be cleaned up on startup. The 15 s timeout ensures genuine cleanup failures are still caught.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.251

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii — could you review this? This fixes the remaining flakiness in your test_keeper_snapshot_chunked_transfer test after #102643. The root cause is that the S3 assertion checked for all tmp_snapshot files (catching transient markers from background snapshot flushes), while the local_disk variant correctly checked only the specific interrupted file.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation (Session cron:clickhouse-ci-task-worker:20260416-161500)

a) Deterministic repro: Race condition in CI — after Keeper restart, background snapshot flushes (serializeSnapshotToDisk via snapshots_queue) temporarily create tmp_snapshot_* markers. The immediate S3 assertion catches these transient markers. Confirmed by: (1) CIDB shows failures exclusively on remote_disk variant, never local_disk; (2) local_disk checks specific file path while remote_disk checked all tmp_snapshot_* — this asymmetry is the root cause.

b) Root cause causal chain: serializeSnapshotToDisk() creates a tmp_<name> marker → writes snapshot data → removes marker. This runs in a background thread. If the test's list_objects(prefix="tmp_snapshot_") executes during this brief window, it finds the transient marker → assertion fails. The local_disk variant avoids this because test -f <specific_path> only checks the interrupted transfer's file, not all tmp files.

c) Fix matches root cause: Yes — narrows the S3 assertion to check only the specific interrupted transfer's tmp files (matching local_disk behavior) and adds a poll to handle the brief window where a same-index marker from a new transfer exists.

d) Test intent preserved: Yes — still verifies interrupted transfer tmp files are cleaned up. 15 s timeout catches genuine cleanup failures.

e) Both directions: This is a CI race condition. The fix is logically proven: narrowing the assertion scope removes the false-positive path while preserving the true-positive detection.

f) Fix is general: The asymmetry between remote_disk (all tmp files) and local_disk (specific file) is the root cause. The fix aligns both variants to check specific files, eliminating the class of false positives.

@kssenii kssenii self-assigned this Apr 16, 2026
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7880ce7]

Summary: ✅


AI Review

Summary

This PR updates test_recover_after_interrupted_transfer[remote_disk] to track and wait for cleanup of the specific interrupted tmp_snapshot_* S3 objects, instead of asserting that all temporary snapshot markers are gone immediately after restart. The change is narrowly scoped to test flakiness mitigation and looks correct for the stated race with asynchronous background snapshot flushes.

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-not-for-changelog This PR should not be mentioned in the changelog label Apr 16, 2026
…ssertion

The test_recover_after_interrupted_transfer[remote_disk] test was flaky
because it asserted that *all* tmp_snapshot_* files are absent from S3
immediately after restart + sync.  After restart, Keeper may create
new local snapshots asynchronously (queued via snapshots_queue), which
temporarily produce fresh tmp_ markers during serializeSnapshotToDisk.
The immediate assertion catches these transient markers as false positives.

The local_disk variant was never flaky because it checks the specific
tmp file path from the interrupted transfer, ignoring any new markers.

Fix: record the specific tmp file names left by the interrupted transfer,
then poll for those specific files to disappear (15 s timeout) instead of
asserting immediately against all tmp_snapshot_* objects.  New transient
markers from background snapshot flushes are correctly ignored.
@groeneai

groeneai commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kssenii — could you take a look? This has been waiting for review since 2026-04-16 (16 days).

Status update (2026-05-02):

Recap of the fix:

After stop_clickhouse(kill=True) mid-transfer, the assertion checks that the leaked tmp_snapshot_* objects in S3 are cleaned up on restart. The previous assertion compared the entire tmp_snapshot_* prefix listing. The problem: after the lagging node restarts, KeeperStateMachine flushes new local snapshots via snapshots_queue (serializeSnapshotToDisk), which transiently produces fresh tmp_snapshot_* markers in S3 with the same/different log indices. These new markers are completely benign but they cause the assertion to fire intermittently.

The fix: snapshot the set of interrupted-transfer tmp filenames at kill time, then poll (15 s) for those specific objects to disappear. Background flushes are ignored.

This explains why only [remote_disk] was flaky — the local-disk variant already checks one specific path, not a prefix.

CIDB shows the assertion-flake is still active across ~30 unrelated PRs in 30 days and 6 master runs. Two open issues track it: #102040, #101969.

Thanks!

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks reasonable.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 2, 2026
Merged via the queue into ClickHouse:master with commit e264fe0 May 2, 2026
165 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 May 2, 2026
pull Bot pushed a commit to TCeason/ClickHouse that referenced this pull request May 8, 2026
…st_recover_after_interrupted_transfer

The test interrupts a chunked snapshot transfer mid-stream, kills the node,
restarts it, and asserts that startup cleanup removes the `tmp_snapshot_<idx>.bin.zstd`
markers left behind by the interrupted transfer.

The polling loop introduced in PR ClickHouse#102899 records `object_name` of the
interrupted markers before the kill and re-checks the listing after the restart.
This is too loose: when the leader resends a snapshot for the same `log_idx`
(common after a kill+restart while no new entries were committed), the new
`beginSnapshotReceiveToDisk` call creates a fresh `tmp_snapshot_<same_idx>.bin.zstd`.
That new in-flight marker has the *same* `object_name` as the original interrupted
marker, so the polling filter mistakes it for the original. The 15-second
deadline expires while the new transfer is still in progress and the test fails
even though the C++ startup cleanup correctly removed the original file.

Match on `(object_name, last_modified)` instead. MinIO returns last_modified
with microsecond precision; the original interrupted marker (created before
the kill) and any new in-flight marker (created after the restart) always have
different timestamps. Genuine cleanup regressions still fail the assertion
because the original file's tuple is unchanged.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100146&sha=60fad4c4a87adad7da97b1b7249acf9d6370d4ff&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29
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-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants