Repository navigation
Add article: merges that fail with MEMORY_LIMIT_EXCEEDED in a loop - #196
Open
BorisTyshkevich wants to merge 5 commits into
Open
BorisTyshkevich wants to merge 5 commits into
BorisTyshkevich wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Describe the pool threshold as a size-based mitigation, not a concurrency cap. Clarify retry backoff, cancellation, rollback and data deletion risks. Preserve the tested diagnostic SQL, summarize benchmark findings and remove unsupported generalizations. Revised recovery sequence still needs runtime validation.
BorisTyshkevich
marked this pull request as ready for review
December 1, 2026 15:50
Distinguish source-verified behavior from tests performed on 25.8. Document the 25.4 introduction of configurable merge retry backoff and qualify immutable granularity settings for ReplicatedMergeTree.
… partition Explain the replicated DROP_RANGE mechanism, empty detached-part precondition, completeness and duplicate-data risks, and the need to reduce subsequent merge sizes. Mark the approach as source-verified but not runtime-tested for this failure scenario; do not add an untested executable recovery recipe.
…sholds Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Changes in the latest commit, all checked or tested:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New article:
altinity-kb-setup-and-maintenance/altinity-kb-merges-memory-limit-loop.md. It covers a replicated merge that fails withMEMORY_LIMIT_EXCEEDEDagain and again: how to detect it, how to stop the loop, and why merges of wide rows use so much memory.Background
We saw this on a production cluster on 25.8: an OpenTelemetry traces table with a
Mapattributes column and a 12.6 GiB pod.MERGE_PARTSentries, each about 30 GB, failed withMEMORY_LIMIT_EXCEEDEDfor about 2 weeks.Sources for the claims (25.8)
ReplicatedMergeTreeQueue::shouldExecuteLogEntryandmax_postpone_time_for_failed_replicated_merges_ms(60000 insystem.merge_tree_settings). Upstream FR #135911 describes the same retry storm.max_bytes_to_merge_at_max_space_in_pooldoes not stop a logged merge.shouldExecuteLogEntry,ignore_max_size = (max_source_parts_size == max_bytes_to_merge_at_max_space_in_pool).getMaxSourcePartsSizeForMerge(Compaction/CompactionStatistics.cpp) returns that maximum while free slots ≥number_of_free_entries_in_pool_to_lower_max_size_of_merge.max_bytes_to_merge_at_min_space_in_pooland the maximum.STOP/START MERGES.STOP MERGEScancels running merges.getActionLock(PartsMerge)callsmerges_blocker.cancel(), andMergeTaskchecks it before every block (checkOperationIsNotCanceled).computeIndexGranularity, and the docs' "data storage" section.Tests (local ClickHouse 25.8.16.34)
The test table has a sort key
(svc, k), 10 smallStringcolumns and anattrs Map(String, String)column. Every 33rd row hassvc = 'heavy'and about 25 KB of attributes. There are 6 inserts of 300,000 rows withmin_bytes_for_wide_part = 0, followed byOPTIMIZE FINAL1–3 times. All merges were vertical. Peak memory comes fromsystem.part_log:merge_max_block_size_bytes = 1048576merge_max_block_size = 1024at CREATEmerge_max_block_size = 1024via ALTER on the defaults tableindex_granularity = 1024index_granularity_bytes = 1048576The result part was 13 MiB compressed in every case.
ALTER ... MODIFY SETTING index_granularityandindex_granularity_bytesfail withREADONLY_SETTING(472) on 25.8.Recipes tested
part_logquery: on local 25.8.16, and as a variant on the production 25.8.16 cluster.replication_queuequery: on local 25.8.16 and on the production cluster.MODIFY SETTING/RESET SETTING number_of_free_entries_in_pool_to_lower_max_size_of_merge: on local 25.8.16.MODIFYalso ran on production.SYSTEM STOP/START MERGES: on production.Not verified
ALTERcase keeps the old memory although average rows per granule went down to 1042. My guess is that the merge copies whole source granules where source parts do not overlap in key order. The article states only what the test observed.Draft: please review before merge.
🤖 Generated with Claude Code