Repository navigation
Fix Iceberg writes to Glue tables after commits of other writers: name metadata files <N>-<uuid>.metadata.json - #128600
Conversation
…data.json` ClickHouse named the metadata files of a Glue Iceberg table `v<N>.metadata.json`, the convention of tables without a catalog. Iceberg Java and pyiceberg parse the version only from `<N>-<uuid>.metadata.json` and restart at `00000-<uuid>` otherwise, so after a few alternating commits the next ClickHouse commit targets a `v<N>.metadata.json` that already exists, the write is refused and every retry regenerates the same name: `INSERT` fails with `Write into iceberg was not successful` and `ALTER TABLE ... DELETE` with `LIMIT_EXCEEDED`. For every table with a catalog, name new metadata files `%05d-<uuid>.metadata.json` as the Iceberg spec (section "Metastore Tables") requires, in all writers: `INSERT`, mutations, `ALTER` of the schema, `DROP PARTITION`, snapshot expiration and manifest compaction. The UUID is derived from the base metadata file name and the version, so a commit on top of a new base always gets a new name, while two ClickHouse writers that commit on top of the same base still collide on the name, which is what serializes them on Glue until the catalog swap is conditional. Closes: #128590
|
Workflow [PR], commit [9d56aaf] Summary: ❌
AI ReviewSummaryThe PR gives catalog-backed Iceberg metadata files standard version-and-UUID names to prevent permanent write failures after commits by other writers. One blocker remains: the unconditional naming transition breaks Glue commit serialization between old and new ClickHouse binaries, allowing acknowledged writes to disappear during a rolling upgrade. Findings❌ Blockers
Tests
Missing context / blind spots
Final Verdict❌ Block. Make the naming transition safe for concurrent legacy writers and cover that transition with a focused regression test. |
| filename_generator = FileNamesGenerator( | ||
| persistent_table_components.path_resolver.getTableLocation(), | ||
| (catalog != nullptr && catalog->isTransactional()), metadata_compression_method, write_format); | ||
| /* use_uuid_in_metadata */ catalog != nullptr, metadata_compression_method, write_format); |
There was a problem hiding this comment.
[P1] Preserve Glue commit serialization during rolling upgrades
Enabling UUID names unconditionally for Glue removes the shared commit reservation between old and new ClickHouse writers. If both read v41.metadata.json, the old binary writes v42.metadata.json while this binary writes 00042-<uuid>.metadata.json. Both writeMetadataFileAndVersionHint calls succeed because they reserve different objects; both then call GlueCatalog::updateMetadata, whose UpdateTable still has no base-pointer or VersionId condition. Both inserts report success, but the last catalog update discards the other insert's snapshot and rows. Two old writers previously collided on v42.metadata.json and retried instead.
The deterministic UUID only serializes writers already running this patch, so deferring the Glue conditional swap introduces a data-loss window during a normal rolling upgrade. Please preserve a reservation shared with legacy writers, or gate the naming transition behind an explicit coordinated migration that fences old writers. Add a regression case with old/new writers committing from the same base; the sequential pyiceberg test cannot detect this overlap.
There was a problem hiding this comment.
This is real, but it cannot be closed by naming alone. Any name that an old binary would also pick for the next commit is v<N+1>.metadata.json computed from the pointer, and keeping that name as the reservation is exactly what wedges the table (#128590): after a Java or pyiceberg commit resets the version, v<N+1> is a file of an older, legitimately committed version, so the reservation can never be taken again. A reservation shared with old writers therefore keeps the bug for every table that also has a non-ClickHouse writer.
The window is limited to two ClickHouse versions committing on top of the same base of the same Glue table during a rolling upgrade, and it is the same lost update that old ClickHouse already has today against every Spark, Athena or pyiceberg writer (#128591). The fix for both is the conditional swap in GlueCatalog::updateMetadata (GetTable, check metadata_location against the base, UpdateTable with VersionId, ConcurrentModificationException as a retryable conflict), which is tracked there and touches the same code as #126924, so I kept it out of this change. Gating the naming behind a setting would leave the wedge on by default, so I did not add one; happy to do so if maintainers prefer that.
|
Validated against real AWS Glue and S3 (us-east-1) with pyiceberg 0.11.1, using Master (26.11.1.1) as baseline: This PR ( A table that master had already wedged (3 rounds with master, the third The Glue databases and S3 objects created for these runs were deleted afterwards. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes11 object files changed (+18.58 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 units47 translation units recompiled, 507 s compile time in total, 47 of them have a recent master baseline. |
Since ClickHouse#128600 a metadata file of a catalog-backed table is named `<N>-<uuid>.metadata.json` with the UUID derived from the base metadata file, and `FileNamesGenerator` throws LOGICAL_ERROR when that base is not set. The data compaction commit still called `setVersion`, so OPTIMIZE on a table in a REST catalog aborted the server (test_database_iceberg in Integration tests (amd_asan_ubsan, flaky)). Use the same generator setup as the other writers after ClickHouse#128600: UUID names for every catalog-backed table and `setBaseMetadataFile` with the metadata file the plan was read from. A non-transactional catalog (Glue) now also gets the deterministic name, so two writers committing on the same base collide on it and the loser retries, as for INSERT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#128600, ClickHouse names the metadata files of a catalog-backed Iceberg table `<N>-<uuid>.metadata.json` with a name-based uuid derived from the base metadata file and `N`, so that two writers on the same base collide. A table dropped and recreated at the same location therefore writes the same names as the dropped one (`v1.metadata.json`, then the same `00002-<uuid>.metadata.json`). The identity check read such a name through the metadata files cache under the cached table's uuid, got the dropped table's JSON back and reused the stale storage, so test_recreated_clickhouse_table_with_compaction_enabled failed with Code 499 after the master merge. Only a random (version 4) uuid, as Iceberg Java and pyiceberg write, makes the name one no other table reuses; every other name is read fresh. The uuid-less test also registers a name-based uuid name now, with and without `table-uuid`.
Closes: #128590
Related: #128591
Related: #112102
Related: #126924
ClickHouse named the metadata files of a Glue Iceberg table
v<N>.metadata.json, the convention of tables without a catalog. Iceberg Java and pyiceberg parse the table version only from<N>-<uuid>.metadata.jsonand restart at00000-<uuid>for any other name, so after a few commits alternating between ClickHouse and another writer, ClickHouse computes av<N>.metadata.jsonthat it already wrote for an earlier commit. The write is refused, every retry regenerates the same name from the unchanged Glue pointer, and the table becomes permanently unwritable for ClickHouse:INSERTfails withWrite into iceberg was not successfulandALTER TABLE ... DELETEwithLIMIT_EXCEEDED.Now every table with a catalog gets new metadata files named
%05d-<uuid>.metadata.json, as the Iceberg spec (section "Metastore Tables") and Iceberg Java require, in all writers:INSERT,ALTER TABLE ... DELETE/UPDATE, schemaALTER,DROP PARTITION, snapshot expiration and manifest compaction (previously onlyINSERTinto a transactional catalog used a UUID, in the formv<N>-<uuid>which Iceberg Java does not parse). Other writers now parse the version, so it keeps increasing across writers. Tables without a catalog keepv<N>.metadata.json.The UUID is not random: it is derived from the file name of the metadata the commit is based on and from the new version. A commit on top of a new base therefore always gets a new name, so a name already used by an older commit cannot block writes anymore, including on tables already in the stuck state. Two ClickHouse writers that commit on top of the same base still pick the same name and only one of them can write it, which is what serializes concurrent ClickHouse writers on Glue today (for example
test_writes_schema_evolution_concurrent_add_columns). With random UUIDs they would both succeed and the lastUpdateTablewould silently drop the other commit, becauseGlueCatalog::updateMetadatadoes not yet sendVersionId. That conditional swap is tracked in #128591 and is not part of this change. The retry loop is unchanged: with these names an identical name is regenerated only while the pointer stays at the same base, which means another writer's commit is in flight (or an orphan file from a failedUpdateTableas in #112102, which this change does not make worse).Tests: a unit test for the names and their round trip through
getMetadataFileAndVersion, and an integration test intest_database_gluethat alternates pyiceberg appends and ClickHouseINSERTs, ends with anALTER TABLE ... DELETEafter a pyiceberg commit, and checks that the version in the Glue pointer only grows and that both sides read all commits.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed writes to Iceberg tables in a Glue
DataLakeCatalogdatabase that is also written by Spark, pyiceberg or another Iceberg writer: after a few alternating commits everyINSERTfailed withWrite into iceberg was not successfulandALTER TABLE ... DELETEwithLIMIT_EXCEEDED. Metadata files of catalog-backed tables are now named<version>-<uuid>.metadata.jsonas the Iceberg spec requires.Workflow [PR]
Sync PR [sync-upstream/pr/128600]
Version info
26.11.1.1967-master(included in26.11and later)