Skip to content

Iceberg: do not throw from SnapshotSummary::fromJSON - #108634

Closed
Diskein wants to merge 3 commits into
masterfrom
dk-iceberg-snapshot-summary-do-not-throw-from-json
Closed

Diskein wants to merge 3 commits into
masterfrom
dk-iceberg-snapshot-summary-do-not-throw-from-json

Conversation

@Diskein

@Diskein Diskein commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Make SnapshotSummary::fromJSON return an error instead of throwing when a snapshot summary cannot be parsed. Previously the exception escaped IcebergMetadata::getHistory, so a query on system.iceberg_history failed for the whole table instead of reporting the affected snapshot with an UNKNOWN summary. Includes a regression unit test.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Queries to system.iceberg_history no longer fail when an Iceberg table has a snapshot whose summary cannot be read. Such snapshots are now shown with an UNKNOWN summary instead.

Diskein and others added 3 commits June 26, 2026 14:58
`SnapshotSummary::fromJSON` must return an error instead of throwing when
a summary counter is serialized negative (an underflowed total such as
`total-files-size = -924`). Otherwise the exception escapes
`IcebergMetadata::getHistory` and `system.iceberg_history` reports the
whole table as broken rather than a single UNKNOWN snapshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1a047b8]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, distributed plan, 2/4) FAIL
test_keeper_disks/test.py::test_snapshots_with_disks FAIL cidb

AI Review

Summary

This PR changes SnapshotSummary::fromJSON to return std::unexpected for malformed Iceberg snapshot summaries so system.iceberg_history can report UNKNOWN instead of losing the whole table. The intended behavior is sound, but the current catch boundary is too broad and can hide fatal resource exceptions, so I am requesting changes.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/SnapshotSummary.cpp:246] SnapshotSummary::fromJSON now catches all std::exceptions, which includes MEMORY_LIMIT_EXCEEDED, CANNOT_ALLOCATE_MEMORY, and std::bad_alloc raised by allocations while parsing. That violates the tolerant-parse invariant used elsewhere in ClickHouse: malformed input can become a failed parse, but resource/control exceptions must propagate. Otherwise system.iceberg_history can keep going with an UNKNOWN summary after a query memory limit instead of failing the query.
    Suggested fix: only convert metadata parse/JSON errors to std::unexpected and rethrow non-parse exceptions, following the rethrowIfNotParseError pattern where applicable.
Tests
  • ⚠️ Add focused coverage that a non-parse DB::Exception such as MEMORY_LIMIT_EXCEEDED raised from the SnapshotSummary::fromJSON path is rethrown, while CANNOT_PARSE_NUMBER still returns std::unexpected.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: narrow the catch boundary in SnapshotSummary::fromJSON so fatal resource/control exceptions propagate, and cover that boundary with a regression test.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 26, 2026

return result;
}
catch (const std::exception & error)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SnapshotSummary::fromJSON is now a tolerant parser, but this function-wide catch (const std::exception &) also converts resource/control exceptions raised while building parsed, copying Strings, or filling extra_fields into a malformed-summary result. In particular MemoryTracker throws MEMORY_LIMIT_EXCEEDED from allocations, and the existing try-deserialize helpers explicitly rethrow non-parse errors for this reason. With this catch, a query on system.iceberg_history can log UNKNOWN for one snapshot and keep going after a query memory limit or std::bad_alloc instead of failing the query. Please only turn data/JSON parse failures into std::unexpected (for example CANNOT_PARSE_NUMBER plus the relevant Poco::Exceptions), and rethrow MEMORY_LIMIT_EXCEEDED, CANNOT_ALLOCATE_MEMORY, std::bad_alloc, and other non-parse exceptions.

@scanhex12 scanhex12 self-assigned this Jun 26, 2026

return result;
}
catch (const std::exception & error)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to catch std::exception? If it's only because a key might be missing from the JSON, let's check for that explicitly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is checked, this is protection from a malformed json, like negative totals (CANNOT_PARSE_NUMBER) or smth like that. Maybe std::exception is too broad, but I don't know what is better. It might be a poco exception or our parser exception and i'm not sure that it is worth it to write a logic which picking errors. WDYT?

Also, the problem with this exceptions that SELECT * FROM system.iceberg_history will ruin whole request, even if just one table is broken (or even one metadata json in its history was broken). Selects with filters by table/database are less affected by this because the table is smarter now #108492

@clickhouse-gh

clickhouse-gh Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.30% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.50% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 16/16 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Diskein
Diskein marked this pull request as draft July 6, 2026 08:46
@Diskein

Diskein commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

waits for #109288

@Diskein Diskein closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants