Repository navigation
Keep the Glue table definition on Iceberg commits and refuse to overwrite a concurrent commit - #128752
Keep the Glue table definition on Iceberg commits and refuse to overwrite a concurrent commit#128752groeneai wants to merge 10 commits into
Conversation
…rite a concurrent commit `GlueCatalog::updateMetadata` sent `UpdateTable` with a `TableInput` built from scratch: Glue replaces the whole definition, so the columns, `previous_metadata_location`, the user parameters and the `EXTERNAL_TABLE` type another engine wrote were lost. It also sent no `VersionId` and did not know the commit's base, so a commit made by another writer between ClickHouse's base read and its `UpdateTable` was silently overwritten (its rows lost). - `ICatalog::updateMetadata` / `updateSchema` take `base_metadata_location`, the pointer the catalog reported when the commit's base was read. The 6 commit sites capture it through a new out-parameter of `getLatestMetadataFileAndVersionWithCatalog` / `getCatalogMetadataFilePath` / `IcebergMetadata::getRelevantState`. `DataLakeSpecificProperties::resolved_from_table_location` tells a stored pointer from a location found by listing. - Glue commits read the table, copy every `TableInput` field, set `metadata_location` and `previous_metadata_location`, refresh the columns on a schema change (keeping a console comment of a field without `doc`) and send `UpdateTable` with `VersionId`. A pointer that moved between two stored values returns `false`; a pointer added or removed meanwhile is an unknown outcome, because a writer that resolves the table by listing may already use the new file. - `ConcurrentModificationException` without an SDK retry re-reads and retries. After an SDK retry the first attempt may have been applied, so the table is read back: ours as the pointer or the previous pointer means applied, the base means not applied, anything else (or a failed read) throws `UNKNOWN_STATUS_OF_TRANSACTION`. - On that code the INSERT sink, mutations and manifest compaction keep their files. On `false` the writer deletes the metadata file it wrote, so the retry can write the same name. - `expire_snapshots` retries a catalog conflict instead of throwing `LOGICAL_ERROR`. - `createTable` registers the Glue columns and uses `EXTERNAL_TABLE`, as Iceberg writers do. Tests: `test_database_glue` gains 4 tests (15 cases). The fault proxy now enforces `UpdateTable.VersionId` (moto ignores it), injects lost-response, superseded and read-back faults, and serves a held `url()` source for the race. 14 cases fail on master. Closes ClickHouse#128591 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…olumns in sync - `GlueCatalog::commitTableUpdate` read the table back only after an SDK-retried `ConcurrentModificationException`. Any other failure that may have applied the update (a 5xx or timeout after the retries, a non-retried 5xx, a call that threw, a client error answering a retry) threw `DATALAKE_DATABASE_ERROR`, and the writers then deleted files the applied commit references. Such outcomes are now read back too: ours means applied, otherwise `UNKNOWN_STATUS_OF_TRANSACTION`. Only a non-retried 4xx that is not retryable keeps `DATALAKE_DATABASE_ERROR`, and only a `ConcurrentModificationException` with the base still in place is retried. - `ICatalog::updateMetadata` gets the metadata object written to `new_metadata_path`, and Glue refreshes the columns from its current schema on every commit, so a table whose columns an earlier ClickHouse commit removed gets them back. The refresh keeps the other parameters of an existing column and the columns of older schemas (`iceberg.field.current = false`). - Keep the REST half of the removed TODO in the INSERT sink, and log the removal of a metadata file the catalog refused. Tests: the fault proxy gains `lostfinal_`, `lostnoretry_`, `failnoretry_` and `rejected_`; `test_glue_update_keeps_table_definition` edits the Glue columns before each commit and gains `insert_after_wipe`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etadata file Glue did not commit - `getGlueColumnType` wrote the Iceberg Java spelling `timestamp_nano` for `timestamp_ns` and `timestamptz_ns`. ClickHouse's Glue reader resolves `timestamp_nano` only for a top-level column; inside a struct, list or map it goes through `DataLake::getType`, which knows only `timestamp_ns` / `timestamptz_ns` and throws `Unknown Iceberg type: timestamp_nano`. Since every commit now rewrites the Glue columns, one ClickHouse commit made a table with a nested nanosecond timestamp unreadable through the Glue database. Write the Iceberg names, as pyiceberg does. - The metadata file is created before the catalog call. When the catalog threw an error other than `UNKNOWN_STATUS_OF_TRANSACTION` (a rejected update, a failed `GetTable`, no `VersionId`, the attempt bound), the update was not applied but the file stayed, so every later write regenerated the same name, collided with it and failed (ClickHouse#112102). The new `Iceberg::commitCreatedMetadataFile` runs the catalog commit at the 5 Glue-reachable sites and removes the file on `false` and on every exception except an unknown outcome. Tests: `test_glue_update_keeps_nested_nanosecond_timestamp_readable` (the version 3 table is made by rewriting pyiceberg's metadata, because pyiceberg 0.11.1 cannot write version 3), and `test_glue_update_conditional_on_version_id[rejected]` checks that no metadata file is left and that the next INSERT succeeds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getGlueColumns` diverged from the Iceberg writers' Glue column history in two ways: - It skipped an existing non-current column whose `iceberg.field.id` is still a current field id. That is the old name of a renamed column (a rename keeps the field id), so any ClickHouse commit (INSERT, DELETE, OPTIMIZE MANIFEST, expire_snapshots, ALTER) removed the rename history that pyiceberg registered. - A current column that the new schema no longer has, after ClickHouse's own `RENAME COLUMN` or `DROP COLUMN`, was dropped instead of being kept as non-current. pyiceberg lists every field of every older schema once by name with `iceberg.field.current = false`. Now the columns are the current fields, then the registered older-schema columns, then the existing columns the new schema no longer has, all non-current, each name once. Tests: `test_glue_update_keeps_table_definition` gains `alter_rename_column` and `alter_drop_column`, and its fixture registers the old name of `s` as an older-schema column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `expire_snapshots` branch that retries when Glue refuses the commit (it threw `LOGICAL_ERROR` before) was not reached by any test: its only race test is an `INSERT` held through a `url()` source, which `expire_snapshots` does not have. The fault proxy gains `held_`: the first `UpdateTable` of such a database waits, outside the lock that serializes the `VersionId` check, until the test releases it. The new test commits with pyiceberg during the hold, so Glue refuses the stale `VersionId`, and checks that the expiration is retried on top of that commit, which stays the previous pointer, keeps all rows, and leaves no metadata file of the refused attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the getGlueColumns comment and drop one that repeats the exception message below it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-5): 7 fixed, 6 noted
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261102-191900 |
|
cc @SmitaRKulkarni @scanhex12, could you review this and add the |
|
Workflow [PR], commit [5e8733a] Summary: ❌
AI ReviewSummaryThe PR preserves Glue table definitions, registers Iceberg columns, and adds conditional catalog commits with explicit handling of uncertain outcomes. Two cleanup gaps remain in Findings❌ Blockers
Tests
Final Verdict❌ Block — preserve partition-drop files on unknown outcomes, remove its metadata on definite refusals, and add the focused regression cases above. |
Glue documents `OperationTimeoutException` for `UpdateTable` as HTTP 400, and the SDK marks it non-retryable, so the commit took it for a definite rejection, threw DATALAKE_DATABASE_ERROR and let the writer delete its metadata and data files. A timeout does not say whether the update was applied, so it now goes through the same read-back as other ambiguous outcomes: ours -> success, otherwise UNKNOWN_STATUS_OF_TRANSACTION with the files kept. The fault proxy gets `losttimeout_` (apply, then answer with OperationTimeoutException) and `failtimeout_` (answer with it without applying), and test_glue_update_conditional_on_version_id the matching `lost_timeout` (success) and `failed_timeout` (UNKNOWN_STATUS_OF_TRANSACTION, pointer unchanged, files kept) cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes23 object files changed (+224.40 KiB total), 0 added.
719 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 units127 translation units recompiled, 1212 s compile time in total, 127 of them have a recent master baseline. |
Glue limits `Column.Name` and `Column.Comment` to 255 characters and `Column.Type` to 131072, all without control characters other than tab. The commit refreshes the Glue columns from the Iceberg schema, so an Iceberg `doc` longer than that or with a newline (Trino, for one, keeps such a doc and registers no Glue columns) made every ClickHouse INSERT fail with a ValidationException, where master never sent columns at all. Such a `doc` is no longer copied: the column keeps the comment Glue already has, if any, and the Iceberg metadata keeps the full `doc`. A column name or type (which embeds nested field names) Glue refuses cannot be registered, so the existing Glue columns are kept as they are. Lengths are counted in UTF-16 code units, the stricter of the two ways Glue may count them. The fault proxy now refuses an `UpdateTable` with such a column like Glue does (moto accepts it), and test_glue_update_skips_column_text_glue_refuses covers a 255-character doc (copied), 255 non-ASCII characters (copied), a 256-character doc (existing comment kept), a multi-line doc (no comment), a 256-character column name and a nested field name with a newline (columns kept). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ames the Glue reader cannot parse After an SDK retry of `UpdateTable` was refused with ConcurrentModificationException, the read-back took `previous_metadata_location == base` as proof that our update was never applied. A writer that copies the Glue parameters and only replaces `metadata_location` keeps the previous pointer our applied commit set, so an update that was applied and then superseded looked refused: the commit returned `false`, and the writer deleted the metadata file and manifest list the other writer's metadata builds on. Only an unchanged pointer now shows that the update was refused; a moved pointer that is neither ours nor has ours as its previous pointer is UNKNOWN_STATUS_OF_TRANSACTION, with the files kept. The fault proxy gets `staleprev_`, and test_glue_update_conditional_on_version_id the case superseded_stale_previous. `DataLake::getType` splits a struct field at its first colon and at commas outside brackets, so a nested Iceberg field named `a:b` registered as `struct<a:b:bigint>` made every later read through the Glue database fail with `Unknown Iceberg type: b:bigint`, for a table that was readable with no Glue columns before the INSERT. A type with a nested field name containing `:`, `,`, `<`, `>`, `(` or `)` is not registered, and the existing Glue columns are kept. test_glue_update_skips_column_text_glue_refuses gets the case nested_delimiter. test_glue_unknown_commit_keeps_files_of_mutation_and_compaction runs the `superseded_unknown` fault for an ALTER DELETE and an OPTIMIZE ... MANIFEST, so the keep-files guards in Mutations.cpp and Compaction.cpp are tested too, not only the one of the INSERT sink. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Glue commits now register columns, so a ClickHouse `Geometry` column is registered as an optional `geometry` Glue column. The Glue reader (`DataLake::getType`) wrapped every optional primitive in `Nullable`, and `Geometry` (a `Variant`) cannot be inside `Nullable`, so the table lookup failed with `Nested type Geometry cannot be inside Nullable type` before the Iceberg metadata was read: right after CREATE, or after the first commit on a table whose Glue columns had been wiped. The reader now uses `makeNullableSafe`, the same rule as the Iceberg schema reader (`canBeInsideNullable`). Test: test_glue_registers_optional_geometry_readably [create, insert_after_wipe]; both fail with Code 43 on the previous head. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const auto & [namespace_name, table_name] = DataLake::parseTableName(storage_id.getTableName()); | ||
| if (!catalog->updateMetadata(namespace_name, table_name, catalog_filename, new_snapshot)) | ||
| if (!catalog->updateMetadata( | ||
| namespace_name, table_name, catalog_filename, new_snapshot, state.base_catalog_metadata_location, state.metadata_object)) |
There was a problem hiding this comment.
[P1] Preserve the partition-drop manifest on an unknown commit outcome
The new Glue commit can throw UNKNOWN_STATUS_OF_TRANSACTION after applying this update. For example, the existing readbackfail_ proxy applies UpdateTable, loses the response, then refuses the read-back. Here that exception escapes commitMetadataJSON before tryCommit sets committed, so its scope guard at lines 678–680 calls cleanupNotCommited and deletes the new manifest list. Glue still points to metadata referencing that deleted list, making the committed table unreadable.
Please propagate the unknown outcome into tryCommit and preserve its attempt files, as the insert, mutation, and manifest-compaction paths now do. Extend the Glue fault test with a partitioned table and DROP PARTITION, checking that the published metadata remains readable after an applied update with a failed read-back.
| auto catalog_filename = components.path_resolver.resolveForCatalog(metadata_info.path); | ||
| const auto & [namespace_name, table_name] = DataLake::parseTableName(storage_id.getTableName()); | ||
| if (!catalog->updateMetadata(namespace_name, table_name, catalog_filename, new_snapshot)) | ||
| if (!catalog->updateMetadata( |
There was a problem hiding this comment.
[P2] Clean up the partition-drop metadata on a refused catalog commit
This is the remaining non-transactional commit site that bypasses commitCreatedMetadataFile. The metadata file was already uploaded above, but neither this false branch nor tryCommit's cleanup removes it. If another writer repoints Glue to a copy of the same metadata version, the new base check returns false; every retry then proposes the same vN+1.metadata.json, encounters its own orphan, and exhausts the retry limit. Later inserts and mutations encounter the same file and also fail until it is removed manually. A definite Glue rejection leaves the same obstruction.
Please wrap this call in commitCreatedMetadataFile for catalogs that do not write metadata themselves, matching the other commit sites. Add a DROP PARTITION case for a same-version repoint or a one-shot rejection, then verify that no uncommitted metadata remains and a subsequent insert succeeds.
CI finish ledger - 5e8733aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261103-073004 |
|
🕵 Closing: #126924 (merged 2026-11-13) implemented the same read-modify-write and I ran this PR's tests against a master build that includes #126924. 10 cases still failed because of real defects:
The fixes for these, with the corresponding tests and the fault proxy, are ported onto master's code in #131575. The remaining failures only pinned this PR's own design choices, so they are not carried over: the column history, |
Closes: #128591
Closes: #112102
Related: #126924
Related: #128600
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Iceberg writes to a Glue
DataLakeCatalogdatabase replacing the Glue table definition with a bare one (losing columns, properties,previous_metadata_locationand table type) and silently overwriting a concurrent commit. A commit now keeps the rest of the definition, setsprevious_metadata_location, syncs the Glue columns with the Iceberg schema (restoring columns a prior commit removed), and applies only if the table still points to its base metadata (GlueVersionId), else it retries. ClickHouse-created tables register their columns. A commit Glue rejects no longer leaves a metadata file behind that makes every later write fail. Closes #128591.Description
On 26.10, any commit (e.g.
INSERT) to an Iceberg table of a GlueDataLakeCatalogdatabase replaces the Glue table definition with a bare one and silently overwrites another writer's concurrent commit, losing its rows.Root cause.
GlueCatalog::updateMetadatabuilt theUpdateTableinput from scratch withoutVersionId, andICatalog::updateMetadatalacked the commit's base.The change.
metadata_locationandprevious_metadata_location, refreshes columns from the Iceberg schema (keeping comments, extra parameters and older-schema columns; renamed or dropped columns become non-current; text Glue refuses is skipped), and sendsUpdateTablewithVersionId.createTableregisters columns asEXTERNAL_TABLE.ConcurrentModificationExceptionre-reads the table. A failedUpdateTablethat may have applied (SDK retry, 5xx, timeout) is read back; if that cannot tell, or the pointer was added or removed, it fails withUNKNOWN_STATUS_OF_TRANSACTION, keeping files.expire_snapshotsretries on a catalog conflict (wasLOGICAL_ERROR).#126924 is partial (no
VersionId, no base check). This also covers the Glue half of #115580.Validation. 9 new tests in
test_database_glue(35 cases), via a fault proxy enforcingVersionIdand Glue's column limits (moto ignores both): 31 fail on master; all pass with the fix (10 runs). Module 75/75, REST commit tests 20/20.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128752]