You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just looked into this a bit more. There are test cases where replace table is failing when a concurrent operation adds a snapshot. The problem is that the replace table produces a snapshot with the next sequence number after the metadata it was based on, but the concurrent commit also uses the same sequence number. Then the commit fails with this error message:
Cannot add snapshot with sequence number 2 older than last sequence number 2
That's a little inaccurate because it is not strictly older, but the point is that the table's current sequence number is 2 and the new sequence number is not newer (greater than 2).
I looked into whether we can fix this by sending a CommitFailedException back to the client because it was out of sync with the current table metadata, but a replace table transaction doesn't currently recommit operations. For a normal transaction, a retry results in each operation getting re-applied (recommitted) on top of the last operation to rebuild metadata. That's unnecessary for replace transactions because any data is completely independent of prior versions. All that needs to happen is that the new snapshot is added and made the current snapshot.
Given that the replace transaction won't rebuild metadata to rewrite the sequence number, retry isn't helpful. We could update retry to rewrite metadata, but that isn't really necessary because the new snapshot is independent. A simpler fix that appears to fix the tests is to update the check in TableMetadata.Builder to allow sequence number reuse if the added snapshot's parent is null (as in the case of a replace table operation). That's safe because there are no existing files.
diff --git a/core/src/main/java/org/apache/iceberg/TableMetadata.java b/core/src/main/java/org/apache/iceberg/TableMetadata.java
index be510dea20..82953c8385 100644
--- a/core/src/main/java/org/apache/iceberg/TableMetadata.java+++ b/core/src/main/java/org/apache/iceberg/TableMetadata.java@@ -1141,7 +1141,7 @@ public class TableMetadata implements Serializable {
snapshot.snapshotId());
ValidationException.check(
- formatVersion == 1 || snapshot.sequenceNumber() > lastSequenceNumber,+ formatVersion == 1 || snapshot.sequenceNumber() > lastSequenceNumber || snapshot.parentId() == null,
"Cannot add snapshot with sequence number %s older than last sequence number %s",
snapshot.sequenceNumber(),
lastSequenceNumber);
Yes, ultimately the other catalogs allow the operation simply because they base the sequence number comparison on the older base snapshot, but they do in fact add the snapshot of the same sequence number.
Activity
rdblue commentedon Sep 2, 2023
@bryanck, can you make sure we fix this before the 1.4.0 release?
bryanck commentedon Sep 2, 2023
Yes, will do!
rdblue commentedon Sep 2, 2023
Just looked into this a bit more. There are test cases where replace table is failing when a concurrent operation adds a snapshot. The problem is that the replace table produces a snapshot with the next sequence number after the metadata it was based on, but the concurrent commit also uses the same sequence number. Then the commit fails with this error message:
That's a little inaccurate because it is not strictly older, but the point is that the table's current sequence number is 2 and the new sequence number is not newer (greater than 2).
I looked into whether we can fix this by sending a
CommitFailedExceptionback to the client because it was out of sync with the current table metadata, but a replace table transaction doesn't currently recommit operations. For a normal transaction, a retry results in each operation getting re-applied (recommitted) on top of the last operation to rebuild metadata. That's unnecessary for replace transactions because any data is completely independent of prior versions. All that needs to happen is that the new snapshot is added and made the current snapshot.Given that the replace transaction won't rebuild metadata to rewrite the sequence number, retry isn't helpful. We could update retry to rewrite metadata, but that isn't really necessary because the new snapshot is independent. A simpler fix that appears to fix the tests is to update the check in
TableMetadata.Builderto allow sequence number reuse if the added snapshot's parent is null (as in the case of a replace table operation). That's safe because there are no existing files.bryanck commentedon Sep 2, 2023
Yes, ultimately the other catalogs allow the operation simply because they base the sequence number comparison on the older base snapshot, but they do in fact add the snapshot of the same sequence number.
rdblue commentedon Sep 2, 2023
Bryan, sorry to tag you and then post a fix. I was just looking into it a bit more and ended up finding an easy solution.