Repository navigation
Cherry pick #117730 to 26.3: Memory-track the JSON FLATTENED path list read from Native - #122886
Merged
Merged
Conversation
The guards added for corrupted `Native` path/type counts carried 9 to 13 lines of comment each, restating what `reserveOrThrowTooManyPaths`, `reserveOrThrowTooManyTypes`, `reserveOrThrowTooMany` and `throwIfInvalidNumberOfBuckets` and their two-line bodies already say. Keep only the part that is not in the code, that the count is untrusted and therefore used as a capped hint, and drop the call-site comments that repeated the same thing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`DeserializeBinaryBulkStateObjectStructure::flattened_paths` was a plain `std::vector<String>`, so its growth was accounted through the non-throwing `MemoryTracker` methods and never rejected: reading a `JSON` column with the `FLATTENED` structure version from a `Native` stream allocated the reserve regardless of `max_memory_usage` and `max_server_memory_usage`. Its sibling `sorted_dynamic_paths`, used by the non-flat versions, is already a `VectorWithMemoryTracking` and does throw `MEMORY_LIMIT_EXCEEDED` on the same input and the same limit. Use `VectorWithMemoryTracking` for `flattened_paths` too, so both structure versions behave the same. The path count itself is capped separately by `reserveOrThrowTooManyPaths`, so this is not an out-of-memory fix. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Addressing review on #117730. Two more containers in the same family were plain `std::vector` and so accounted through the non-throwing `MemoryTracker`, letting a reserve driven by a count from the stream push past `max_memory_usage` without throwing: - `DeserializeBinaryBulkStateDynamic::flattened_states`, reserved from the number of `FLATTENED` types decoded off a `Native` stream, and its serialize-side twin. Weaker than `flattened_paths`, since the size comes from types actually read rather than from the raw header count, but the reserve itself was still untracked. - `SerializationObjectSharedData::StructureGranule::all_paths`, reserved from the per-granule path count, together with the compact and wide readers' full copies of that list and the `deserializeIndexesAndCollectPaths` signature consuming them. Reachable only from a corrupted MergeTree part written with `ADVANCED` shared data serialization, not from `Native`. `PathInfo::substreams` is left plain: converting it needs the `getSubcolumnsDeserializationOrder` parameter changed, which `MergeTreeReaderCompact` also calls with a plain `std::vector<String>`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Conflicts in the `ADVANCED` shared data reader only. Master reworked the per-granule path lists into per-chunk lists and renamed granule to chunk, while this branch changed their container type. Kept master's structure and naming and reapplied the memory tracking on top: `StructureChunk::all_paths` and the per-chunk `chunks_paths` copies in both the Compact and Wide read paths are `VectorWithMemoryTracking<String>`, matching the `deserializeIndexesAndCollectPaths` signature they feed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Addressing review on #117730, the last two containers on the `ADVANCED` shared data read path that were still plain `std::vector` / `std::unordered_map`: - `PathInfo::substreams`, whose `reserve` is driven by the `num_substreams` count read from `ObjectSharedDataSubstreams`, so a corrupted part could preallocate up to `DEFAULT_NATIVE_BINARY_MAX_NUM_COLUMNS` strings outside the throwing tracker. - `PathInfo::substream_to_mark`, which gets one node per entry of that list. `substreams` is passed to `getSubcolumnsDeserializationOrder`, which `MergeTreeReaderCompact` also calls with a plain `std::vector<String>` from `ColumnsSubstreams`. Rather than convert `ColumnsSubstreams` too, the paths argument is now a template parameter, explicitly instantiated for both containers, so nothing outside `DataTypes` changes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Addressing review on #117730. `getSubcolumnsDeserializationOrder` builds a lookup map over the substream list it is given, so on the `ADVANCED` shared data read path its node allocations scale with the substream names read from a possibly corrupted part while bypassing the throwing tracker. The list itself is already tracked, so this was the last untracked step on that path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The merge of master brought a new caller in `StorageGenerateRandom.cpp:1818`
that passes a plain `std::vector<String>`, which no longer converts after this
branch narrowed the parameter to `VectorWithMemoryTracking<String>`:
error: no matching function for call to 'unflattenAndInsertPaths'
note: no known conversion from 'vector<[...], (default) std::allocator<std::string>>'
to 'const vector<[...], AllocatorWithMemoryTracking<String>>'
Take the paths container as a template parameter, explicitly instantiated for
both, the same way `getSubcolumnsDeserializationOrder` already handles its
`MergeTreeReaderCompact` caller. The generated paths in `StorageGenerateRandom`
come from a schema rather than from a stream, so there is no reason to track
them.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117730&sha=2ce73b92a4a69ae2f9c7126ecbad580f614b93af&name_0=PR&name_1=Fast%20test
#117730
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Name the property that makes the template necessary rather than the callers that happen to exercise it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…s-memory-tracking Memory-track the JSON `FLATTENED` path list read from `Native`
`26.3` has neither the untrusted-count hardening that this change rewords on master (the `reserveOrThrowTooMany*` helpers and the `MAX_DYNAMIC_TYPES_LIMIT` check) nor master's newer `SerializationObjectHelpers` signatures. Keep the `26.3` code and apply only the switch to memory-tracked containers, with `unflattenAndInsertPaths` instantiated for `std::vector<ColumnPtr> &&`. The version 2 query in the test expects the non-flat path list to be memory-tracked, which came with #98145 and is not in `26.3`, so the test keeps only the version 3 (FLATTENED) query that this change fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Original pull-request #117730
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job