Repository navigation
Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing - #106802
Conversation
…ring parsing Composite columns grow several nested structures in sequence inside `insertDefault` with no rollback. If one of them throws (for example on a memory limit [1]) the already-grown structures are left ahead of the rest, so the column's nested structures end up with different sizes. [1]: https://pastila.nl/?0005eb6b/e1cd0ca11139b61c65264e368f8e6150#BjWwSA/197t3/SuuGCsqdg==GCM This is reachable during deserialization default-filling: a missing named-tuple element (`input_format_json_defaults_for_missing_elements_in_named_tuple`) or a null with `input_format_null_as_default` calls `insertDefault` on a nested column. When an allocation throws in the middle, the column is left desynchronized; the exception then unwinds into a serialization-level restore (`SerializationTuple::addElementSafe` and friends) which calls `popBack` to undo the partial row, and `popBack` over-pops the shorter nested structure: Cannot pop 1 rows from String: there are only 0 rows Per type: - `Tuple`: `size` is `columns[0]->size` and `columns[0]` grows first, so any later element that throws leaves `size` ahead - roll back the grown elements. - `Nullable`: the nested column grows before the null map - roll back the nested column if appending to the null map throws. - `Variant`: `local_discriminators` grows before `offsets` - roll it back if appending to `offsets` throws. - `Object`: typed/dynamic paths and `shared_data` grow in sequence - roll each back to the previous size. This should be sufficient (i.e. we do not need to fix IColumn::insert() and others) because usually if some method of IColumn throws, we discard the column, there are only few exceptions: - checkpoint-based rollback (`getCheckpoint`/`rollback`) - should be safe already - manual handling of parsing errors and reverting the state via popBack() - usually safe, but not safe when filling defaults via insertDefault() -- this patch Note `insertManyDefaults` is not on this path (parsing fills defaults one row at a time via `insertDefault`), but the `Variant`/`Object` overrides were made exception-safe too, since they do a bulk fill and may be reused elsewhere. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [19b12cf] Summary: ❌
AI ReviewSummaryThis PR makes several composite column Missing context / blind spots
Findings
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 49/81 (60.49%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 2 line(s) · Uncovered code |
|
349e653
Cherry pick #106802 to 26.3: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
… MEMORY_LIMIT_EXCEEDED) during parsing
Cherry pick #106802 to 26.4: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
… MEMORY_LIMIT_EXCEEDED) during parsing
Cherry pick #106802 to 26.5: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
… MEMORY_LIMIT_EXCEEDED) during parsing
Backport #106802 to 26.4: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
Backport #106802 to 26.3: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
Backport #106802 to 26.5: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1842 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
…tion (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
…6802 Backport ClickHouse#106802 to 26.4: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
Linked issues
Composite columns grow several nested structures in sequence inside
insertDefaultwith no rollback. If one of them throws (for example on a memory limit 1) the already-grown structures are left ahead of the rest, so the column's nested structures end up with different sizes.This is reachable during deserialization default-filling: a missing named-tuple element (
input_format_json_defaults_for_missing_elements_in_named_tuple) or a null withinput_format_null_as_defaultcallsinsertDefaulton a nested column. When an allocation throws in the middle, the column is left desynchronized; the exception then unwinds into a serialization-level restore (SerializationTuple::addElementSafeand friends) which callspopBackto undo the partial row, andpopBackover-pops the shorter nested structure:Per type:
Tuple:sizeiscolumns[0]->sizeandcolumns[0]grows first, so any later element that throws leavessizeahead - roll back the grown elements.Nullable: the nested column grows before the null map - roll back the nested column if appending to the null map throws.Variant:local_discriminatorsgrows beforeoffsets- roll it back if appending tooffsetsthrows.Object: typed/dynamic paths andshared_datagrow in sequence - roll each back to the previous size.This should be sufficient (i.e. we do not need to fix IColumn::insert() and others) because usually if some method of IColumn throws, we discard the column, there are only few exceptions:
getCheckpoint/rollback) - should be safe alreadyNote
insertManyDefaultsis not on this path (parsing fills defaults one row at a time viainsertDefault), but theVariant/Objectoverrides were made exception-safe too, since they do a bulk fill and may be reused elsewhere.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix inconsistent columns (that leads to LOGICAL_ERROR later) on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
Version info
26.6.1.57826.5.3.19,26.4.5.11,26.3.14.11