pvary commented on issue #14425:
URL: https://github.com/apache/iceberg/issues/14425#issuecomment-3486082610
I have added this test method to the `TestRowDelta` class:
```
@TestTemplate
public void testPreventCommitIfTableChanged() {
// First commit: add FILE_A through RowDelta
commit(table, table.newRowDelta().addRows(FILE_A), branch);
Snapshot firstSnapshot = latestSnapshot(table, branch);
long firstSnapshotId = firstSnapshot.snapshotId();
// Prepare a second RowDelta that will be committed later
RowDelta rowDelta2 =
table
.newRowDelta()
.addRows(FILE_B)
.validateFromSnapshot(firstSnapshotId)
.validateNoConflictingDataFiles();
// Simulate a concurrent operation: add FILE_B to the table
commit(table, table.newRowDelta().addRows(FILE_B), branch);
Snapshot concurrentSnapshot = latestSnapshot(table, branch);
assertThat(concurrentSnapshot.sequenceNumber()).isEqualTo(2);
// Now try to commit rowDelta2 - it will detect the concurrent change
and fail
assertThatThrownBy(() -> commit(table, rowDelta2, branch))
.isInstanceOf(ValidationException.class)
.hasMessageStartingWith("Found conflicting files");
// Verify the table state shows only the concurrent commit succeeded
Snapshot finalSnapshot = latestSnapshot(table, branch);
assertThat(finalSnapshot.sequenceNumber()).isEqualTo(2);
assertThat(finalSnapshot.snapshotId()).isEqualTo(concurrentSnapshot.snapshotId());
}
```
This shows that we could prevent accepting concurrent updates to the table.
Do I miss something? Is there something which could prevent us to use this
method to prevent concurrent changes?
--
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]