Repository navigation
Add background cleanup of store/ subdirs - #38265
Conversation
| bool hasUUIDMapping(const UUID & uuid); | ||
|
|
||
| void addProtectedUUIDDir(const UUID & uuid); | ||
| void removeProtectedUUIDDir(const UUID & uuid); |
There was a problem hiding this comment.
Make removeProtectedUUIDDir() (and the other new methods) noexcept? Otherwise we an exception may leak out of the UUIdDirectoryProtector destructor.
There was a problem hiding this comment.
Actually it was ugly ad-hoc trick, I've removed addProtectedUUIDDir and removeProtectedUUIDDir methods and added more assertions (so it looks less bad now).
As for noexcept, it's really helpful sometimes (for example, when you would prefer to get SIGABRT instead of inconsistent state of data structures in memory due to some stupid exception like bad_alloc), but in most cases it does not make sense. I don't think noexcept is needed for method that calls only std::unordered_set::erase. Also it was called only from dtor that is noexcept be default.
| /// And remove only if nobody noticed it after, for example, one month. | ||
|
|
||
| struct stat st; | ||
| if (stat(unused_dir.string().c_str(), &st)) |
There was a problem hiding this comment.
Guess below calls on the st struct could be replaced (in part) by something portable in std::filesystem?
There was a problem hiding this comment.
Probably it could, but these stat/utime/chmod calls look more clear and straightforward to me. We use POSIX API a lot in different places and I think it's ok to use it here.
|
|
||
| if (!expected_prefix_dir) | ||
| { | ||
| LOG_WARNING(log, "Found invalid directory {}, will try to remove it", prefix_dir.path().string()); |
There was a problem hiding this comment.
In this case directory is rather invalid than stale, because if has unexpected name. Such directory may appear in two cases: due to a bug in ClickHouse or due to manual intervention.
| @@ -0,0 +1,11 @@ | |||
| <clickhouse> | |||
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, I will add new config params to docs
|
Integration tests: Stateless tests: |
|
@Mergifyio update |
✅ Branch has been successfully updated |
|
|
||
| void DatabaseCatalog::cleanupStoreDirectoryTask() | ||
| { | ||
| fs::path store_path = fs::path(getContext()->getPath()) / "store"; |
There was a problem hiding this comment.
@tavplubix But this will not cleanup store folder on other disks except default (path directive from config), right?
There was a problem hiding this comment.
Yes, I will add cleanup for other disks
`DatabaseCatalogCleanupStoreDirectoryTask` (added in ClickHouse#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` (ClickHouse#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` (ClickHouse#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 ClickHouse#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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added background cleanup of subdirectories in
store/. In some cases clickhouse-server might left garbage subdirectories instore/(for example, on unsuccessful table creation) and those dirs were never been removed. Fixes #33710