Skip to content

Fix inconsistent deduplication block cleanup ordering - #98293

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-dedup-cleanup-sort-order
Mar 2, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-dedup-cleanup-sort-order

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix sporadic test failure in 00953_zookeeper_suetin_deduplication_bug caused by inconsistent deduplication block cleanup ordering across blocks/ and deduplication_hashes/ ZooKeeper directories
  • With COMPATIBLE_DOUBLE_HASHES (default), each insert creates entries in both directories with different node names (SYNC hash vs UNIFIED/SipHash). The cleanup sort comparator used (ctime, node_name) as tiebreaker, which can produce different sort orders across directories when ctimes are equal, causing different logical inserts to be removed from each directory
  • Changed the sort tiebreaker from node name to czxid (ZooKeeper creation transaction ID), which is the same for entries created in the same multi-op, ensuring both directories remove entries for the same logical inserts

Closes #98123

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96351&sha=82aad167343abbf730a07809b553b3b029d62d52&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29
#96351

Test plan

  • Existing test 00953_zookeeper_suetin_deduplication_bug should pass consistently
  • Verify no regressions in other deduplication-related tests

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix sporadic deduplication failure where re-inserts were incorrectly deduplicated due to inconsistent cleanup ordering between blocks/ and deduplication_hashes/ ZooKeeper directories.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.277

With `COMPATIBLE_DOUBLE_HASHES` (the default `insert_deduplication_version`),
each insert creates entries in both `blocks/` and `deduplication_hashes/`
ZooKeeper directories with different node names (SYNC hash vs UNIFIED/SipHash).

The cleanup thread sorts blocks by `(ctime, node_name)` descending and removes
the oldest entries beyond the deduplication window. When multiple entries have
equal ctimes, the node name tiebreaker can produce different sort orders in
`blocks/` vs `deduplication_hashes/` because the hash algorithms yield different
names. This causes different logical inserts to be removed from each directory,
and the union of remaining entries can cover all original hashes, making all
re-inserts appear as duplicates.

Fix by using `czxid` (creation transaction ID) instead of node name as the sort
tiebreaker. Entries created in the same ZooKeeper multi-op (same logical insert)
share the same `czxid`, ensuring consistent ordering across both directories.

Closes #98123

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96351&sha=82aad167343abbf730a07809b553b3b029d62d52&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29

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

clickhouse-gh Bot commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [78fb5cc]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 28, 2026
alexey-milovidov and others added 4 commits February 28, 2026 03:51
…ctories

The test verifies that cleanup of `blocks/` and `deduplication_hashes/`
ZooKeeper directories removes entries for the same logical inserts.
Unlike the existing test `00953`, this test waits for cleanup of BOTH
directories before re-inserting, which catches the case where inconsistent
ordering causes different entries to be removed from each directory.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The style check requires `$CLICKHOUSE_TEST_ZOOKEEPER_PREFIX` or `{database}`
to appear directly in the `ReplicatedMergeTree(...)` constructor call.
Using an intermediate variable caused the check to fail.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix `04005_dedup_cleanup_consistent_across_directories`: add missing
  `/clickhouse/tables/` prefix to ZooKeeper path (was causing "ZooKeeper
  path must starts with '/'" errors in CI).

- Fix `00953_zookeeper_suetin_deduplication_bug`: wait for BOTH
  `blocks/` and `deduplication_hashes/` directories to be cleaned up,
  not just `blocks/`. With `COMPATIBLE_DOUBLE_HASHES` (default), each
  insert creates entries in both directories. The cleanup thread
  processes them sequentially, so an insert between the two cleanups
  can leave `deduplication_hashes/` with stale entries while `blocks/`
  is already cleaned, causing re-inserts to be incorrectly deduplicated.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@CheSema CheSema 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.

Thanks, I should have done this in my PR but it had not been triggered there, so I missed it.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 2, 2026
Merged via the queue into master with commit a592d01 Mar 2, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-dedup-cleanup-sort-order branch March 2, 2026 17:56
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

Flaky test: 00953_zookeeper_suetin_deduplication_bug

3 participants