Repository navigation
Keep the caches of a part when it is moved to another disk - #125404
RinChanNOWWW wants to merge 4 commits into
Conversation
|
Workflow [PR], commit [44a33dc] Summary: ❌
AI ReviewSummaryThe PR transfers part caches across disk moves and corrects projection cache paths. At commit Missing context / blind spots
Findings
Tests
Final VerdictStatus: |
The keys of the mark cache, the index mark cache and the primary index cache contain the disk and the path of the part, so a part moved to another disk (`ALTER TABLE ... MOVE PART|PARTITION ... TO DISK|VOLUME`, a move by the storage policy or a move TTL) started with cold caches, and its first reads loaded the marks and the primary index again from the new disk. - Add the MergeTree setting `transfer_caches_on_disk_move` (enabled by default). When it is enabled, `MergeTreePartsMover::swapClonedPart` calls the new `IMergeTreeDataPart::moveCachesTo` after the copy replaced the part: it takes the entries of the part out of the caches and puts them back under the keys of the copy, and hands over the primary index the part keeps in memory when the copy has none (`primary_key_lazy_load`). Projection parts are handled recursively. - Add `take` to `ICachePolicy` and `CacheBase`: it removes an entry and returns it with one lookup, and counts neither as a hit nor as a miss. - Fix the columns cache: its entries are keyed by the name of the part, which a move keeps, so destroying the replaced part (or a copy whose move failed) removed the entries the active part still used. Only one of the parts with the same name owns them now, see `owns_columns_cache_entries`. - Fix the keys of the projection parts: `getRelativePathOfActivePart` returned `<part>/<projection>/` instead of `<part>/<projection>.proj/`, so the marks of projection parts were never removed from the mark cache when the part was removed, and the marks prewarmed for them on insert and merge were never used.
The key of the vector similarity index cache contains the disk and the path of the part, like the mark cache and the primary index cache, so a part moved to another disk (`ALTER TABLE ... MOVE PART|PARTITION ... TO DISK|VOLUME`) started with a cold cache and its first vector search loaded and deserialized the vector index granules again. `IMergeTreeDataPart::moveCachesTo` now transfers them as well: it enumerates the vector similarity indices of the table and the index granules of the part (the same keys `MergeTreeIndexReader::read` inserts under) and moves the entries to the keys of the copy with `take` + `set`. Tested by 05370_vector_similarity_index_cache_move_part_to_disk.
5421ecd to
e52f08b
Compare
The record was written for 26.10, but the setting has not shipped in any release and the current version is 26.11, which the settings_changes_history check requires.
The rebase brought a new SIEVE cache policy which does not implement the `take` method this PR added to `ICachePolicy`, so every explicit instantiation of `CacheBase` with the SIEVE policy failed to compile (allocation of an abstract class, e.g. `LowCardinalityDictionaryCache` in `ColumnsHashing.cpp`). Implement it like `LRUCachePolicy` does: `take` removes the entry, returns its value and keeps the hand consistent when it points at the removed entry; `remove` delegates to `take`. Tested in `gtest_sieve_cache.cpp` the same way as the LRU one.
| } | ||
|
|
||
| void MergeTreeDataPartWide::removeMarksFromCache(MarkCache * mark_cache) const | ||
| void MergeTreeDataPartWide::forEachMarksFile(const std::function<void(const String & marks_file)> & func) const |
There was a problem hiding this comment.
[P2] Include dynamic data streams in the marks transfer
moveCachesTo now relies on this enumeration, but this overload of enumerateStreams receives neither a column sample nor a deserialization state. SerializationDynamic::enumerateStreams consequently returns after the structure stream, and SerializationObject::enumerateStreams skips the dynamic paths and shared data. Thus, warming a Wide part containing Dynamic values or dynamic JSON paths and moving it to S3 still leaves its data-stream marks behind: the first read reloads them despite transfer_caches_on_disk_move = 1.
Please enumerate the persisted column substreams or the relevant marks entries in the part's checksums, so the transfer covers the actual data streams without additional I/O. A warm/read–move–read test with a dynamic column should assert that its marks are not loaded again.
| /// Remove deserialized columns from cache | ||
| if (mayStoreColumnsInColumnsCache()) | ||
| /// Remove deserialized columns from cache, unless another part with the same name owns them. | ||
| if (mayStoreColumnsInColumnsCache() && owns_columns_cache_entries) |
There was a problem hiding this comment.
[P2] Preserve cleanup until readers of every moved copy finish
The latest copy can become uniquely owned while a reader still holds an earlier copy. For example: a reader holds part A; a move replaces it with B and disables A's ownership; a merge replaces B; background cleanup clears B's columns-cache entries. The reader of A can then call MergeTreeReaderWide::flushPendingColumnsCacheWrites and recreate those entries, because ColumnsCache::removePart does not advance the invalidation generation. When that reader releases A, this new condition skips its cleanup, leaving deserialized columns for a removed part resident until eviction and consuming cache capacity needed by live parts.
Please share the cleanup lifetime across the physical copies, or invalidate/reject writes from surviving copies when the last active copy is cleared. The existing columns_cache_reader_pause_before_later_range failpoint can cover a reader spanning the move and subsequent merge/cleanup.
The keys of the mark cache, the index mark cache and the primary index cache contain the disk and the path of the part. So a part moved to another disk (
ALTER TABLE ... MOVE PART|PARTITION ... TO DISK|VOLUME, a move by the storage policy, or a move TTL) started with cold caches, and its first reads loaded the marks and the primary index again from the new disk, which is costly when that disk is S3.This PR:
transfer_caches_on_disk_move(enabled by default). After the copy replaced the part inMergeTreePartsMover::swapClonedPart, the newIMergeTreeDataPart::moveCachesTotakes the entries of the part out of these caches and puts them back under the keys of the copy. It also hands over the primary index that the part keeps in memory (withoutuse_primary_key_cache) when the copy has not loaded one (primary_key_lazy_load). Projection parts are handled recursively. This runs outside of the lock of the parts.taketoICachePolicy(LRU, SLRU, TTL) andCacheBase: it removes an entry and returns it with one lookup, and counts neither as a hit nor as a miss.owns_columns_cache_entries, handed over inMergeTreeData::swapActivePart). This does not depend on the setting.getRelativePathOfActivePartreturned<part>/<projection>/, while the marks are loaded from<part>/<projection>.proj/. So the marks of projection parts were never removed from the mark cache when the part was removed, and the marks prewarmed for them on insert and merge were never found.Tests:
05366_move_part_to_disk_transfers_caches,05367_columns_cache_move_part_to_disk,05368_move_part_to_disk_primary_index_in_memory,05369_projection_part_marks_removed_from_mark_cache, and gtests fortakeingtest_lru_cache.cppandgtest_slru_cache.cpp.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A part moved to another disk or volume keeps its entries in the mark cache, the index mark cache and the primary index cache, and its primary index in memory, so the first queries after the move do not load them again from the new disk. Controlled by the new MergeTree setting
transfer_caches_on_disk_move, enabled by default. Also, the entries of the columns cache are no longer removed by a move, and the marks of projection parts are now removed from the mark cache when the part is removed.Workflow [PR]
Sync PR [sync-upstream/pr/125404]