timothyw553 commented on code in PR #18900:
URL: https://github.com/apache/iceberg/pull/18900#discussion_r4724688301
##########
core/src/test/java/org/apache/iceberg/TestTransaction.java:
##########
@@ -62,6 +63,45 @@ public void testEmptyTransaction() {
assertThat(version()).isEqualTo(0);
}
+ @TestTemplate
+ public void
testTransactionWithDirectlyStagedMetadataCommitsWithoutConflict() {
+ Transaction txn = table.newTransaction();
+ TableOperations transactionOps = ((HasTableOperations)
txn.table()).operations();
+ TableMetadata stagedBase = transactionOps.current();
+ transactionOps.commit(
+ stagedBase,
+ TableMetadata.buildFrom(stagedBase).setProperties(Map.of("staged",
"true")).build());
+
+ txn.commitTransaction();
+
+ assertThat(readMetadata().properties()).containsEntry("staged", "true");
+ }
+
+ @TestTemplate
+ public void
testTransactionWithDirectlyStagedMetadataCannotLoseConcurrentUpdate() {
+ // The REST catalog test adapter stages metadata through
TransactionTableOperations,
+ // bypassing the transaction's PendingUpdate list.
+ Transaction txn = table.newTransaction();
+ TableOperations transactionOps = ((HasTableOperations)
txn.table()).operations();
+ TableMetadata stagedBase = transactionOps.current();
+ transactionOps.commit(
+ stagedBase,
+ TableMetadata.buildFrom(stagedBase).setProperties(Map.of("staged",
"true")).build());
+
+ // A separate writer commits after the transaction was staged.
+ table.updateProperties().set("concurrent", "true").commit();
+
+ // The transaction cannot rebase without replayable updates: report a
conflict rather
+ // than acknowledging success while silently discarding the staged change.
+ assertThatThrownBy(txn::commitTransaction)
Review Comment:
here the concurrent write happens before `commitTransaction()`, so this
still passes even if `BaseTransaction` retries a bare `CommitFailedException`
until timeout. could we add a test that injects the concurrent write during the
first underlying commit and checks refresh count to prove retries stop right
away? counting `commit` calls alone wouldn't catch retries that fail in the
guard before `commit`.
##########
core/src/main/java/org/apache/iceberg/BaseTransaction.java:
##########
@@ -438,6 +438,16 @@ private void deleteUncommittedFiles(Iterable<String>
paths) {
private void applyUpdates(TableOperations underlyingOps) {
if (base != underlyingOps.refresh()) {
+ // A transaction may stage metadata directly through its TableOperations
rather than
+ // registering PendingUpdates (e.g. the REST catalog test adapter). Such
changes cannot
+ // be replayed after a concurrent commit. Failing is safer than silently
dropping them
+ // and reporting a successful transaction.
+ if (updates.isEmpty()) {
Review Comment:
what happens if a transaction has both a registered `PendingUpdate` and
directly staged metadata? `updates.isEmpty()` is false, so `applyUpdates`
reloads and replays only `updates`, silently losing the directly staged change.
should we track direct staging in `TransactionTableOperations.commit` instead
and add tests for both staging orders?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]