Skip to content

Fix dangling PrehistoricTID removal locks on concurrent TRUNCATE failure - #97211

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-dangling-removal-tid-lock
Feb 18, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-dangling-removal-tid-lock

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Summary

  • In MergeTreeData::Transaction::commit, the pre-NOEXCEPT loop calls lockRemovalTID(PrehistoricTID) on covered parts. If a later iteration throws (e.g., SERIALIZATION_ERROR from a concurrent transaction), the removal TID locks from previous iterations were never cleaned up.
  • This left dangling PrehistoricTID locks causing subsequent non-transactional TRUNCATE operations to fail with the LOGICAL_ERROR exception "Tried to lock part for removal second time", killing the server in debug builds.
  • The fix adds a try-catch that tracks locked parts and unlocks them on failure before rethrowing.

Related issue: #59103

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8aaa13be4cb6810d70d58f144c97cafc344ec674&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20sequential%29

Test plan

  • Ran test 03811_parallel_truncate_race 4 times on debug build — all passed
  • Verified server remains healthy after test runs

Changelog category (leave one):

  • CI Fix or Improvement

Changelog entry:

Fix LOGICAL_ERROR exception "Tried to lock part for removal second time" on concurrent TRUNCATE operations.

Version info

  • Merged into: 26.2.1.869

…failure

In `MergeTreeData::Transaction::commit`, the pre-NOEXCEPT loop calls
`lockRemovalTID(PrehistoricTID)` on covered parts via
`addNewPartAndRemoveCovered`. If a later iteration throws (e.g.,
`SERIALIZATION_ERROR` because a concurrent transaction already locked a
part), the removal TID locks set in previous iterations were never cleaned
up. This left dangling `PrehistoricTID` locks that caused subsequent
non-transactional operations to fail with the LOGICAL_ERROR exception
"Tried to lock part for removal second time".

The fix adds a try-catch around the loop that tracks which parts had their
removal TID locked by non-transactional operations, and unlocks them all
on failure before rethrowing.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8aaa13be4cb6810d70d58f144c97cafc344ec674&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20sequential%29

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

clickhouse-gh Bot commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8635872]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 1/6) failure
Select historical data failure

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 17, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as draft February 17, 2026 16:04
@alexey-milovidov alexey-milovidov removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Feb 17, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review February 17, 2026 16:07
@alexey-milovidov
alexey-milovidov merged commit b39fa66 into master Feb 18, 2026
142 of 143 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-dangling-removal-tid-lock branch February 18, 2026 04:46
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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