Repository navigation
Isolate requirements on tables without updates in commitTransaction - #5820
ShivanshhhG wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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:
- The re-check and the CAS read the table at two different times (details inline).
- None of the three new tests fail on main. Iceberg's requirement
validatealready throwsCommitFailedExceptionin 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 finalupdateEntitiesPropertiesIfNotChanged(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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
-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.
|
Copy my concern from the mailing list: My main concern is that it introduces conflicts between
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. |
|
Thanks @flyrain — that's a very fair point. Using To avoid this, there seem to be two paths:
Would you prefer going with (1) for now, or is (2) something we should pursue across the metastore layer? |
|
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. |
|
Thanks @flyrain for pointing me to #5961! I've reviewed PR #5961 by @qlong—adding conditional entity writes ( Since #5961 completely addresses #5807 across the metastore SPI, backends, and |
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, ifcurrentMetadata.changes().isEmpty(), the table commit was skipped and the entity was never enrolled intransactionMetaStoreManager(pendingUpdates). Consequently:updateEntitiesPropertiesIfNotChanged), allowing concurrent contradictory transactions to both succeed.This change:
transactionMetaStoreManager.updateEntityPropertiesIfNotChangedon the target entity to ensure atomic version conflict arbitration during commit.CommitTransactionTestcovering:CommitFailedException).Fixes #5807
Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)