Skip to content

Make 05315_plain_rewritable_part_removal_without_copies independent of where parts are removed - #123637

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-flaky-05315-plain-rewritable-part-removal
Oct 6, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-flaky-05315-plain-rewritable-part-removal

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

05315_plain_rewritable_part_removal_without_copies fails sometimes in the private CI: the TRUNCATE query has no DiskS3DeleteObjects, so the test decides the parts were not removed.

The test needed TRUNCATE to remove the truncated parts itself, and it read the profile events of that query. But removing the parts at the end of TRUNCATE is best-effort. MergeTreeData::grabOldParts skips all of them when another thread holds grab_old_parts_mutex, or when a part is still referenced somewhere else. The background cleanup then removes them later, outside the query.

With this change the test creates a plain_rewritable disk of its own, both plain and wrapped in cache and encryption. It waits until the truncated parts are gone, no matter which thread removed them. Then it checks the Copy and Delete events of that disk in system.blob_storage_log since TRUNCATE started. These events do not belong to a query, so removal by the background cleanup is covered too. Events before TRUNCATE are ignored: inserting a part also unlinks a few files outside parts, and DROP TABLE unlinks format_version.txt, and both make copies.

I checked it locally in the CI Docker environment. On a binary with the fix from #123303 reverted, the test fails with 6 copies per table. With the fix, it passed 100 runs out of 100.

Related: https://github.com/ClickHouse/clickhouse-private/issues/79034
Related: #123303

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):

...

🤖 Generated with Claude Code


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

Version info

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

… of where parts are removed

The test asserted that `TRUNCATE` itself removes the truncated parts and checked
`DiskS3CopyObject`/`DiskS3DeleteObjects` of that query. Removal at the end of `TRUNCATE` is
best-effort: `MergeTreeData::grabOldParts` skips everything when another thread holds
`grab_old_parts_mutex` or a part is still referenced elsewhere, and then the parts are removed
later by the background cleanup, so the test was flaky in the private CI.

Now the test uses a `plain_rewritable` disk of its own, waits until the truncated parts are gone
regardless of which thread removed them, and checks the `Copy` and `Delete` events of that disk in
`system.blob_storage_log` since `TRUNCATE` started. The events are not tied to a query, so the
check holds for the background cleanup as well.

Related: ClickHouse/clickhouse-private#79034

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2e01126]

Summary: ✅


AI Review

Summary

This PR rewrites 05315_plain_rewritable_part_removal_without_copies as a shell test that waits for background cleanup and then inspects system.blob_storage_log instead of query_log, which is the right direction for the original flake. I’m requesting changes because the new log query is not scoped tightly enough to the current TRUNCATE: it can accept a later Delete on the reused test disk, including a failed delete, as proof that this run removed its own parts.

Findings
  • ⚠️ Majors
    • [tests/queries/0_stateless/05315_plain_rewritable_part_removal_without_copies.sh:60] The success condition is countIf(event_type = 'Delete') > 0 over every row on a stable disk_name since truncate_time. That means a late delete from the opening DROP TABLE IF EXISTS or an earlier run on the same S3 prefix can satisfy removed = 1, and a failed delete is also counted because system.blob_storage_log records Delete rows with non-zero error_code. In both cases the test can pass even if the current TRUNCATE never deletes its own blobs.
    • Suggested fix: scope the rows to the current table's local_path / remote_path (for example via the current table UUID or system.remote_data_paths) and require error_code = 0 for the delete check.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required: tie the blob_storage_log query to the current table's objects and count only successful Delete rows.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123637&sha=1e6ef2736b394f70d5a38b8b993af187d859215d&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 (04891_distributed_plan_limit_early_stop: local exchanges: MISMATCH missing=['exchange_0__2_2']; it also fails on master several times in 2026-09/2026-10, unrelated to this test-only PR) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

This is already fixed by #122453 (mine, merged 2026-10-04 00:08 UTC). The failing run was on 1e6ef27, which does not contain it; your master merge 89e1b87 does.

missing=['exchange_0__2_2'] is the race it fixes: SourceFromInMemoryExchange::prepare read its output port once to decide the detach, then ISource::prepare read it again. A concurrent InputPort::close between the two reads finished the source without detachReader, so that one stream never saw the LIMIT stop.

Since 01:00 UTC today, CIDB has 0 failures of 04891_distributed_plan_limit_early_stop in any check: 2417 OK runs, 402 of them on master across 44 commits and 356 on arm_asan_ubsan.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, thanks, confirmed: the master merge includes #122453, and 04891_distributed_plan_limit_early_stop did not fail on 89e1b87.

The only red job on 89e1b87 is Stateless tests (arm_asan_ubsan, azure, sequential). It stopped at the job timeout (9000 s) after test 1153 of 1164, and every test before that passed. 05315_plain_rewritable_part_removal_without_copies does not run in that job. This is unrelated to this test-only PR, and #123849 (splitting that job into 2 batches) is already open for it. I merged master again to start a fresh CI run.

@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 Oct 6, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 6, 2026
Merged via the queue into master with commit 34afd80 Oct 6, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-flaky-05315-plain-rewritable-part-removal branch October 6, 2026 09:54
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 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-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... 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

comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... 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