Skip to content

Fix REST catalogs behavior with v2 tables #8390

Closed

Description

@aokolnychyi

Apache Iceberg version

main (development)

Query engine

None

Please describe the bug 🐞

Refer here.

Activity

  1. rdblue commented on Sep 2, 2023

    @rdblue
    Contributor

    @bryanck, can you make sure we fix this before the 1.4.0 release?

  2. bryanck commented on Sep 2, 2023

    @bryanck
    Contributor

    Yes, will do!

  3. rdblue commented on Sep 2, 2023

    @rdblue
    Contributor

    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);
  4. bryanck commented on Sep 2, 2023

    @bryanck
    Contributor

    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.

  5. rdblue commented on Sep 2, 2023

    @rdblue
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions