Repository navigation
fix(catalog): keep prepared resources when the outcome of COMMIT is unknown - #2176
Conversation
…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
|
No actionable comments were generated in the recent review.
|
| 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:
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
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: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
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::commitnow usesCommitStateUnknownExceptionfor 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. SQLSTATE40003no 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.
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.
…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.
…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.
✅ PR Title Formatted CorrectlyThe title of this PR match the correct format. Thank you! |
Closes #2173
When
COMMITreturns 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 aCOMMITthat 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::commitreturns an error of the new typeCOMMIT_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.40003and the classes08,53,57,58andXX, or the FATAL idle-in-transaction timeout25P03, which ends the session beforeCOMMITruns. Everything else is unknown. Reasons:query_timeoutduringCOMMITas a FATAL error, also when the server applied the commit.COMMITis raised after the commit, when duration logging is on, as ERROR57014or FATAL57P01.lakekeeper openfga reconcilerestores the edge the catalog implies.remove_allon the file path deleted nothing.40003(statement_completion_unknown) now returns 500 instead of 409. A 409 tells clients that the commit failed.User-visible behavior
COMMITis unknown, the response is still 500, now with the typeCommitStateUnknownException(on every endpoint). Iceberg clients already treat a 500 on commit as an unknown commit state.location, or a storage layout whose table segment is only{name}) is rejected with "Unexpected files in location" until the file is removed.warehouse-id, that id cannot be used again until its authorization relations are removed, and the storage secret is orphaned.Testing
08P01, ERROR57014and FATAL57P01.lakekeeper-storage-postgres:P0001(rolled back) and08006,40003,53200,57014,58030,XX000(unknown) atCOMMIT.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