Skip to content

Detached parts update#163

Open
lesandie wants to merge 5 commits intomainfrom
detached_parts_update
Open

Detached parts update#163
lesandie wants to merge 5 commits intomainfrom
detached_parts_update

Conversation

@lesandie
Copy link
Member

@lesandie lesandie commented Mar 3, 2026

Updated detached-parts KB with safer cleanup guidance and query fixes: added warnings before destructive actions, added asynchronous detached-part monitoring queries, fixed the bulk DROP DETACHED helper to use system.detached_parts block columns (validated locally), and shortened appendix/reference links for readability.

I have read the CLA Document and I hereby sign the CLA

@lesandie lesandie self-assigned this Mar 3, 2026
@lesandie lesandie requested review from SaltTan and filimonov March 3, 2026 16:05
WHERE active
) b
ON a.database = b.database AND a.table = b.table AND a.partition_id = b.partition_id
WHERE a.min_block_number IS NOT NULL
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to suggest removing all?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will rewrite this

Here is a quick way to find out if you have detached parts along with the reason why.
### Monitoring of detached parts

You can find information in `clickhouse-server.log`, for what happened when the parts were detached during startup. If `clickhouse-server.log` is lost it might be impossible to figure out what happened and why the parts were detached.
Copy link
Member

Choose a reason for hiding this comment

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

part_log fragment disappeared.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it, because checked and RemovePart event_type is generated if there is a manual ALTER TABLE DETACH partition, but if clickhouse is detaching because of problem when starting up, it seems RemovePart event is not pushed to part_log. But I can recheck with codex again. Did that earlier when seeing that fragment about part_log.

Copy link
Member Author

Choose a reason for hiding this comment

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

Codex:

In ClickHouse, system.part_log.event_type='RemovePart' is written when a part is actually removed via the normal part-removal pipeline (removePartsFinally()).

Main cases:

Old/outdated parts are physically cleaned up after merges/mutations/replace/drop workflows.
ALTER ... DROP PART|PARTITION paths that end with old part cleanup.
ALTER ... DETACH PART|PARTITION also results in RemovePart for the removed-from-working-set old part during cleanup.
Important exceptions:

Automatic startup detach of broken parts (broken-on-start) is usually just renameToDetached(...), so no RemovePart is written at that moment.
Other direct renames to detached/ (without passing final removal path) won’t emit RemovePart.
Code points:

Write of RemovePart: MergeTreeData.cpp (line 3437)
Removal pipeline call: MergeTreeData.cpp (line 3765)
Startup broken detach (no part_log add there): MergeTreeData.cpp (line 2461)

Copy link
Member Author

Choose a reason for hiding this comment

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

So we could check for manual ops in part_log. I guess clickhouse-server log will provide more info than part_log here when there was a unexpected/broken part

Here is a query that can help with investigations. It looks for active parts containing the same data blocks as the detached parts and generates commands to drop the detached parts.

```sql
SELECT a.*,
Copy link
Member

Choose a reason for hiding this comment

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

since we generating set of ALTER statements there, i would put all missing details to the comment of ALTER, to simplify copy and paste.

@lesandie lesandie requested a review from DougTidwell March 5, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants