Skip to content

Remove the background cleanup of unused directories in store/ - #133464

Merged
alexey-milovidov merged 2 commits into
masterfrom
remove-store-cleanup-task
Nov 22, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
remove-store-cleanup-task

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

DatabaseCatalogCleanupStoreDirectoryTask (added in #38265) walked store/ on every disk, revoked all access rights from the directories it considered unused (chmod 0), and removed them recursively after database_catalog_unused_dir_rm_timeout_sec (30 days by default).

Its only criterion for "unused" was that there is no UUID mapping for the directory, and that is not a reliable sign of garbage:

Leaving garbage in store/ is better than the complex and error-prone logic of removing it, so the task is removed entirely, as proposed in #133462 (comment)

Notes:

  • The server settings database_catalog_unused_dir_hide_timeout_sec, database_catalog_unused_dir_rm_timeout_sec, and database_catalog_unused_dir_cleanup_period_sec are kept as obsolete settings without effect. The server refuses to start with unknown keys in the configuration, and existing configurations contain these settings (the workaround from the issue is to set all three to large values).
  • This is not a literal revert. The "locking" of UUIDs in DatabaseCatalog (addUUIDMapping without a table, TemporaryLockForUUIDDirectory), which came with the same pull request, stays: by now it is also what prevents two tables or databases from using the same UUID and so the same directory. Only the comments that referred to the task are updated.
  • IDisk::stat, IDisk::chmod, supportsStat, and supportsChmod have no other users after this change. They are left in place to keep the change small and easy to backport, and can be removed separately.
  • The integration test test_store_cleanup is removed together with the task, and the test configurations no longer set the removed settings. 01601_detach_permanently no longer has to tolerate STD_EXCEPTION, which was caused by the task revoking access rights from a table directory.

Closes: #133462
Closes: #111837
Related: #38265

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Removed the background task that cleaned up unused directories in store/. With async_load_databases enabled, it could revoke all access rights from the data directory of an attached table (queries to the table failed with Permission denied) and delete the directory 30 days later. It could also delete the data of a table that was recoverable with ATTACH TABLE ... UUID after a power loss. Unused directories in store/ are now left untouched. The server settings database_catalog_unused_dir_hide_timeout_sec, database_catalog_unused_dir_rm_timeout_sec, and database_catalog_unused_dir_cleanup_period_sec are obsolete and have no effect.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.173-master (included in 26.12 and later)
  • Backported to: 26.11.1.2924, 26.10.11.8, 26.9.37.5, 26.8.45.4, 26.3.70.4

`DatabaseCatalogCleanupStoreDirectoryTask` (added in
#38265) walked `store/` on every
disk, revoked all access rights from the directories it considered unused
(`chmod 0`), and removed them recursively after
`database_catalog_unused_dir_rm_timeout_sec` (30 days by default).

Its notion of "unused" was "there is no UUID mapping for this directory", which
is not a reliable sign of garbage:

- With `async_load_databases` the task can run while a table is still being
  attached, so it hides the data directory of a live, attached table, and
  every query to the table fails with `Permission denied`
  (#133462).
- After a power loss that loses a `.sql` metadata file, the task hides and then
  deletes data that could be recovered with `ATTACH TABLE ... UUID`
  (#111837).

Leaving garbage in `store/` is better than the complex and error-prone logic of
removing it, so the task is removed, as proposed in
#133462 (comment)

The server settings `database_catalog_unused_dir_hide_timeout_sec`,
`database_catalog_unused_dir_rm_timeout_sec`, and
`database_catalog_unused_dir_cleanup_period_sec` are kept as obsolete settings
without effect, because the server refuses to start with unknown keys in the
configuration, and existing configurations (including the workaround from the
issue) contain them.

The "locking" of UUIDs in `DatabaseCatalog` (`addUUIDMapping`,
`TemporaryLockForUUIDDirectory`) stays: it also protects from two tables or
databases using the same UUID and so the same directory.

The test `test_store_cleanup` is removed together with the task. The test
`01601_detach_permanently` no longer has to tolerate `STD_EXCEPTION`, which was
caused by the task revoking access rights from a table directory.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [33655d7]

Summary: ✅


AI Review

Summary

Removes DatabaseCatalogCleanupStoreDirectoryTask to prevent recoverable or asynchronously loading table data in store/ from being hidden and deleted. UUID collision protection remains, and the three cleanup settings stay accepted as obsolete settings without effect. Reviewed head 33655d7194db6c90c9c75198cca9bd51e1519a3d; no actionable findings.

Final Verdict

Status: ✅ Approve

@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 Nov 22, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. label Nov 22, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The failure of La Casa Del Dolor (amd_debug) is unrelated to this change: the BuzzHouse client exited because the harness HTTP server could not decode a table name with invalid UTF-8 (UnicodeDecodeError in tests/casa_del_dolor/utils/httpserver.py, PUT /sparkupdate → 500). The server was healthy and exited with code 0. Filed as #133476

@stresshouse

stresshouse Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

This PR does not change the speed of any query on clickbench or tpch_adapted_1_official. The only flagged query, clickbench Q4 (COUNT(DISTINCT UserID)), was marked inconclusive automatically because it falls inside master's normal range: the PR median of 80.5 ms is inside master's current range of 67-81 ms, even though it is +15.0% over the 70 ms baseline. The PR removes the background cleanup task for unused store/ directories, marks its three settings as obsolete, and changes comments and tests. None of that code runs while a query executes, so leaving Q4 inconclusive is the right call. Q4 also has a noisy history on master.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 70 80 +15.0% <0.0001 aggregation: This PR removes the store/ cleanup background task, which this COUNT(DISTINCT) aggregation never runs. The +15.0% sits inside master's current range on a query with a noisy history.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 80cb3a6c-632d-4b39-aecc-bf7633ebeea5
  • MIRAI run: 6e6c106a-5fd4-477b-85f0-33f0daec2533
  • PR check IDs:
    • clickbench_809337_1795361986
    • clickbench_809343_1795361986
    • tpch_adapted_1_official_809357_1795361986
    • tpch_adapted_1_official_809404_1795361987

@alexey-milovidov alexey-milovidov self-assigned this Nov 22, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Amazing!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 22, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

IDisk::stat, IDisk::chmod, supportsStat, and supportsChmod have no other users after this change. They are left in place to keep the change small and easy to backport, and can be removed separately.

@groeneai, after this is merged, remove the unused methods and send a PR.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. After #133464 is merged I'll send a PR removing IDisk::chmod and supportsChmod.

IDisk::stat and supportsStat gained a user on master after this PR was opened: #133436 (merged today at 03:10 UTC) calls them in StorageReplicatedMergeTree::checkPartsImpl, where collectFileIds compares the inodes of a part with its copy in detached/. So I'll keep those two, unless you'd rather I rewrite that check without them.

Merged via the queue into master with commit 376a2c4 Nov 22, 2026
385 of 386 checks passed
@alexey-milovidov
alexey-milovidov deleted the remove-store-cleanup-task branch November 22, 2026 15:00
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 22, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Sent: #133549 removes IDisk::chmod, supportsChmod and the rest of the chmod chain; stat and supportsStat stay for StorageReplicatedMergeTree::checkPartsImpl.

clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #133464 to 26.11: Remove the background cleanup of unused directories in `store/`
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #133464 to 26.3: Remove the background cleanup of unused directories in `store/`
alexey-milovidov added a commit that referenced this pull request Nov 22, 2026
Resolve the conflicts of the cherry-pick of #133464 to 26.3:

- `ServerSettings.cpp`: 26.3 has the old documentation format; replace the three `database_catalog_unused_dir_*` declarations with the obsolete ones.
- `DatabaseCatalog.cpp`: remove `cleanupStoreDirectoryTask` and `maybeRemoveDirectory` in the 26.3 form (`getSchedulePool` returns a reference there); `checkDatabaseCanBeRenamedWithNoCyclicDependencies` does not exist on 26.3 and is not brought in.
- `integration_tests_configs.py`, `tests/casa_del_dolor/properties.py`: 26.3 has no entries for the removed test and settings, keep the release version.
- `test_store_cleanup`: removed (modified on 26.3, deleted by the change).
- `02888_obsolete_settings.reference`: add the three settings to the 26.3 list.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
alexey-milovidov added a commit that referenced this pull request Nov 22, 2026
Resolve conflicts of the cherry-pick of #133464 to 26.8: remove `cleanupStoreDirectoryTask` and `maybeRemoveDirectory` from `DatabaseCatalog`, mark the `database_catalog_unused_dir_*` server settings as obsolete, and remove `test_store_cleanup`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
robot-ch-test-poll3 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #133464 to 26.8: Remove the background cleanup of unused directories in `store/`
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #133464 to 26.9: Remove the background cleanup of unused directories in `store/`
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #133464 to 26.10: Remove the background cleanup of unused directories in `store/`
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #133464 to 26.10: Remove the background cleanup of unused directories in `store/`
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #133464 to 26.9: Remove the background cleanup of unused directories in `store/`
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #133464 to 26.8: Remove the background cleanup of unused directories in `store/`
alexey-milovidov added a commit that referenced this pull request Nov 23, 2026
Backport #133464 to 26.3: Remove the background cleanup of unused directories in `store/`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants