Skip to content

Keep the files of a Glue commit with an unknown outcome, and rebuild after a removed pointer - #131575

Open
fm4v wants to merge 3 commits into
masterfrom
nik/glue-keep-files-of-unknown-commit
Open

fm4v wants to merge 3 commits into
masterfrom
nik/glue-keep-files-of-unknown-commit

Conversation

@fm4v

@fm4v fm4v commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Closes: #112102
Related: #128591
Related: #126924
Related: #128752

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 Iceberg writes to a Glue DataLakeCatalog database deleting the files of a commit that Glue may have applied (after a lost response, a timeout or a failed read-back), which left the table pointing to missing files. Such a commit now reads the table back, and fails with UNKNOWN_STATUS_OF_TRANSACTION keeping its files if the outcome cannot be established. Also fixed a commit on a Glue table without metadata_location removing files that a concurrent commit references, and every write failing on a table whose column name Glue refuses.

Description

#126924 made Glue commits read-modify-write and conditional on VersionId. #128752 did the same in parallel and now conflicts with it. I ran the tests of #128752 against a master build (253dc40d795, includes #126924). 10 cases still failed because of real defects; this PR ports the fixes for those onto the code on master. The failing cases that only pinned that PR's own choices are not carried over: the Glue column history, timestamp_ns, EXTERNAL_TABLE, and comment handling.

  • Unknown commit outcome. GlueCatalog::commitTableUpdate threw DATALAKE_DATABASE_ERROR after a 5xx, OperationTimeoutException, a failed SDK retry, a failed read-back, or a superseded commit. The writers then deleted the data files, manifests and manifest list that the table may already reference; master had a TODO for this in IcebergWrites.cpp. Now, after such a response, or an exception from the SDK while reading it, the commit reads the table back. If the table points to the new metadata, the commit succeeded. If it still points to the base, the update is sent again with the current VersionId, so at most one attempt is applied. Otherwise the commit throws UNKNOWN_STATUS_OF_TRANSACTION. INSERT, mutations, ALTER, manifest compaction, expire_snapshots and DROP PARTITION keep their files on that error. They share commitMetadataFileToCatalog, which also removes the metadata file of a definitely refused commit on the exception path, so the file does not block the next write.
  • Pointerless base and removed pointer. The base of a table without metadata_location is the latest metadata file under its location, so another writer can take the metadata file of a pending commit as its base and commit on top of it. A commit cleaning up after a conflict then removed files the table references. Also, isSamePointerlessTable accepted a table whose pointer another writer removed, so the commit was applied on a stale base. The base of a pointerless table is now passed as an empty pointer (DataLakeSpecificProperties::resolved_from_table_location). A commit with such a base, or one that finds the pointer removed, reports every failure as UNKNOWN_STATUS_OF_TRANSACTION and keeps its files.
  • Column text Glue refuses. A column name or type longer than its limit, or with a control character (a nested field name is part of the type), made every UpdateTable fail with ValidationException. Now the commit keeps the existing Glue columns, and CREATE TABLE registers none. ClickHouse reads the schema from the metadata file.

The fault proxy from #128752 replaces the one on master. It enforces VersionId for every database (master's existing cas_ test now reads /rejected/) and injects lost-response, superseded, read-back, timeout and rejected faults. With the proxy, all existing test_database_glue tests pass against the master build. The new tests are not run locally against this change; CI will run them.


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

…fter a removed pointer

When an `UpdateTable` of a Glue commit got a response that does not say whether it was applied (a server error, `OperationTimeoutException`, a failed SDK retry), or its read-back failed, the commit threw `DATALAKE_DATABASE_ERROR` and the writer deleted its data files, manifests and manifest list, although the table may already point to them. Now the commit reads the table back and resends the update if the table still points to the base. If it still cannot tell, it throws `UNKNOWN_STATUS_OF_TRANSACTION`, and `INSERT`, mutations, manifest compaction and `DROP PARTITION` keep their files. A metadata file whose commit Glue definitely refused is removed on the exception path too, so it does not block the next write.

A commit built on a table pointer accepted a table whose pointer another writer removed, so it could be applied on a stale base and drop a concurrent commit. The base of a pointerless table is now passed as an empty pointer, and a removed or added pointer makes the commit rebuild on the latest metadata.

Glue refuses a column name or type longer than its limit or with a control character other than tab. Such columns made every commit fail; now the commit keeps the existing Glue columns, and `CREATE TABLE` registers none.

The tests are taken from #128752, which overlapped with #126924; the fault proxy now enforces `VersionId` for every database.
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cb38b81]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

This PR preserves Iceberg files after ambiguous Glue commits, cleans up definitely rejected metadata, and avoids registering column text that Glue refuses. Review of cb38b81d3b1ab7ffa1c0a07129e528c905354d59 found two remaining blockers: a pointer transition can still cause deletion of committed files, and an unapplied ambiguous commit can permanently block subsequent writes.

Findings

❌ Blockers

  • GlueCatalog.cpp:1004: A pointed base does not rule out adoption through an intermediate pointerless state. Hold A's compaction after it publishes metadata B based on catalog pointer P. Remove the pointer, let another writer list B and commit C referencing its consolidated manifests, then release A. A's conditional update is rejected, but neither uncertainty flag is set. Reading C returns false before inspecting its previous_metadata_location = B; metadata cleanup and compaction cleanup consequently delete files committed C references. Preserve the files unless adoption can be ruled out across the pointer transition, including later descendants. The earlier pointerless cleanup thread is reopened because the claimed fix leaves this variant reachable.
  • Utils.cpp:604: Retained ambiguous metadata must not permanently lock out future commits. If all five updates fail before applying, candidate B is kept while Glue still points to P. After recovery, every new writer deterministically regenerates B from P; writeMetadataFile rejects the existing file, and retries keep resolving P and choosing B without reaching Glue. Subsequent inserts, mutations and schema changes remain broken until an external intervention advances the pointer or removes the object. Allow later commits to choose another safe candidate while retaining the ambiguous commit's files. This leaves the write-wedge contract of Iceberg Glue catalog: commit has no compare-and-swap (external commits silently clobbered), and one failed UpdateTable leaves an orphan metadata file that permanently wedges all further writes #112102 incomplete.
Missing context / blind spots
  • ⚠️ No full ClickHouse/Glue integration run was performed locally; this checkout has no built server. A standalone harness compiled and executed the current commitTableUpdate, commitMetadataFileToCatalog and writeMetadataFile bodies with mocked dependencies, confirming the branch decisions and metadata cleanup above. The full writer's deterministic filename reuse and compaction cleanup were verified from source. A targeted integration run is needed to validate the complete storage behavior; the current head's Praktika integration reports expose no completed test results.
Tests
  • ⚠️ Extend the held-compaction regression to start with a registered pointer, remove it while compaction is pending, and commit through listing before releasing compaction. Verify the winning table remains readable after cleanup.
  • ⚠️ Refuse all update attempts without applying them, then restore the catalog and verify a fresh write succeeds without deleting retained objects. Existing one-shot failure modes recover within the original commit and miss the permanent write lock.
Final Verdict

Status: ❌ Block. Prevent deletion after the intermediate pointerless transition, make later writes progress past retained candidates, and add the two focused regressions.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 14, 2026
Glue requires `Column.Name` to have 1 to 255 characters, so an Iceberg field with an empty name made `UpdateTable` fail with `ValidationException` on every commit, the same way as a too long name. `canRegisterGlueColumns` now refuses it, and the fault proxy enforces the minimum length like Glue does.

Also move `#include <algorithm>` out of the middle of the project includes in `GlueCatalog.cpp`, describe the empty `catalog_metadata_location` of a pointerless table in `MetadataFileWithInfo`, and fix the name of the test a comment in `test_database_glue` refers to.

Related: #131575
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Outdated
/// if another writer removed the pointer, the latest metadata file under the location may be a commit our base lacks.
const bool same_base = current_metadata_path.empty()
? isSamePointerlessTable(existing, base_catalog_metadata_location)
? base_catalog_metadata_location.empty() && isSamePointerlessTable(existing, new_metadata_path)

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.

[Blocker] Establish a catalog pointer before publishing a pointerless writer's files

For a pointerless table, this accepts any base at the same location, while tryGetTableMetadata discovers the base by listing the latest metadata file. Consequently another writer can consume a candidate which the first writer still considers uncommitted:

  1. Writer A runs manifest compaction, uploads metadata B and its consolidated manifests, and pauses before its UpdateTable is applied.
  2. Writer B starts an INSERT, resolves B from the pointerless table's location, and successfully commits metadata C referencing those consolidated manifests. Glue still had no pointer when B checked this condition, so the commit is accepted.
  3. A's conditional update is rejected. On reading C, A returns false because update_may_have_landed is false. The cleanup in writeConsolidatedManifestFile then removes the manifests which the committed C references, making the table unreadable.

VersionId protects the Glue row but cannot protect a base selected from files published before that row changes. Please conditionally register the resolved base pointer before publishing candidate metadata, or reject writes until a pointer is registered. Add an overlapping compaction/insert case; the proxy's held_ mode can hold A's update while B commits.

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.

🕵 Fixed in cb38b81 by keeping the files instead of registering the pointer first. Registering the resolved base would not close the hole: the writer would still choose that base by listing, and the listing can return another writer's uncommitted metadata file.

commitTableUpdate now treats a commit as possibly referenced when its base is pointerless (empty base_catalog_metadata_location) or when it finds the pointer removed. Such a commit never returns false and never reports a definite error. Every failure becomes UNKNOWN_STATUS_OF_TRANSACTION, so INSERT, mutations, compaction and DROP PARTITION keep their files.

In your scenario, writer A's compaction now fails with UNKNOWN_STATUS_OF_TRANSACTION and keeps the consolidated manifests that C references. The cost on pointerless tables is possible orphan files after a failed commit, never a broken table. The same rule replaces the earlier rebuild after a removed pointer: those commits now fail and keep their files too.

New test test_glue_pointerless_compaction_keeps_files_another_writer_built_on covers it. The proxy's held_ mode holds the OPTIMIZE TABLE ... MANIFEST update while an INSERT lists the compaction's metadata file and commits on top of it. The test then checks that the compaction fails with UNKNOWN_STATUS_OF_TRANSACTION and that the table reads back 1, 2, 3, both through pyiceberg and through ClickHouse.

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.

[Blocker] The cleanup hole remains in cb38b81d3b1 when the pointer is removed and re-registered while a writer with a pointed base is pending.

At src/Databases/DataLake/GlueCatalog.cpp:1004-1008, consider this variant of the held-compaction case: A reads pointed base P, publishes compaction metadata B, and its update is held. Another client removes metadata_location; writer B lists A's metadata and commits C on top of it, setting previous_metadata_location = B. Release A: its conditional update is rejected without an SDK retry, so both base_is_listed and update_may_have_landed remain false. The next iteration reads C and returns false at line 1008, before checking previous_metadata_location at line 1012. commitMetadataFileToCatalog deletes A's metadata and the compaction cleanup deletes the consolidated manifests that C references.

The new guard covers a base that was already pointerless, or a pointer that is still absent when read back; it does not cover this intermediate pointerless state. Please preserve adopted files for this transition too, including when further commits have already advanced beyond C. A source-extracted harness confirms the current false return and metadata deletion for this state.

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing cb38b81d3 with master b8fc8d44b (stripped binary size, per-symbol sizes and ThinLTO time; 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

20 object files changed (+69.71 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Databases/DataLake/GlueCatalog.cpp.o 1.09 MiB 1.13 MiB +37.63 KiB (+3.37%)

711 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

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 14, 2026
…terless base

Address review of #131575:

- The SDK reads a response body lazily, so a timeout or a truncated body can throw out of `GetTable` or `UpdateTable` instead of returning an unsuccessful outcome. An exception from `UpdateTable` now leads to a read-back like an ambiguous error, and an exception from `GetTable` after an update may have landed is reported as `UNKNOWN_STATUS_OF_TRANSACTION`. The fault proxy gets `truncated_` and `truncreadback_` faults that interrupt a response body.
- The base of a table without `metadata_location` is the latest metadata file under its location, so another writer may take the metadata file of a pending commit as its base and commit on top of it. A commit with such a base, or one that finds the pointer removed, now reports every failure as `UNKNOWN_STATUS_OF_TRANSACTION` and keeps its files instead of returning a conflict that makes the writer remove them. A test runs an `INSERT` on top of a held manifest compaction of a pointerless table.
}
catch (...)
{
if (writer_wrote_metadata_file && !isCatalogCommitOutcomeUnknown())

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.

[Blocker] Let subsequent writes get past metadata retained after an unknown outcome

Keeping the candidate file is necessary, but the current filename/retry scheme makes it a permanent write lock when the update never landed. If all five UpdateTable attempts fail before applying (for example, a temporary Glue outage), commitTableUpdate throws UNKNOWN_STATUS_OF_TRANSACTION and this handler keeps candidate B, while Glue still points to base P.

After Glue recovers, every new writer resolves P and regenerates exactly B: FileNamesGenerator::generateMetadataPathWithInfo derives the UUID from the base filename and next version. writeMetadataFile then returns false because B exists (Utils.cpp:429); the conflict retry rereads P and resets the generator to the same successor. All retries fail before another UpdateTable is sent. This affects subsequent INSERT, mutations and schema changes, so the write wedge from #112102 remains.

Please allow a fresh candidate name for a later commit, or otherwise make retries tolerate retained candidates safely, while keeping the files of the ambiguous commit. Add a fault case that refuses every update attempt without applying it, restores Glue, and verifies a new write succeeds without manually deleting objects. The current failed_no_retry/failed_timeout cases fail only the first attempt and therefore miss this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

1 participant