Repository navigation
Memory-track the JSON FLATTENED path list read from Native - #117730
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]>
|
Workflow [PR], commit [eeee9f1] Summary: ✅
AI ReviewSummaryThis PR switches the Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit eeee9f1.
Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · Uncovered code |
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]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes17 object files changed (+67.89 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units22 translation units recompiled, 87 s compile time in total, 22 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
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]>
|
@groeneai check the AST fuzzer failure, does it have existing fix? |
|
Yes, it has a fix: #120509 (the abort is STID 2508-436e). The fuzzer query reads It is not caused by your change: your diff touches no format or schema inference code, and it reproduces on stable 26.8.6.5 with |
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]>
… read from `Native`
Backport #117730 to 26.9: Memory-track the JSON `FLATTENED` path list read from `Native`
Cherry pick #117730 to 26.3: Memory-track the JSON `FLATTENED` path list read from `Native`
Cherry pick #117730 to 26.7: Memory-track the JSON `FLATTENED` path list read from `Native`
Cherry pick #117730 to 26.8: Memory-track the JSON `FLATTENED` path list read from `Native`
Backport #117730 to 26.7: Memory-track the JSON `FLATTENED` path list read from `Native`
Backport #117730 to 26.8: Memory-track the JSON `FLATTENED` path list read from `Native`
Backport #117730 to 26.3: Memory-track the JSON `FLATTENED` path list read from `Native`
SerializationObject'sflattened_pathswas a plainstd::vector<String>, so its growth was accounted through the non-throwingMemoryTrackermethods and never rejected. Reading aJSONcolumn with theFLATTENEDstructure version from aNativestream therefore allocated its path list regardless ofmax_memory_usageandmax_server_memory_usage, while the non-flat structure versions, which useVectorWithMemoryTrackingforsorted_dynamic_paths, correctly throwMEMORY_LIMIT_EXCEEDEDon the same input and the same limit.With
max_memory_usage = 10000000and a path count of1000000:FLATTENED)ATTEMPT_TO_READ_AFTER_EOFMEMORY_LIMIT_EXCEEDEDMEMORY_LIMIT_EXCEEDEDThe path count itself is already capped by
reserveOrThrowTooManyPaths, so this is not an out-of-memory fix; it only removes the asymmetry between the two structure versions.The first commit is separate cleanup: the guards for corrupted
Nativepath and type counts each carried 9 to 13 lines of comment restating their own two-line bodies, so they are reduced to the one thing that is not already in the code.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
max_memory_usageandmax_server_memory_usagenot being respected when reading aJSONcolumn with theFLATTENEDserialization version from theNativeformat.Workflow [PR]
Sync PR [sync-upstream/pr/117730]
Version info
26.10.1.998-master(included in26.10and later)26.9.6.9,26.8.16.25,26.7.20.17,26.3.39.12