Skip to content

Isolate requirements on tables without updates in commitTransaction - #5820

Closed
ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-5807-commit-tx-isolate-requirements
Closed

ShivanshhhG wants to merge 1 commit into
apache:mainfrom
ShivanshhhG:fix-5807-commit-tx-isolate-requirements

Conversation

@ShivanshhhG

Copy link
Copy Markdown

Rationale

In multi-table commit transactions, tables can be included solely with requirements and no updates (updates: []), for example to validate foreign key relationships or state dependencies across tables where the catalog arbitrates concurrent writers.

Previously in IcebergCatalogHandler.commitTransaction, if currentMetadata.changes().isEmpty(), the table commit was skipped and the entity was never enrolled in transactionMetaStoreManager (pendingUpdates). Consequently:

  1. Requirements were not re-evaluated against refreshed metadata at commit time, missing any concurrent changes that occurred after initial staging.
  2. The entity version was never checked atomically during metastore compare-and-swap (updateEntitiesPropertiesIfNotChanged), allowing concurrent contradictory transactions to both succeed.

This change:

  1. Refreshes table metadata and re-evaluates all requirements at commit time for tables without updates.
  2. Calls transactionMetaStoreManager.updateEntityPropertiesIfNotChanged on the target entity to ensure atomic version conflict arbitration during commit.
  3. Adds comprehensive unit tests in CommitTransactionTest covering:
    • Valid requirement-only table commits successfully.
    • Stale requirement on requirement-only table fails commit.
    • Concurrent contradictory transactions with cross-table assertions are properly isolated (only one can commit, the other fails with CommitFailedException).

Fixes #5807

Checklist

Multi-table commits with requirement-only tables (e.g. assertion/dependency tables
with updates: []) previously skipped committing and did not enroll the table entity
in pendingUpdates. Consequently, requirements were not re-evaluated against refreshed
metadata at commit time, nor was the entity version verified atomically by the
transactionMetaStoreManager, allowing concurrent conflicting transactions to succeed.

This change:
1. Refreshes table metadata and re-evaluates requirements at commit time for tables without updates.
2. Calls transactionMetaStoreManager.updateEntityPropertiesIfNotChanged on the target entity to ensure atomic version conflict detection during commit.
3. Adds unit tests covering successful commit, stale requirement failure, and concurrent cross-table isolation.

Fixes apache#5807

Signed-off-by: SHIVANSH-ux-ys <[email protected]>

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

AI-generated review. Written by an agent. It can be wrong, so please push back where it is.

Nice fix overall. Reusing the pending-updates CAS for requirement-only tables is the right way to do this. Two main things:

  1. The re-check and the CAS read the table at two different times (details inline).
  2. None of the three new tests fail on main. Iceberg's requirement validate already throws CommitFailedException in the existing first-pass loop, and the 'concurrent' test runs tx1 to completion before tx2 starts. Can we add a test that injects a write between staging and the final updateEntitiesPropertiesIfNotChanged (e.g. a spy on the metastore manager), and check that it fails without this change?

Also: requirement-only tables now bump their entity version, so concurrent single-table writers on them can start getting 409s. Can we add a line to the CHANGELOG under Unreleased?

Authz looks fine: every identifier is already authorized for COMMIT_TRANSACTION and registered as a passthrough path.

// For tables without updates (e.g. assertion/dependency-only tables in a multi-table
// transaction), re-evaluate requirements against refreshed metadata at commit time to
// catch any concurrent modifications that occurred since the table was staged.
TableMetadata refreshedMetadata = tableOps.refresh();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The requirements are checked against this refresh(), but the entity we send to the CAS comes from a second read a few lines down (getPassthroughResolvedPath builds a new resolver each time). If another writer commits between the two reads, the CAS sees the newer version and passes, but the requirements were checked against the older metadata. Could we resolve the entity once and check that its metadata location matches baseMetadata.metadataFileLocation() before enrolling it? That closes the gap and lets us drop this extra metadata.json read.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think a better way is is not check here, verify requirements for both changed and unchanged are still valid within the transaction of doing CAS.

