Skip to content

Cherry pick #117730 to 26.8: Memory-track the JSON FLATTENED path list read from Native - #122889

Merged
PedroTadim merged 12 commits into
backport/26.8/117730from
cherrypick/26.8/117730
Oct 2, 2026
Merged

PedroTadim merged 12 commits into
backport/26.8/117730from
cherrypick/26.8/117730

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Avogar and others added 11 commits September 2, 2026 16:24
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`
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Sep 29, 2026
`26.8` still uses the per-granule names in `SerializationObjectSharedData`, which master later
renamed to per-chunk. Keep the `26.8` code and switch its path containers to
`VectorWithMemoryTracking<String>`, as the change does for the renamed ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants