Skip to content

add tsa annotation to column sizes and indexes around lazy evaluation - #99240

Merged
Diskein merged 7 commits into
masterfrom
dk-merge-tree-data-tsa-lazy-indexes
Mar 24, 2026
Merged

Diskein merged 7 commits into
masterfrom
dk-merge-tree-data-tsa-lazy-indexes

Conversation

@Diskein

@Diskein Diskein commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

The problem that lazy evaluation of indexes sizes might lead to data races and it should be carefully used, so I think it's mandatory to have TSA annotations here to prevent problems with that laziness.

There is one problem still though, even after this PR code relies on the fact that checksums are preloaded before part could be accessed from any thread. AFAIU this is true now, until we have lazy checksum preload.

Another change with this PR which could lead to side-effects that columns sizes are copied now instead of passing by reference - if the map is very big could be performance penalty for copying that.

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)

Note

Medium Risk
Touches MergeTree part size caching and locking semantics; incorrect locking or pointer lifetime could affect concurrent reads and size-based heuristics, and the new MultiVersion indirection may have minor performance implications.

Overview
Improves thread-safety around lazy on-disk size calculation for MergeTree parts by adding TSA annotations, switching callers to UniqueLock, and splitting calculation into a mutex-held calculateColumnsAndSecondaryIndicesSizesOnDiskUnlocked() helper.

Changes the column-size cache from an in-place map to MultiVersion<ColumnSizeByName> and updates getColumnSizes() to return a shared pointer snapshot, updating read-path users (MergeTreeReadPoolBase, MergeTreeReadTask) to dereference the returned pointer. This avoids exposing mutable references while allowing lock release before iterating sizes.

Written by Cursor Bugbot for commit 64f890b. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.4.1.195

@clickhouse-gh

clickhouse-gh Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4369345]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) failure
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb IGNORED
BuzzHouse (amd_tsan) failure
Logical error: 'have_no_tasks_info || queue_nodes.end() == std::find_if(queue_nodes.begin(), queue_nodes.end(), [&](const String & entry_name) { String reason; auto task = initAndCheckTask(entry_name, reason, zookeeper, true); bool maybe_currently_processing = current_tasks.end() != std::find_if(current_tasks.begin(), current_tasks.end(), [&](const auto & t) { return t->entry_name == entry_name; }); if (begin_node == queue_nodes.end() || entry_name < *begin_node) { bool maybe_concurrently_deleting = task && !zookeeper->exists(fs::path(task->entry_path) / "active"); return task && !maybe_concurrently_deleting && !maybe_currently_processing; } if (last_skipped_entry_name.has_value() && !queue_fully_loaded_after_initialization_debug_helper) { return false; } bool processed = !task && reason == TASK_PROCESSED_OUT_REASON; return processed || maybe_currently_processing; })' (STID: 2508-2795) FAIL cidb, issue ISSUE EXISTS

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 11, 2026
@alesapin alesapin self-assigned this Mar 11, 2026

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

Good change, the only thing -- maybe we can use MultiVersion to avoid copies?

@Diskein

Diskein commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

Good change, the only thing -- maybe we can use MultiVersion to avoid copies?

I've tried, but it looks heavy and kinda brings in this "atomic" semantic which is redundant since we have to hold mutex, so you are starting doing unlocks and etc.

I think that more natural choice it's just a shared_ptr for columns sizes, since we have to lock the mutex for "lazy calculation" anyway for indexes sizes. This approach is pretty straightforward as well. (less LOC also, but who cares nowadays).

@Diskein
Diskein requested a review from alesapin March 13, 2026 16:11
@clickhouse-gh

clickhouse-gh Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 90.53% (86/95, 2 noise lines excluded)
Diff coverage report
Uncovered code

@Diskein
Diskein enabled auto-merge March 24, 2026 11:41
@Diskein
Diskein disabled auto-merge March 24, 2026 11:41
@Diskein
Diskein added this pull request to the merge queue Mar 24, 2026
Merged via the queue into master with commit a7914c5 Mar 24, 2026
157 of 159 checks passed
@Diskein
Diskein deleted the dk-merge-tree-data-tsa-lazy-indexes branch March 24, 2026 11:54
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants