Hold StoragePtr in StorageFromMergeTreeDataPart for clarity#95123
Closed
alexey-milovidov wants to merge 3 commits intomasterfrom
Closed
Hold StoragePtr in StorageFromMergeTreeDataPart for clarity#95123alexey-milovidov wants to merge 3 commits intomasterfrom
StoragePtr in StorageFromMergeTreeDataPart for clarity#95123alexey-milovidov wants to merge 3 commits intomasterfrom
Conversation
`StorageFromMergeTreeDataPart` holds parts that reference the original `MergeTreeData` storage. Previously it only held a raw reference to the storage, which could theoretically become dangling if the storage were destroyed while this wrapper still exists. In practice, this is a no-op change because `MutationsInterpreter` (the only place where `StorageFromMergeTreeDataPart` is created) cannot outlive the storage. However, holding the `StoragePtr` explicitly makes the lifetime dependency clear and follows the same pattern as `StorageFromMergeTreeProjection`. Also removed an unused constructor and its associated `analysis_result_ptr` member. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
|
Workflow [PR], commit [4d1ed99] Summary: ❌
|
In rare cases, the query pipeline can hold references to data parts after the storage has been dropped. When the part destructor runs, it tries to access `storage.decrefColumnsDescriptionForColumns` and `storage.total_outdated_parts_count`, which causes a segmentation fault if the storage has already been destroyed. This change adds a `storage_weak` member that stores a weak pointer to the storage. In the destructor, we lock this weak pointer to check if the storage is still alive before accessing it. The existing `const MergeTreeData & storage` reference is kept for backward compatibility since ~30 files access `part->storage.` directly. The weak pointer is only used in the destructor path where we need to safely handle the case of expired storage. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
| } | ||
|
|
||
| void IMergeTreeDataPart::decrementStateMetric(MergeTreeDataPartState state_) const | ||
| void IMergeTreeDataPart::decrementStateMetric(MergeTreeDataPartState state_, bool storage_alive) const |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StorageFromMergeTreeDataPartholds parts that reference the originalMergeTreeDatastorage. Previously it only held a raw reference to the storage, which could theoretically become dangling if the storage were destroyed while this wrapper still exists.In practice, this is a no-op change because
MutationsInterpreter(the only place whereStorageFromMergeTreeDataPartis created) cannot outlive the storage. However, holding theStoragePtrexplicitly makes the lifetime dependency clear and follows the same pattern asStorageFromMergeTreeProjection.Also removed an unused constructor and its associated
analysis_result_ptrmember.Changelog category (leave one):