Repository navigation
Limit the total size of text bloom filter indexes and track their memory - #126549
Conversation
The text bloom filter skip indexes (`tokenbf_v1`, `ngrambf_v1`, `sparse_grams`) checked only the size of a single filter (at most `MAX_BLOOM_FILTER_SIZE`, 1 GiB), but every granule of the index eagerly allocates one filter per indexed column. Also, the filter was stored in a `std::vector` with the default allocator, and implicit `operator new` allocations are not refused by the memory tracker by default, so a one-row `INSERT` into a table with large filters could allocate past the available RAM and get the server killed by the OOM killer. - `BloomFilter::Container` now uses `AllocatorWithMemoryTracking`, so the allocation of a filter respects the memory limits and fails with `MEMORY_LIMIT_EXCEEDED`. This covers all users of `BloomFilter`, including the `bloom_filter` index and runtime filters. - `bloomFilterIndexTextValidator` rejects indexes where the filter size multiplied by the number of indexed columns exceeds `MAX_BLOOM_FILTER_SIZE`. The check is skipped on `ATTACH`, so existing tables still load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [fd395b8] Summary: ✅
AI ReviewSummaryThe PR makes Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Preserve replay of committed replicated metadata and cover that path with a regression test. |
Address review: an index inherited from the old metadata (for example, of a table attached after being created by an older version) is revalidated with `attach = false` on every `ALTER` by `MergeTreeData::checkProperties`, so the check in `bloomFilterIndexTextValidator` made unrelated alters of such tables fail. Move the check to `bloomFilterIndexTextCheckTotalSize`, called from `checkProperties`, which accepts an inherited index as long as its total size does not grow. Also use `VectorWithMemoryTracking` for `BloomFilter::Container`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| old_index = &candidate; | ||
|
|
||
| bloomFilterIndexTextCheckTotalSize(index, old_index); | ||
| } |
There was a problem hiding this comment.
[P1] Exempt committed replicated index additions from the new limit
During a rolling upgrade, an older replica can still commit ALTER TABLE ... ADD INDEX idx (a, b) TYPE tokenbf_v1(536870913, 3, 0) GRANULARITY 1. The upgraded replica applies that entry through StorageReplicatedMergeTree::executeMetadataAlter → setTableStructure → setProperties(new_metadata, old_metadata), whose default attach is false. Since idx is absent from the previous local metadata, old_index is null and this call throws BAD_ARGUMENTS on every retry. The metadata change is already committed in Keeper, and subsequent metadata changes cannot pass the failed entry (ReplicatedMergeTreeQueue orders them through alter_sequence). This also affects entries queued before the replica was upgraded, without any concurrent old-version DDL.
Keep the limit on originating DDL, but treat replay of committed metadata like loading existing metadata. The inherited-index exception alone cannot cover an index that the replica has not applied yet. Please add focused regression coverage for this replay path; no inserted data or large filter allocation is needed.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units336 translation units recompiled, 3303 s compile time in total, 326 of them have a recent master baseline. Translation units without a recent master baseline:
|
Backport #126549 to 26.10: Limit the total size of text bloom filter indexes and track their memory
Cherry pick #126549 to 26.9: Limit the total size of text bloom filter indexes and track their memory
…ndexes and track their memory
Cherry pick #126549 to 26.8: Limit the total size of text bloom filter indexes and track their memory
…ndexes and track their memory
Cherry pick #126549 to 26.3: Limit the total size of text bloom filter indexes and track their memory
…ndexes and track their memory
Backport #126549 to 26.8: Limit the total size of text bloom filter indexes and track their memory
Backport #126549 to 26.3: Limit the total size of text bloom filter indexes and track their memory
…ndexes and track their memory
…ndexes and track their memory
…indexes and track their memory
Backport #126549 to 26.9: Limit the total size of text bloom filter indexes and track their memory
The text bloom filter skip indexes (
tokenbf_v1,ngrambf_v1,sparse_grams) checked only the size of a single filter (at most 1 GiB), but every granule of the index eagerly allocates one filter per indexed column. The filter was stored in astd::vectorwith the default allocator, and such allocations are not refused by the memory tracker by default, so a one-rowINSERTinto a table with large filters could allocate past the available RAM and get the server killed by the OOM killer.BloomFilter::Containernow usesAllocatorWithMemoryTracking, so the allocation of a filter respects the memory limits and fails withMEMORY_LIMIT_EXCEEDED. This covers all users ofBloomFilter, including thebloom_filterindex and runtime filters.CREATE TABLEandALTER TABLE ... ADD INDEXreject text bloom filter indexes where the filter size multiplied by the number of indexed columns exceeds 1 GiB. The check is skipped onATTACHand for an index inherited from the old metadata as long as it does not grow, so existing tables still load and can be altered.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Bloom filters of skip indexes respect the memory limits, so creating large filters fails with
MEMORY_LIMIT_EXCEEDEDinstead of the server being killed by the OOM killer. Text bloom filter indexes (tokenbf_v1,ngrambf_v1,sparse_grams) with the total size of filters in a granule (filter size multiplied by the number of columns) over 1 GiB are rejected on creation.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126549]
Version info
26.11.1.385-master(included in26.11and later)26.9.28.163