// Enroll the entity in pendingUpdates so updateEntitiesPropertiesIfNotChanged
// atomically verifies the entity version has not changed concurrently.
PolarisResolvedPathWrapper target =
resolutionManifest.getPassthroughResolvedPath(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This lookup isn't subtype-checked. If the table gets dropped and a view with the same name is created concurrently, we'd enroll the view. Can we use the (key, PolarisEntitySubType.ICEBERG_TABLE) overload like doRefresh does?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

PolarisEntity.toCoreList(target.getRawParentPath()),
target.getRawLeafEntity());
} else {
throw new CommitFailedException("Table not found: %s", tableIdentifier);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A table dropped mid-transaction comes back as a 409 "Table not found", which tells the client to retry. Is that intended, or should this be NoSuchTableException (404)?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
}

// Tx2 has table1 as a requirement-only table, but table1 was concurrently modified by tx1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tx1 has already finished by the time tx2 starts, so tx2's loadTable sees schema 1 and fails in the existing first-pass requirement check. This passes on main and never reaches the new code. Can we inject the table1 write between staging and the final CAS (e.g. spy on updateEntitiesPropertiesIfNotChanged) so this actually tests the race?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

List.of(new MetadataUpdate.SetProperties(Map.of(propertyName, "val1")))),
UpdateTableRequest.create(
TableIdentifier.of(namespace, table2Name),
List.of(new UpdateRequirement.AssertCurrentSchemaID(-99)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

-99 fails in the existing first-pass loop, before the new branch runs, so this test passes on main too. Can we fold it into a parameterized test with the success case, or drop it?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

@flyrain

flyrain commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Copy my concern from the mailing list: My main concern is that it introduces conflicts between
transactions that should be able to succeed independently. For example:

  1. T1 updates table A and checks that table C is unchanged.
  2. T2 updates table B and checks that table C is unchanged.

Neither transaction actually changes C, so both should succeed. With this PR, however, each transaction bumps C's entity version, causing the other to fail its version check. If many transactions share the same dependency, this could lead to unnecessary conflicts and retries.

@ShivanshhhG

Copy link
Copy Markdown
Author

Thanks @flyrain — that's a very fair point. Using updateEntityPropertiesIfNotChanged effectively treats requirement validation as a write lock by bumping entityVersion, which creates artificial conflicts between independent transactions that only read table C.

To avoid this, there seem to be two paths:

  1. Refresh-only validation (in-place fix): Keep the commit-time refresh and requirement re-validation against refreshedMetadata, but remove the updateEntityPropertiesIfNotChanged call for tables without updates. This prevents entityVersion bumps on requirement-only tables so concurrent transactions checking C can both succeed, while still catching concurrent commits on C that landed before the commit pass.
  2. Read-validation in MetaStoreManager: Add an entity version check to PolarisMetaStoreManager (e.g. assertEntityVersionNotChanged / read validation) that participates in the multi-entity atomic CAS without incrementing entityVersion. This provides strict serializability for read dependencies without false conflicts, but requires changes to the metastore interface.

Would you prefer going with (1) for now, or is (2) something we should pursue across the metastore layer?

@flyrain

flyrain commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

I think 1 just reduces the race condition time window, it can still happen. 2 is probably something we need. PR #5961 implements option (2). Pls take a look.

@ShivanshhhG

Copy link
Copy Markdown
Author

Thanks @flyrain for pointing me to #5961!

I've reviewed PR #5961 by @qlong—adding conditional entity writes (writeEntitiesIfConditionsHold with Condition.Unchanged) to the metastore SPI is definitely the clean, architecturally sound solution to #5807. It avoids the artificial version conflicts and write-lock contention that bumping entityVersion in this PR introduced.

Since #5961 completely addresses #5807 across the metastore SPI, backends, and IcebergCatalogHandler, closing this PR in favor of #5961. Thanks everyone!

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Done in Basic Kanban Board Nov 30, 2026
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.

Multi-table commit does not isolate requirements on tables without updates: concurrent transactions both succeed

4 participants