Skip to content

Fix Iceberg writes to Glue tables after commits of other writers: name metadata files <N>-<uuid>.metadata.json - #128600

Merged
fm4v merged 1 commit into
masterfrom
nik/iceberg-glue-metadata-file-names
Nov 11, 2026
Merged

fm4v merged 1 commit into
masterfrom
nik/iceberg-glue-metadata-file-names

Conversation

@fm4v

@fm4v fm4v commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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.json and restart at 00000-<uuid> for any other name, so after a few commits alternating between ClickHouse and another writer, ClickHouse computes a v<N>.metadata.json that 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: INSERT fails with Write into iceberg was not successful and ALTER TABLE ... DELETE with LIMIT_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, schema ALTER, DROP PARTITION, snapshot expiration and manifest compaction (previously only INSERT into a transactional catalog used a UUID, in the form v<N>-<uuid> which Iceberg Java does not parse). Other writers now parse the version, so it keeps increasing across writers. Tables without a catalog keep v<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 last UpdateTable would silently drop the other commit, because GlueCatalog::updateMetadata does not yet send VersionId. 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 failed UpdateTable as 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 in test_database_glue that alternates pyiceberg appends and ClickHouse INSERTs, ends with an ALTER TABLE ... DELETE after 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):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed writes to Iceberg tables in a Glue DataLakeCatalog database that is also written by Spark, pyiceberg or another Iceberg writer: after a few alternating commits every INSERT failed with Write into iceberg was not successful and ALTER TABLE ... DELETE with LIMIT_EXCEEDED. Metadata files of catalog-backed tables are now named <version>-<uuid>.metadata.json as the Iceberg spec requires.


Workflow [PR]
Sync PR [sync-upstream/pr/128600]

Version info

  • Merged into: 26.11.1.1967-master (included in 26.11 and later)

…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
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9d56aaf]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb IGNORED

AI Review

Summary

The 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
  • ⚠️ Add a deterministic mixed-version Glue commit test: make an old and new writer read the same base, overlap their commits, and verify every acknowledged insert remains visible. The new sequential pyiceberg test and same-format filename test do not cover this case.
Missing context / blind spots
  • ⚠️ No ClickHouse binary or configured build is available in this checkout, so the added unit and Glue integration tests were not run locally. The rollout finding follows from the old/new filename generation and unconditional catalog update paths; a mixed-version integration run would validate it end to end.
Final Verdict

❌ Block. Make the naming transition safe for concurrent legacy writers and cover that transition with a focused regression test.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 2, 2026
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);

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.

[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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@fm4v

fm4v commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Validated against real AWS Glue and S3 (us-east-1) with pyiceberg 0.11.1, using clickhouse local with a DataLakeCatalog database (catalog_type = 'glue'). Script: create a table with pyiceberg, then 5 rounds of pyiceberg append followed by ClickHouse INSERT, then a pyiceberg append, ClickHouse ALTER TABLE ... DELETE WHERE id = 1, another pyiceberg append, and finally a full read from both sides. Glue metadata_location file name after each step:

Master (26.11.1.1) as baseline:

round 0: pyiceberg append  -> 00001-7cd1085a-....metadata.json
round 0: ClickHouse INSERT -> ok -> v2.metadata.json
round 1: pyiceberg append  -> 00000-d23b0aea-....metadata.json
round 1: ClickHouse INSERT -> ok -> v1.metadata.json
round 2: pyiceberg append  -> 00000-ebc05885-....metadata.json
round 2: ClickHouse INSERT -> Code: 736. DB::Exception: Write into iceberg was not successful. (DATALAKE_DATABASE_ERROR)
round 3: pyiceberg append  -> 00001-893c3353-....metadata.json
round 3: ClickHouse INSERT -> Code: 736. DB::Exception: Write into iceberg was not successful. (DATALAKE_DATABASE_ERROR)
round 4: pyiceberg append  -> 00002-0cb9b15d-....metadata.json
round 4: ClickHouse INSERT -> ok -> v3.metadata.json
pyiceberg append           -> 00000-21fcfb69-....metadata.json
ClickHouse ALTER DELETE    -> Code: 290. DB::Exception: Too many unsuccessed retries to create iceberg snapshot. (LIMIT_EXCEEDED)

This PR (build_amd_binary of 9d56aaf):

round 0: pyiceberg append  -> 00001-04cd29fe-....metadata.json
round 0: ClickHouse INSERT -> ok -> 00002-d9fd4ccf-....metadata.json
round 1: pyiceberg append  -> 00003-5b2fa297-....metadata.json
round 1: ClickHouse INSERT -> ok -> 00004-34e1fa2d-....metadata.json
round 2: pyiceberg append  -> 00005-7b5b24b8-....metadata.json
round 2: ClickHouse INSERT -> ok -> 00006-642c2fa9-....metadata.json
round 3: pyiceberg append  -> 00007-24b9f6fe-....metadata.json
round 3: ClickHouse INSERT -> ok -> 00008-9ceadec0-....metadata.json
round 4: pyiceberg append  -> 00009-6abf31fc-....metadata.json
round 4: ClickHouse INSERT -> ok -> 00010-a6fbb108-....metadata.json
pyiceberg append           -> 00011-9ee1f8c1-....metadata.json
ClickHouse ALTER DELETE    -> ok -> 00012-3959490e-....metadata.json
pyiceberg append           -> 00013-f9f59172-....metadata.json
expected  : [0, 10, 11, 20, 21, 30, 31, 40, 41, 1000, 2000]
ClickHouse: [0,10,11,20,21,30,31,40,41,1000,2000]
pyiceberg : [0, 10, 11, 20, 21, 30, 31, 40, 41, 1000, 2000]

A table that master had already wedged (3 rounds with master, the third INSERT failed with code 736) accepts writes again after switching to this PR's binary: 3 more rounds of pyiceberg append and ClickHouse INSERT plus the ALTER TABLE ... DELETE all succeeded, versions continued 00001, 00002, ..., 00009, and ClickHouse and pyiceberg returned the same rows.

The Glue databases and S3 objects created for these runs were deleted afterwards.

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9d56aafe2 with master 0ea6ec133 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 267fb186d; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

11 object files changed (+18.58 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/FileNamesGenerator.cpp.o 31.39 KiB 47.92 KiB +16.53 KiB (+52.64%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

47 translation units recompiled, 507 s compile time in total, 47 of them have a recent master baseline.

Job report

@fm4v
fm4v added this pull request to the merge queue Nov 11, 2026
Merged via the queue into master with commit c37547d Nov 11, 2026
178 of 180 checks passed
@fm4v
fm4v deleted the nik/iceberg-glue-metadata-file-names branch November 11, 2026 15:20
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 11, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
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]>
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 13, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 24, 2026
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

3 participants