Skip to content

Fix MarkCache entries never evicted after a part is moved or detached - #107302

Closed
murphy-4o wants to merge 1 commit into
ClickHouse:masterfrom
murphy-4o:markcache-evict-key-fix
Closed

murphy-4o wants to merge 1 commit into
ClickHouse:masterfrom
murphy-4o:markcache-evict-key-fix

Conversation

@murphy-4o

@murphy-4o murphy-4o commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

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 to CHANGELOG.md):

Fix a rare Number of marks N is not divisible by number of columns in mark M logical error caused by the mark cache serving a stale entry after a part was moved between disks or detached.


The mark-cache insert key (MergeTreeMarksLoader) used getFullPath(), while eviction (removeMarksFromCache) uses getRelativePathOfActivePart(). getFullPath() changes when a part is moved between disks or detached, so the keys diverge and the entry is never freed on removal; a later part reusing the directory can then be served stale, wrong-shaped marks and trip the divisibility check in MergeTreeMarksGetter.

Fix: key the insert on the active-part path so it matches eviction. Same fix as de320f18af0 (index caches).

The MarkCache insertion key in MergeTreeMarksLoader::loadMarksSync /
loadMarksAsync was built from IDataPartStorage::getFullPath(), while eviction
in IMergeTreeDataPart::removeMarksFromCache() builds it from
getRelativePathOfActivePart(). getFullPath() changes when a part is moved
between disks or detached, so the two keys diverge and the inserted entry is
never freed on part removal.

A later part reusing the same on-disk directory can then be served the stale
marks of a differently-shaped part, which trips the
"Number of marks N is not divisible by number of columns in mark M"
LOGICAL_ERROR in the MergeTreeMarksGetter constructor (most easily hit via
prewarm-on-fetch, which eagerly loads marks for every freshly downloaded part).

Use the active-part path for the insertion key so it matches eviction. This is
the same class of bug fixed for the primary-index and vector-similarity index
caches in de320f1.

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

clickhouse-gh Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5d8c7b6]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) FAIL
Logical error: Mutation of Memory table produced incomplete output: A (STID: 2380-2e8c) FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL

AI Review

Summary

This PR changes MergeTreeMarksLoader so MarkCache insertion uses the same active-part key shape as removeMarksFromCache eviction. The code change is consistent with the existing wide/compact mark eviction paths, and the PR metadata matches the actual Bug Fix, but I am requesting changes because the bug fix currently has no focused regression evidence.

Tests
  • ⚠️ [src/Storages/MergeTree/MergeTreeMarksLoader.cpp:250] This cache-key invariant is the whole bug fix, but the PR adds no test that would fail if insertion went back to getFullPath while eviction stayed on getRelativePathOfActivePart. Please add a focused stateless/integration test, or a small unit test around key construction, that loads marks for the move/detach or prewarm-on-fetch lifecycle and proves stale MarkCache entries are not served.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: add regression coverage for the MarkCache insertion/eviction key match across the lifecycle described in the PR.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 12, 2026
/// columns M" check in MergeTreeMarksGetter. Same class of bug as the index caches (de320f18af0).
auto key = MarkCache::hash(
data_part_storage->getDiskName() + ":"
+ (fs::path(data_part_storage->getFullRootPath()) / data_part_reader->getPartName() / mrk_path).string());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because this PR is a Bug Fix, the cache-key invariant needs regression coverage. The current change has no test that loads marks for a part whose storage path differs from its eventual active path and then verifies removeMarksFromCache evicts the inserted MarkCache key; changing either side of the key back to getFullPath would still pass. Please add a focused stateless/integration test, or a small unit test around key construction, that reproduces the stale MarkCache entry across move/detach or prewarm-on-fetch and proves stale marks are not served.

@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.40% +0.10%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 11/11 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@murphy-4o
murphy-4o marked this pull request as ready for review June 13, 2026 01:21
@abashkeev abashkeev added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@murphy-4o murphy-4o closed this Sep 23, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants