Skip to content

fix(catalog): keep prepared resources when the outcome of COMMIT is unknown - #2176

Merged
c-thiel merged 3 commits into
mainfrom
ct/keep-resources-when-commit-outcome-is-unknown
Oct 25, 2026
Merged

c-thiel merged 3 commits into
mainfrom
ct/keep-resources-when-commit-outcome-is-unknown

Conversation

@c-thiel

@c-thiel c-thiel commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Closes #2173

When COMMIT returns an error, several handlers undo what they prepared outside the transaction: table commits delete their new metadata files, create table deletes its metadata file and authorization entry, create generic table deletes its authorization entry, and create warehouse deletes its authorization entry and storage secret. Rename and namespace move put the old parent edge back. Postgres and connection poolers can report an error for a COMMIT that was applied, for example when the connection drops during a failover or proxy restart. The cleanup then removed the metadata file, authorization entry or secret of an object that exists, or, for rename and move, let grants of the old namespace keep applying.

Changes

  • Transaction::commit returns an error of the new type COMMIT_STATE_UNKNOWN_ERROR_TYPE ("CommitStateUnknownException", the name the Iceberg REST spec uses) when the backend cannot tell whether the transaction was committed. Any other error means it was rolled back.
  • The Postgres backend counts an error as a rollback only if it is an ERROR outside SQLSTATE 40003 and the classes 08, 53, 57, 58 and XX, or the FATAL idle-in-transaction timeout 25P03, which ends the session before COMMIT runs. Everything else is unknown. Reasons:
    • PgBouncer and other poolers report a lost server connection or a query_timeout during COMMIT as a FATAL error, also when the server applied the commit.
    • A cancel or terminate that reaches the backend during COMMIT is raised after the commit, when duration logging is on, as ERROR 57014 or FATAL 57P01.
    • An ERROR raised after the commit record, for example out of memory, reaches the client before the PANIC.
    • A dropped connection gives an I/O error.
  • When the outcome is unknown, these paths skip their cleanup and log it:
    • table commits, create table and create generic table keep the new metadata files and authorization entries;
    • create warehouse keeps its authorization entries and storage secret;
    • rename and namespace move do not put the old parent edge back, so the object has no parent edge until a retry (if the commit did not apply) or an additive lakekeeper openfga reconcile restores the edge the catalog implies.
  • Cleanup after a failure the backend reports as a rollback:
    • Metadata writes run inside the cleanup, so a multi-table commit whose writes fail part-way deletes all of its new metadata files.
    • View create and view commit delete their new metadata file when a later step fails. The view-commit idempotency-conflict path now deletes the file; the old remove_all on the file path deleted nothing.
    • View create removes its authorization entry, as table and generic-table create already did.
  • SQLSTATE 40003 (statement_completion_unknown) now returns 500 instead of 409. A 409 tells clients that the commit failed.

User-visible behavior

  • If the outcome of COMMIT is unknown, the response is still 500, now with the type CommitStateUnknownException (on every endpoint). Iceberg clients already treat a 500 on commit as an unknown commit state.
  • If such a commit was in fact rolled back, what it prepared stays behind and is named in the log:
    • A metadata file of a table commit stays in the table location as an unreferenced file.
    • After a create table, the metadata file stays in the table location. A retry that uses the same location (an explicit location, or a storage layout whose table segment is only {name}) is rejected with "Unexpected files in location" until the file is removed.
    • After a create warehouse with a caller-supplied warehouse-id, that id cannot be used again until its authorization relations are removed, and the storage secret is orphaned.

Testing

  • Local experiments with sqlx 0.9 against Postgres 15–18 and PgBouncer 1.26 confirmed each case in the rule above, including applied commits that returned FATAL 08P01, ERROR 57014 and FATAL 57P01.
  • New tests in lakekeeper-storage-postgres:
    • A deferred trigger raises SQLSTATE P0001 (rolled back) and 08006, 40003, 53200, 57014, 58030, XX000 (unknown) at COMMIT.
    • A terminated session is unknown.
    • An idle-in-transaction timeout is a rollback.
    • I/O and protocol errors are unknown.

Release notes

If the database connection fails while Lakekeeper commits a change, the change may still have been saved. Lakekeeper now keeps the new metadata files, permissions and storage secret in this case, and a rename or namespace move no longer restores the old parent's permissions. Failed view changes and multi-table commits also delete their new metadata files.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of transaction errors when it’s unclear whether a change was committed. Potentially committed metadata and access settings are preserved, avoiding cleanup that could leave the catalog inconsistent.
    • Improved cleanup after failed table, view, and warehouse operations. Newly written metadata and related resources are removed when the transaction is known to have failed.
    • Improved handling of namespace and table reparenting when a commit outcome is unknown, avoiding potentially incorrect restoration of previous access relationships.

…nknown

When the connection drops after COMMIT reached Postgres, the commit may have been applied, but table commits, create table and create generic table cleaned up as if it had failed. They deleted the new metadata file or the authorization entry of a table that exists.

The Postgres backend now returns the error type `CommitStateUnknown` when a COMMIT fails without a server-reported rollback (transport error, PANIC, SQLSTATE 40003). The cleanups skip only that case. A server-reported error at COMMIT still means rollback, and the cleanup runs as before.

Also clean up metadata files left behind by a multi-table commit whose metadata write fails part-way, and by view create and view commit when a step after the metadata write fails. SQLSTATE 40003 no longer maps to 409.

Closes #2173
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bca5d008-3eef-4a9f-8360-9f5a2a2d6ec8
Commits

Reviewing files that changed from the base of the PR and between 22eb2e3 and 7abef92.

Files selected for processing: 10
  • crates/lakekeeper-storage-postgres/src/dbutils.rs
  • crates/lakekeeper-storage-postgres/src/lib.rs
  • crates/lakekeeper/src/api/management/v1/namespace.rs
  • crates/lakekeeper/src/api/management/v1/warehouse/mod.rs
  • crates/lakekeeper/src/server/io.rs
  • crates/lakekeeper/src/server/tables.rs
  • crates/lakekeeper/src/server/tables/create_table.rs
  • crates/lakekeeper/src/server/tabular.rs
  • crates/lakekeeper/src/server/views/create.rs
  • crates/lakekeeper/src/service/authz/mod.rs
Files skipped from review as they are similar to previous changes: 5
  • crates/lakekeeper/src/api/management/v1/namespace.rs
  • crates/lakekeeper/src/server/tables/create_table.rs
  • crates/lakekeeper/src/api/management/v1/warehouse/mod.rs
  • crates/lakekeeper-storage-postgres/src/dbutils.rs
  • crates/lakekeeper/src/server/io.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The change classifies PostgreSQL commit errors whose outcome may be unknown. Table and view operations use error-aware cleanup for metadata files. Creation and authorization-reparenting paths also handle unknown outcomes without applying cleanup or restoration intended for a known rollback.

Changes

Commit outcome and resource handling

Layer / File(s) Summary
Classify PostgreSQL commit outcomes
crates/lakekeeper/src/service/catalog_store.rs, crates/lakekeeper-storage-postgres/src/dbutils.rs, crates/lakekeeper-storage-postgres/src/lib.rs
Adds the COMMIT_STATE_UNKNOWN_ERROR_TYPE error type and PostgreSQL error classification. PostgreSQL transaction commits return this error type for classified failures. Tests cover database errors and I/O or protocol errors.
Handle metadata writes and commit failures
crates/lakekeeper/src/server/io.rs, crates/lakekeeper/src/server/tables.rs, crates/lakekeeper/src/server/views/create.rs, crates/lakekeeper/src/server/views/commit.rs
Adds shared cleanup that retains files for unknown commit outcomes and attempts deletion for other errors. Table metadata writes and view creation and commit use the helper. Expired metadata files are deleted concurrently on a best-effort basis.
Preserve resources during uncertain creation
crates/lakekeeper/src/server/generic_tables/create.rs, crates/lakekeeper/src/server/tables/create_table.rs, crates/lakekeeper/src/api/management/v1/warehouse/mod.rs
Creation cleanup receives the error. For unknown commit outcomes, it retains the relevant authorization resources, table metadata file, or warehouse secret.
Handle uncertain authorization reparenting
crates/lakekeeper/src/api/management/v1/namespace.rs, crates/lakekeeper/src/server/tabular.rs, crates/lakekeeper/src/service/authz/mod.rs
Namespace moves and tabular renames skip restoration of the old authorization parent for unknown commit outcomes. Other commit errors retain the existing restoration behavior. Authorization-hook documentation describes compensation for rolled-back commits.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant PostgreSQL
  participant PostgresTransaction
  participant ServerOperation
  participant MetadataStorage
  ServerOperation->>PostgresTransaction: Commit transaction
  PostgresTransaction->>PostgreSQL: Send COMMIT
  PostgreSQL-->>PostgresTransaction: Return commit result
  PostgresTransaction-->>ServerOperation: Return commit error classification
  alt Outcome is unknown
    ServerOperation->>MetadataStorage: Retain prepared metadata files
  else Outcome is known
    ServerOperation->>MetadataStorage: Attempt file cleanup
  end
Loading

Possibly related issues

  • lakekeeper/lakekeeper#2173: The change addresses unknown-commit cleanup for table and generic-table creation, table commits, and SQLSTATE 40003. It also applies error-aware cleanup to view operations.

Possibly related PRs

  • lakekeeper/lakekeeper#2165: It changes overlapping table and view commit-failure metadata cleanup paths, which this change updates to retain files when the commit outcome is unknown.

Suggested reviewers: brgr-s

Merge Risk: Minimal · up to 7abef

No identified issue currently prevents merging. View creation removes its authorization entry when bootstrap grants fail.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 39.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: when the outcome of a catalog COMMIT is unknown, cleanup keeps prepared resources (metadata files, authorizer entries, storage secrets) instead of deleting them. The s…
Linked Issues check Passed [#2173] requires cleanup to skip only when COMMIT outcome is unknown. Transaction::commit now uses CommitStateUnknownException for unknown outcomes. Table commits, table creation, and generic-tabl…
Out of Scope Changes check Passed The changes apply the same commit-outcome rule to related cleanup paths. Warehouse creation preserves authorization entries and the storage secret for unknown outcomes. Rename and namespace move do no…
Full details: Title check

Explanation

The title names the main change: when the outcome of a catalog COMMIT is unknown, cleanup keeps prepared resources (metadata files, authorizer entries, storage secrets) instead of deleting them. The summary and objectives describe the same behavior: commit-state-unknown errors skip cleanup in table, view, namespace, rename, and warehouse paths, and the SQLSTATE 40003 mapping changed. The title is specific, uses the conventional commit prefix, and stays under the length a teammate would scan easily. It does not mention the SQLSTATE 40003 change or the new storage tests, which is expected for a title.

Full details: Linked Issues check

Explanation

[#2173] requires cleanup to skip only when COMMIT outcome is unknown. Transaction::commit now uses CommitStateUnknownException for unknown outcomes. Table commits, table creation, and generic-table creation preserve prepared resources for that error. Rollback cleanup removes metadata files, including multi-table and view metadata. View creation removes authorization on known commit failure. SQLSTATE 40003 no longer maps to 409. The Postgres tests cover the reported rollback, unknown-outcome, timeout, termination, I/O, and protocol cases.

Full details: Out of Scope Changes check

Explanation

The changes apply the same commit-outcome rule to related cleanup paths. Warehouse creation preserves authorization entries and the storage secret for unknown outcomes. Rename and namespace move do not restore the old parent edge for unknown outcomes. View cleanup and metadata-file cleanup support the linked issue requirements. No unrelated change is demonstrated.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the commit reply,
And keeps the files when answers fly.
If rollback’s clear, it sweeps the floor,
If outcomes hide, it guards the door.
Old edges wait for what is known,
While carrots mark the safer zone.

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 24, 2026
@c-thiel
c-thiel enabled auto-merge (squash) October 24, 2026 14:47
@c-thiel
c-thiel disabled auto-merge October 24, 2026 14:52
…se create, rename and move

Postgres and connection poolers can report an error for a COMMIT that was applied: PgBouncer and other poolers send a FATAL error when the server connection drops, and a cancel or terminate during COMMIT surfaces as ERROR 57014 or FATAL 57P01 when duration logging is on. Only an ERROR reply outside SQLSTATE 40003 and the classes 08, 53, 57, 58 and XX now counts as a rollback, plus FATAL 25P03 (idle-in-transaction timeout), which ends the session before COMMIT is read. Every other error has the type `CommitStateUnknownException`, the name the Iceberg REST spec uses.

Warehouse create keeps its storage secret and authorization entries when the outcome is unknown. Rename and namespace move no longer put the old parent edge back in that case; the object stays without a parent until a reconcile restores the edge the catalog implies.

Metadata writes now run inside the cleanup wrapper, so a write that fails part-way is cleaned up with the others. The cleanup helpers are shared, and the view metadata builder and the warehouse cleanup are extracted, so the functions under `too_many_lines` shrink.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 24, 2026
…docs and logs with unknown commit outcomes

View create removes its authorization entry when the bootstrap grants or the commit fail, and keeps it when the commit outcome is unknown, like table and generic-table create.

The Authorizer hook docs, the classifier doc and the rename, namespace-move and warehouse comments describe the current handling of an unknown outcome: no compensation, so an edge may be missing until a retry or an additive reconcile. The rename and move logs no longer claim the object has no parent, which is false for authorizers without hierarchy edges, and log their ids as fields. The warehouse log is an error and names what stays behind. Logs print plain paths. The SQLSTATE test covers the classes 53 and 58.
@github-actions

Copy link
Copy Markdown
Contributor

✅ PR Title Formatted Correctly

The title of this PR match the correct format. Thank you!

@c-thiel
c-thiel merged commit 7b9e47c into main Oct 25, 2026
76 checks passed
@c-thiel
c-thiel deleted the ct/keep-resources-when-commit-outcome-is-unknown branch October 25, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip commit cleanups when the outcome of COMMIT is unknown

1 participant