Skip to content

Cancel vector similarity index builds when a merge or mutation is cancelled - #123062

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:cancel-merge-vector-index-on-drop
Oct 1, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:cancel-merge-vector-index-on-drop

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

A merge or mutation that builds a vector_similarity index over one large block does the whole build in a single step on the index build pool. The pool threads only checked KILL QUERY through a query context, which background merges and mutations don't have. Cancelling the merge had no effect until the index build finished, so DROP TABLE SYNC could wait for minutes. In a stress test run, flushAndPrepareForShutdown waited about 15 minutes for such a merge and the hung check fired: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122893&sha=b9ea0599debe81cc756eef94529577290f2b789b&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29

Merges and mutations now install their cancellation check on their thread group. The index build calls CurrentThread::checkIfNotCancelled for every added vector, so it stops as soon as the merge is cancelled. Locally, DROP TABLE SYNC during such a merge took 1m54s before this change and 0.27 s after.

Changelog category (leave one):

  • Improvement

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

DROP TABLE and other operations that cancel merges and mutations no longer wait for an in-progress vector_similarity index build to finish.


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

Version info

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

…celled

Building a `vector_similarity` index for one large block happens in a single step on the
build pool threads. Those threads only checked `KILL QUERY` through a query context, which
merges and mutations don't have, so `DROP TABLE SYNC` waited for the whole build. In a stress
test run `flushAndPrepareForShutdown` waited about 15 minutes and the hung check fired.

Merges and mutations now install their cancellation check on their thread group, and the
index build calls `CurrentThread::checkIfNotCancelled` for every added vector.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122893&sha=b9ea0599debe81cc756eef94529577290f2b789b&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29

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

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2f51e73]

Summary: ✅


AI Review

Summary

The PR routes merge/mutation cancellation into the vector_similarity index-build workers and stops waiting on rows after the first failure, which is the right direction for the DROP TABLE SYNC / cancellation hang it targets. I found one remaining approval blocker: the new stateless regression test does not reliably prove that the cancellation path was exercised, so the current evidence is still too weak for the behavior this PR claims.

Tests
  • ⚠️ tests/queries/0_stateless/05294_drop_table_cancels_vector_index_merge.sh:33 The new regression test can pass without ever observing cancellation. Shell tests run as plain bash, so wait $optimize_pid ignores a failed background OPTIMIZE unless the script checks its exit status, and the elapsed > 3 polling loop also times out silently if the merge finishes quickly. On a fast build this can print OK after dropping an idle table, which means the test does not actually prove that DROP TABLE SYNC interrupted an in-progress vector_similarity build. Tighten it so it fails unless the merge is observed running and the background OPTIMIZE aborts after the drop.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: strengthen tests/queries/0_stateless/05294_drop_table_cancels_vector_index_merge.sh so it explicitly proves the cancellation path instead of passing on a silent poll timeout or ignored background-query failure.

LLVM Coverage Report

Measured on commit 2f51e73.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 60/60 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 30, 2026
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-vector-index Vector similarity index in MergeTree: ANN/HNSW index build/query, usearch integration, vector ind... label Sep 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2f51e73ec with master f76d7abfb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

118 translation units recompiled, 779 s compile time in total, 118 of them have a recent master baseline.

Job report

Algunenano and others added 2 commits October 1, 2026 13:55
…up predicates

The predicates only checked `merges_blocker`, so server shutdown (`MergeList::cancelAll`),
`KILL MUTATION` and `SYSTEM STOP TTL MERGES` still did not interrupt a long vector similarity
index build. Reuse `ctx->is_cancelled` for merges and the `checkOperationIsNotCanceled`
condition for mutations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The index build schedules one pool task per row. After cancellation the merge thread kept
enqueueing the remaining rows and then waited for all of them. With the thread fuzzer used in
CI every scheduling round trip is slow, so `DROP TABLE SYNC` still waited 80 to 106 seconds.
Now enqueueing stops at the first error, and the waiter rethrows it right away; the runner's
destructor drops the rows that are still queued.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@Algunenano
Algunenano added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit dfd7f5c Oct 1, 2026
149 checks passed
@Algunenano
Algunenano deleted the cancel-merge-vector-index-on-drop branch October 1, 2026 23:55
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Oct 3, 2026
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md.

Changelog-revert: 123033 122902 Revert "Revert "Fix ALTER TABLE ... COMMENT COLUMN being silently discarded on a materialized view with an inner table""
Changelog-revert: 123588 123062 Revert "Cancel vector similarity index builds when a merge or mutation is cancelled"
Changelog-revert: 123641 114184 Revert "Support JOIN with arbitrary ON condition (block nested loop)"
Changelog-deleted-entry: 114184 [New Feature] [raw] * Implemented generic block nested loop join algorithm. `JOIN` now supports an arbitrary `ON` condition with no equality between the two tables, executing it as a block nested loop join — as slow as a `CROSS JOIN` with a filter — instead of failing with `INVALID_JOIN_ON_EXPRESSION`; the new setting `allow_block_nested_loop_join` turns it on/off. Close [#106352](#106352). [#114184](#114184) ([Vladimir Cherkasov](https://github.com/vdimir)).
Changelog-deleted-entry: 123062 [Improvement] [section] * `DROP TABLE` and other operations that cancel merges and mutations no longer wait for an in-progress `vector_similarity` index build to finish. [#123062](#123062) ([Raúl Marín](https://github.com/Algunenano)).
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 3, 2026
…t storage

`StorageObjectStorage::resolveHivePartitioningSamplePathIfDeferred` held
`hive_partitioning_resolution_mutex` across `configuration->update` and
`getPathSample`, i.e. across the listing of the storage. Every other query
on the same table (`SELECT`, `DESCRIBE`, `INSERT ... SELECT`, `ALTER`)
then waited in `std::mutex::lock`, where neither its own `KILL QUERY` nor
`max_execution_time` can reach it, for as long as the first caller kept
listing. With an unreachable endpoint that is the whole S3 retry budget
(500 attempts with a 5 s backoff cap, ~41 min per retry loop).

`Stress test (arm_asan_ubsan, s3)` hit it: a cancelled `DESC TABLE` waited
1513 s on the mutex behind a background mutation that kept listing
`http://localhost:1/...` after `KILL MUTATION` (that half is fixed by
ClickHouse#123062, which lets a killed or shut-down mutation stop its S3 retries).

Now the listing runs without the lock, and the lock is taken only to check
the resolved flag and to install the result, so the metadata update stays
serialized with `alter`. The mutex never de-duplicated listings under an
outage anyway: a failed or empty listing is not cached, so every waiter
listed again after acquiring it.

The new test lists an unreachable S3 endpoint from one query and checks
that a `DESCRIBE` and a `SELECT` with `max_execution_time = 1` finish while
the first query is still listing. On master both wait for the first query
to hit its own 120 s limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-vector-index Vector similarity index in MergeTree: ANN/HNSW index build/query, usearch integration, vector ind... pr-improvement Pull request with some product improvements 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