Skip to content

Fix flaky test_move_after_processing_preserve_path - #117066

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-s3queue-move-after-processing
Aug 30, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-s3queue-move-after-processing

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

Fixes a rare flake of test_storage_s3_queue/test_0.py::test_move_after_processing_preserve_path, seen once in ~11950 master runs:

assert count_objects(started_cluster, dst_bucket, expected_key) == 1
AssertionError: assert 0 == 1
 +  where 0 = count_minio_objects(<ClickHouseCluster>, 'root',
                                  'sink/move_after_processing_preserve_S3Queue_kudmif_data/a.csv')

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=dcf60013dc275ac8a3c4c8187e83ff95d58efcdc&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29

StorageObjectStorageQueue::postProcess, which performs the after_processing = 'move' action, is called from StorageObjectStorageQueue::commit, and commit runs only after the rows have been inserted into the materialized view target table. So reaching the final row count does not imply the objects have been moved yet — there is a window in which the rows are already visible and the copy-then-delete is still in flight.

Both after_processing = 'move' tests waited for SELECT count() on the target table to reach its final value and then asserted on the object storage immediately, so a move still in that window was reported as a lost object. They now poll the object counts until they match instead of asserting once. test_move_after_processing was racy the same way; it only never failed because it happens to issue SYSTEM FLUSH LOGS and several system.*_log queries between the row-count wait and the object assertions, which usually hides the window.

The polling helper returns the counts it last observed, so a genuine failure still fails, with the observed counts in the assertion message rather than a bare 0 == 1.

Not fixed here, but worth noting: test_tag_after_processing has the same latent race — after_processing = 'tag' goes through the same postProcess — but it has 0 failures in ~12000 master runs, and its per-object tag assertions do not fit the count-based helper.

Changelog category (leave one):

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

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

Version info

  • Merged into: 26.9.1.362 (included in 26.9 and later)

`StorageObjectStorageQueue::postProcess`, which performs the
`after_processing = 'move'` action, is called from
`StorageObjectStorageQueue::commit` and therefore runs only *after* the rows
have been committed to the materialized view target table.

Both `after_processing = 'move'` tests waited for `SELECT count()` on the
target table to reach its final value and then asserted on the object storage
immediately. Reaching the final row count does not imply the objects have been
moved yet, so a move still in flight was reported as a lost object:

    assert count_objects(started_cluster, dst_bucket, expected_key) == 1
    AssertionError: assert 0 == 1
     +  where 0 = count_minio_objects(<ClickHouseCluster>, 'root',
                                      'sink/move_after_processing_preserve_S3Queue_kudmif_data/a.csv')

Poll the object counts until they match the expectation instead of asserting
on them once. `test_move_after_processing` was racy in the same way; it only
never failed because it happens to issue `SYSTEM FLUSH LOGS` and several
`system.*_log` queries between the row-count wait and the object assertions.

Observed once in ~11950 `master` runs of
`test_storage_s3_queue/test_0.py::test_move_after_processing_preserve_path[True-same_bucket-S3Queue]`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=dcf60013dc275ac8a3c4c8187e83ff95d58efcdc&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29

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

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [60a323d]

Summary: ✅


AI Review

Summary

This PR updates test_move_after_processing and test_move_after_processing_preserve_path to wait for object-storage state to converge after StorageObjectStorageQueue::postProcess runs asynchronously after the materialized view commit. I did not find a correctness or coverage regression in the current diff; the new helper preserves the existing assertions while removing the row-count-versus-move race described in the PR.

Missing context / blind spots
  • ⚠️ The Praktika matrix was still pending at review time, so I could not validate the change against a completed CI run. I only verified that the touched Python files parse locally with python3 -m py_compile.
Final Verdict

Status: ✅ Approve

No review findings in the current diff, so I did not post inline comments.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 29, 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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit 6f2305c Aug 30, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-s3queue-move-after-processing branch August 30, 2026 00:23
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 30, 2026
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Sep 4, 2026
`test_delete_after_processing`, `test_tag_after_processing` and `test_move_after_processing`
wait for the destination materialized view table to reach its final row count, then issue a
single `SYSTEM FLUSH LOGS` and assert on `system.s3queue_log` / `system.azure_queue_log`
and the corresponding metadata cache.

That is racy: `ObjectStorageQueueSource::appendLogElement` is called from `finalizeCommit`,
after the rows have already been committed to the materialized view target, so the log entry
may not have been queued yet when the flush happens, and the flush then flushes nothing.
The assertion then sees `0` instead of `files_num * row_num`.

Replace the one-shot flush and assert with `wait_for_queue_log_rows`, which flushes and polls
until the expected counts are reported, in the same shape as `wait_for_object_counts` added in
ClickHouse#117066 for the object-count race in the same tests.

Observed on ClickHouse#116992 in
`Integration tests (arm_binary, distributed plan, 4/4)`:
`test_move_after_processing[another_bucket-AzureQueue]` failed with
`assert 0 == (5 * 10)` on `SELECT sum(rows_processed) FROM system.azure_queue_log`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants